Maxwell-Guo commented on code in PR #2469:
URL: https://github.com/apache/cassandra/pull/2469#discussion_r1254362823
##########
src/java/org/apache/cassandra/db/marshal/VectorType.java:
##########
@@ -352,10 +352,10 @@ private void check(List<?> values)
}
}
- private static <V> void checkConsumedFully(V buffer, ValueAccessor<V>
accessor, int offset)
+ private <V> void checkConsumedFully(V buffer, ValueAccessor<V> accessor,
int offset)
{
if (!accessor.isEmptyFromOffset(buffer, offset))
- throw new MarshalException("Unexpected extraneous bytes after
vector value");
+ throw new MarshalException("Unexpected extraneous bytes after " +
asCQL3Type() + " value");
Review Comment:
Can we give more details about the left size from offset using : `default
int sizeFromOffset(V value, int offset)
{
return size(value) - offset;
}`
##########
test/unit/org/apache/cassandra/cql3/validation/operations/CQLVectorTest.java:
##########
@@ -139,6 +140,95 @@ public void insertNonPK()
test.run();
}
+ @Test
+ public void cannotInsertWrongNumberOfDimensionsFixedWidth() throws
Throwable
+ {
+ createTable("CREATE TABLE %s (pk int primary key, value vector<int,
2>)");
+
+ // fewer values than expected, with literals and bind markers
+ assertInvalidThrowMessage("Invalid vector literal for value of type
vector<int, 2>; expected 2 elements, but given 1",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0,
[1])");
+ assertInvalidThrowMessage("Not enough bytes to read a vector<int, 2>",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0, ?)",
vector(1));
+
+ // more values than expected, with literals and bind markers
+ assertInvalidThrowMessage("Invalid vector literal for value of type
vector<int, 2>; expected 2 elements, but given 3",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0, [1,
2, 3])");
+ assertInvalidThrowMessage("Unexpected extraneous bytes after
vector<int, 2> value",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0, ?)",
vector(1, 2, 3));
+ }
+
+ @Test
+ public void cannotInsertWrongNumberOfDimensionsVariableWidth() throws
Throwable
+ {
+ createTable("CREATE TABLE %s (pk int primary key, value vector<text,
2>)");
+
+ // fewer values than expected, with literals and bind markers
+ assertInvalidThrowMessage("Invalid vector literal for value of type
vector<text, 2>; expected 2 elements, but given 1",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0,
['a'])");
+ assertInvalidThrowMessage("Not enough bytes to read a vector<text, 2>",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0, ?)",
vector("a"));
+
+ // more values than expected, with literals and bind markers
+ assertInvalidThrowMessage("Invalid vector literal for value of type
vector<text, 2>; expected 2 elements, but given 3",
+ InvalidRequestException.class,
+ "INSERT INTO %s (pk, value) VALUES (0, ['a',
'b', 'c'])");
+ assertInvalidThrowMessage("Unexpected extraneous bytes after
vector<text, 2> value",
Review Comment:
what about show more detail messages about the left size as I have describe
before ?
May be can be : "Unexpected extraneous bytes after vector<text, 2> value,
xxx size of text is given"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]