Skip to content

Commit 71ee401

Browse files
authored
Disallow insertion of vectors of different precision and dimensions. (#3730)
It is possible to `INSERT` a vector with a different precision and dimensions than the ones defined in the schema. This is fixed by doing exact check of precision and dimensions in `PromoteValue.isPromotionNeeded` which does, besides checking promotion feasibility, type (in)compatibilities, which we may want to move to somewhere else later on. This fixes #3729.
1 parent 539b081 commit 71ee401

File tree

2 files changed

+67
-0
lines changed
  • fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/values
  • yaml-tests/src/test/resources

2 files changed

+67
-0
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/values/PromoteValue.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ public static boolean isPromotionNeeded(@Nonnull final Type inType, @Nonnull fin
460460
}
461461
return promotionNeeded;
462462
}
463+
if (inType.isVector() && promoteToType.isVector()) {
464+
final var inVectorType = (Type.Vector)inType;
465+
final var promoteToVectorType = (Type.Vector)promoteToType;
466+
SemanticException.check(inVectorType.nullable().equals(promoteToVectorType.nullable()), SemanticException.ErrorCode.INCOMPATIBLE_TYPE);
467+
return false;
468+
}
463469
SemanticException.check((inType.isPrimitive() || inType.isEnum() || inType.isUuid()) &&
464470
(promoteToType.isPrimitive() || promoteToType.isEnum() || promoteToType.isUuid()), SemanticException.ErrorCode.INCOMPATIBLE_TYPE);
465471
return inType.getTypeCode() != promoteToType.getTypeCode();

yaml-tests/src/test/resources/vector.yamsql

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,67 @@ test_block:
363363
-
364364
- query: select cast([1.0, 2.0] as VECTOR(3, DOUBLE)) from tDoubleVector where a = 100
365365
- error: "22F3H"
366+
# Tests for attempting to insert vectors of different precision / size
367+
# Wrong number of dimensions - HALF vector with 2 dimensions into table expecting 3
368+
-
369+
- query: insert into tHalfVector values (400, !! !v16 [1.1, 2.2] !!)
370+
- error: "22000"
371+
# Wrong number of dimensions - HALF vector with 4 dimensions into table expecting 3
372+
-
373+
- query: insert into tHalfVector values (401, !! !v16 [1.1, 2.2, 3.3, 4.4] !!)
374+
- error: "22000"
375+
# Wrong number of dimensions - FLOAT vector with 2 dimensions into table expecting 3
376+
-
377+
- query: insert into tFloatVector values (402, !! !v32 [1.1, 2.2] !!)
378+
- error: "22000"
379+
# Wrong number of dimensions - FLOAT vector with 4 dimensions into table expecting 3
380+
-
381+
- query: insert into tFloatVector values (403, !! !v32 [1.1, 2.2, 3.3, 4.4] !!)
382+
- error: "22000"
383+
# Wrong number of dimensions - DOUBLE vector with 2 dimensions into table expecting 3
384+
-
385+
- query: insert into tDoubleVector values (404, !! !v64 [1.1, 2.2] !!)
386+
- error: "22000"
387+
# Wrong number of dimensions - DOUBLE vector with 4 dimensions into table expecting 3
388+
-
389+
- query: insert into tDoubleVector values (405, !! !v64 [1.1, 2.2, 3.3, 4.4] !!)
390+
- error: "22000"
391+
# Wrong precision - FLOAT vector into HALF table
392+
-
393+
- query: insert into tHalfVector values (406, !! !v32 [1.1, 2.2, 3.3] !!)
394+
- error: "22000"
395+
# Wrong precision - DOUBLE vector into HALF table
396+
-
397+
- query: insert into tHalfVector values (407, !! !v64 [1.1, 2.2, 3.3] !!)
398+
- error: "22000"
399+
# Wrong precision - HALF vector into FLOAT table
400+
-
401+
- query: insert into tFloatVector values (408, !! !v16 [1.1, 2.2, 3.3] !!)
402+
- error: "22000"
403+
# Wrong precision - DOUBLE vector into FLOAT table
404+
-
405+
- query: insert into tFloatVector values (409, !! !v64 [1.1, 2.2, 3.3] !!)
406+
- error: "22000"
407+
# Wrong precision - HALF vector into DOUBLE table
408+
-
409+
- query: insert into tDoubleVector values (410, !! !v16 [1.1, 2.2, 3.3] !!)
410+
- error: "22000"
411+
# Wrong precision - FLOAT vector into DOUBLE table
412+
-
413+
- query: insert into tDoubleVector values (411, !! !v32 [1.1, 2.2, 3.3] !!)
414+
- error: "22000"
415+
# Wrong number of dimensions - HALF vector with 1 dimension into table expecting 3
416+
-
417+
- query: insert into tHalfVector values (412, !! !v16 [1.1] !!)
418+
- error: "22000"
419+
# Wrong number of dimensions - FLOAT vector with 5 dimensions into table expecting 3
420+
-
421+
- query: insert into tFloatVector values (413, !! !v32 [1.1, 2.2, 3.3, 4.4, 5.5] !!)
422+
- error: "22000"
423+
# Wrong number of dimensions - DOUBLE vector with 0 dimensions into table expecting 3
424+
-
425+
- query: insert into tDoubleVector values (414, !! !v64 [] !!)
426+
- error: "22000"
366427
# Tests for tWithStruct (struct with HALF vector field)
367428
# Insert struct with vector
368429
-

0 commit comments

Comments
 (0)