joao-r-reis commented on code in PR #1952: URL: https://github.com/apache/cassandra-java-driver/pull/1952#discussion_r1923674272
########## core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java: ########## @@ -156,4 +116,195 @@ public CqlVector<SubtypeT> parse(@Nullable String value) { ? null : CqlVector.from(value, this.subtypeCodec); } + + private static class FixedLength<SubtypeT> implements VectorCodecProxy<SubtypeT> { + private final VectorType cqlType; + private final TypeCodec<SubtypeT> subtypeCodec; + + private FixedLength(VectorType cqlType, TypeCodec<SubtypeT> subtypeCodec) { + this.cqlType = cqlType; + this.subtypeCodec = subtypeCodec; + } + + @Override + public ByteBuffer encode( + @Nullable CqlVector<SubtypeT> value, @NonNull ProtocolVersion protocolVersion) { + if (value == null || cqlType.getDimensions() <= 0) { + return null; + } + ByteBuffer[] valueBuffs = new ByteBuffer[cqlType.getDimensions()]; + Iterator<SubtypeT> values = value.iterator(); + int allValueBuffsSize = 0; + for (int i = 0; i < cqlType.getDimensions(); ++i) { + ByteBuffer valueBuff; + SubtypeT valueObj; + + try { + valueObj = values.next(); + } catch (NoSuchElementException nsee) { + throw new IllegalArgumentException( + String.format( + "Not enough elements; must provide elements for %d dimensions", + cqlType.getDimensions())); + } + + try { + valueBuff = this.subtypeCodec.encode(valueObj, protocolVersion); + } catch (ClassCastException e) { + throw new IllegalArgumentException("Invalid type for element: " + valueObj.getClass()); + } + if (valueBuff == null) { + throw new NullPointerException("Vector elements cannot encode to CQL NULL"); + } + allValueBuffsSize += valueBuff.limit(); + valueBuff.rewind(); + valueBuffs[i] = valueBuff; + } + // if too many elements, throw + if (values.hasNext()) { + throw new IllegalArgumentException( + String.format( + "Too many elements; must provide elements for %d dimensions", + cqlType.getDimensions())); Review Comment: The C# driver throws. Silently ignoring seems like a bad idea imo -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org