You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "frankgh (via GitHub)" <gi...@apache.org> on 2024/06/17 23:46:46 UTC

[PR] CASSANDRA-19716: Invalid mapping when timestamp is used as a partitio… [cassandra-analytics]

frankgh opened a new pull request, #60:
URL: https://github.com/apache/cassandra-analytics/pull/60

   …n key during bulk writes
   
   Patch by Francisco Guerrero; Reviewed by Yifan Cai for CASSANDRA-19716


-- 
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: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSANDRA-19716: Invalid mapping when timestamp is used as a partitio… [cassandra-analytics]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #60:
URL: https://github.com/apache/cassandra-analytics/pull/60#discussion_r1643695104


##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/SparkTestUtils.java:
##########
@@ -167,21 +173,27 @@ public SparkConf defaultSparkConf()
 
     public void validateWrites(List<Row> sourceData, Object[][] queriedData)
     {
+        validateWrites(sourceData, queriedData, null, Row::getInt);

Review Comment:
   we pass `null` from the test class as well. I wanted to avoid passing it from the test class. But I guess we can disallow nulls here instead



-- 
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: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSANDRA-19716: Invalid mapping when timestamp is used as a partitio… [cassandra-analytics]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #60:
URL: https://github.com/apache/cassandra-analytics/pull/60#discussion_r1643623184


##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/common/schema/TimestampType.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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 org.apache.cassandra.spark.common.schema;
+
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+/**
+ * Provides functionality to convert {@link ByteBuffer}s to a {@link Date} column type and to serialize
+ * {@link Date} types to {@link ByteBuffer}s
+ */
+public class TimestampType implements ColumnType<Date>
+{
+    private static final Date DEFAULT_DATE = new Date(0L);
+
+    /**
+     * Parses a value of this type from buffer. Value will be parsed from current position of the buffer. After
+     * completion of the function, position will be moved by "length" bytes.
+     *
+     * @param buffer Buffer to parse column from
+     * @param length Serialized value size in buffer is as big as length
+     * @return value as {@link Date} type
+     */
+    @Override
+    public Date parseColumn(ByteBuffer buffer, int length)
+    {
+        assert length == Long.SIZE / Byte.SIZE;

Review Comment:
   nit: how about declare a constant for the division result instead? The value is used in `serialize` method too.



##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/SparkTestUtils.java:
##########
@@ -167,21 +173,27 @@ public SparkConf defaultSparkConf()
 
     public void validateWrites(List<Row> sourceData, Object[][] queriedData)
     {
+        validateWrites(sourceData, queriedData, null, Row::getInt);

Review Comment:
   can we pass the `DEFAULT_COLUMNS_MAPPER`, instead of `null`? and remove the null check in the method below?



##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/PartitionKeyIntegrationTest.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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 org.apache.cassandra.analytics;
+
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import com.datastax.driver.core.utils.UUIDs;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.ICoordinator;
+import org.apache.cassandra.sidecar.testing.QualifiedName;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.ASCII;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.BIGINT;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.BLOB;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.BOOLEAN;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.DOUBLE;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.INT;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.TEXT;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.TIMESTAMP;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.TIMEUUID;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.UUID;
+import static org.apache.cassandra.spark.bulkwriter.SqlToCqlTypeConverter.VARCHAR;
+import static org.apache.cassandra.testing.TestUtils.DC1_RF1;
+import static org.apache.cassandra.testing.TestUtils.TEST_KEYSPACE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration test that performs bulk reads and writes using different types for the partition key to test
+ * type mapping for the partition key
+ */
+class PartitionKeyIntegrationTest extends SharedClusterSparkIntegrationTestBase
+{
+    static final List<String> DATASET = Arrays.asList("a", "b", "c", "d", "e", "f", "g");
+    static final List<String> REDUCED_DATASET_FOR_BOOLEAN = Arrays.asList("a", "b");
+    static final String CREATE_TEST_TABLE_STATEMENT =
+    "CREATE TABLE IF NOT EXISTS %s (id %s, course text, marks int, PRIMARY KEY (id)) WITH read_repair='NONE';";

Review Comment:
   How about adding another test for the composite partition key case?



-- 
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: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org