tolbertam commented on code in PR #1635:
URL:
https://github.com/apache/cassandra-java-driver/pull/1635#discussion_r1732057687
##########
core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/UdtCodec.java:
##########
@@ -107,10 +111,8 @@ public UdtValue decode(@Nullable ByteBuffer bytes,
@NonNull ProtocolVersion prot
int i = 0;
while (input.hasRemaining()) {
if (i == cqlType.getFieldTypes().size()) {
Review Comment:
This feels ok given that the only operations you can do on `ALTER TYPE` are
`ADD` and `RENAME`,
Given that:
1. you can't drop a udt field;
2. adding a field is always additive (e.g. if you have existing fields, any
added fields should come after, at least that is what it looks like this does:
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java#L161-L162)
This means you won't risk reading the wrong field as position-ally
everything should be retained after any `ALTER TYPE` operation.
Also considering that you can still write a udt value with the old udtCodec
when the type is altered, it seems reasonable that you'd be able to read
partially from it as well.
I suppose there is some inherent risk of someone creating a `UdtCodec` by
hand and potentially reading the wrong interpretation of things; but I think
that should probably done at your own peril anyways.
If you pull a `UdtCodec` from the registry and the type is later changed,
the codec would still be usable after this change, this seems of more value
than protecting against the risk I outlined.
##########
integration-tests/src/test/java/com/datastax/oss/driver/internal/core/type/codec/UdtCodecIT.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.datastax.oss.driver.internal.core.type.codec;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import com.datastax.oss.driver.api.core.CqlSession;
+import com.datastax.oss.driver.api.core.cql.Row;
+import com.datastax.oss.driver.api.core.data.UdtValue;
+import com.datastax.oss.driver.api.core.type.UserDefinedType;
+import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
+import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
+import com.datastax.oss.driver.api.testinfra.session.SessionRule;
+import com.datastax.oss.driver.categories.ParallelizableTests;
+import java.util.Objects;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+@Category(ParallelizableTests.class)
Review Comment:
Can you reformat this with?:
```
mvn fmt:format
```
##########
integration-tests/src/test/java/com/datastax/oss/driver/internal/core/type/codec/UdtCodecIT.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.datastax.oss.driver.internal.core.type.codec;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import com.datastax.oss.driver.api.core.CqlSession;
+import com.datastax.oss.driver.api.core.cql.Row;
+import com.datastax.oss.driver.api.core.data.UdtValue;
+import com.datastax.oss.driver.api.core.type.UserDefinedType;
+import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
+import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
+import com.datastax.oss.driver.api.testinfra.session.SessionRule;
+import com.datastax.oss.driver.categories.ParallelizableTests;
+import java.util.Objects;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+@Category(ParallelizableTests.class)
+public class UdtCodecIT {
+
+ private CcmRule ccmRule = CcmRule.getInstance();
+
+ private SessionRule<CqlSession> sessionRule =
SessionRule.builder(ccmRule).build();
+
+ @Rule public TestRule chain =
RuleChain.outerRule(ccmRule).around(sessionRule);
+
+ @Test
+ public void should_decoding_udt_be_backward_compatible() {
+ try (CqlSession session = sessionRule.session()) {
Review Comment:
tiny problem here, while the test passes, the `CqlSession` returned by
`SessionRule.session()` gets used in teardown to drop keyspaces, so shouldn't
put it in try (as it would get closed when it exists the block).
```
java.lang.IllegalStateException: Session is closed
at
com.datastax.oss.driver.internal.core.session.DefaultSession.execute(DefaultSession.java:232)
at
com.datastax.oss.driver.api.testinfra.session.SessionUtils.dropKeyspace(SessionUtils.java:223)
at
com.datastax.oss.driver.api.testinfra.session.SessionRule.after(SessionRule.java:198)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:59)
```
--
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]