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 2023/11/16 00:41:26 UTC
[PR] CASSANDRA-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
frankgh opened a new pull request, #20:
URL: https://github.com/apache/cassandra-analytics/pull/20
Cassandra in nature is case insensitive when creating identifiers (i.e. keyspace names, table names, column
names, etc.). We can define case-sensitive identifiers or use a reserved word as an identifier by quoting it
during DDL creation.
In the analytics library, bulk writing fails when we encounter these identifiers. In this commit, we fix the
issue by property propagating the information about whether identifiers need to be quoted by exposing a new data
frame option (`quote_identifiers`). When set to `true`, it will _maybe_ quote the keyspace/table/column names
and it will properly be able to write data when using mixed-case or reserved words in the identifiers.
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#discussion_r1419765509
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/CassandraClusterInfo.java:
##########
@@ -535,6 +548,15 @@ protected boolean isReplacement(RingEntry ringEntry)
return false;
}
+ protected CassandraBridge bridge()
+ {
+ if (bridge == null)
+ {
+ bridge = CassandraBridgeFactory.get(getLowestCassandraVersion());
Review Comment:
underlying ConcurrentHashMap in factory guarantees single bridge initialization here, so no need for synchronization
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#issuecomment-1847673499
Closed via https://github.com/apache/cassandra-analytics/commit/c7c3bbca2c7cb415b39689e924fa2357c239f043
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#discussion_r1419972095
##########
cassandra-analytics-core/src/test/java/org/apache/cassandra/spark/bulkwriter/TableSchemaTest.java:
##########
@@ -231,4 +234,10 @@ private TableSchemaTestCommon.MockTableSchemaBuilder getValidSchemaBuilder()
.withWriteMode(WriteMode.INSERT)
.withDataFrameSchema(validDataFrameSchema);
}
+
+ // Removes the unique table name to make validation consistent
+ private static String replaceTableName(String statement)
Review Comment:
table Id might cause confusion with Cassandra's table ID. I will rename it to `trimUniqueTableName`
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#discussion_r1419970047
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/QuoteIdentifiersWriteTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.LongStream;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.vertx.junit5.VertxExtension;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.sidecar.testing.QualifiedName;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.spark.SparkContext;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.api.java.function.Function2;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.SQLContext;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.types.StructType;
+
+import static org.apache.spark.sql.types.DataTypes.BinaryType;
+import static org.apache.spark.sql.types.DataTypes.LongType;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests the bulk writer behavior when requiring quoted identifiers for keyspace, table name, and column names.
+ *
+ * <p>These tests exercise a full integration test, which includes testing Sidecar behavior when dealing with quoted
+ * identifiers.
+ */
+@ExtendWith(VertxExtension.class)
+class QuoteIdentifiersWriteTest extends SparkIntegrationTestBase
+{
+ static final int ROW_COUNT = 10_000;
+
+ @CassandraIntegrationTest(nodesPerDc = 3, gossip = true)
Review Comment:
good point, we don't need 3 instances. I will lower it to 1
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#discussion_r1419958662
##########
cassandra-analytics-core/src/test/java/org/apache/cassandra/spark/bulkwriter/TableSchemaTest.java:
##########
@@ -231,4 +234,10 @@ private TableSchemaTestCommon.MockTableSchemaBuilder getValidSchemaBuilder()
.withWriteMode(WriteMode.INSERT)
.withDataFrameSchema(validDataFrameSchema);
}
+
+ // Removes the unique table name to make validation consistent
+ private static String replaceTableName(String statement)
Review Comment:
nit: how about rename to `trimTestTableId`?
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/QuoteIdentifiersWriteTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.LongStream;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.vertx.junit5.VertxExtension;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.sidecar.testing.QualifiedName;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.spark.SparkContext;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.api.java.function.Function2;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.SQLContext;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.types.StructType;
+
+import static org.apache.spark.sql.types.DataTypes.BinaryType;
+import static org.apache.spark.sql.types.DataTypes.LongType;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests the bulk writer behavior when requiring quoted identifiers for keyspace, table name, and column names.
+ *
+ * <p>These tests exercise a full integration test, which includes testing Sidecar behavior when dealing with quoted
+ * identifiers.
+ */
+@ExtendWith(VertxExtension.class)
+class QuoteIdentifiersWriteTest extends SparkIntegrationTestBase
+{
+ static final int ROW_COUNT = 10_000;
+
+ @CassandraIntegrationTest(nodesPerDc = 3, gossip = true)
Review Comment:
Does the test quire 3 nodes? If not, let's use 1 node to consume less resources.
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/CassandraClusterInfo.java:
##########
@@ -535,6 +548,15 @@ protected boolean isReplacement(RingEntry ringEntry)
return false;
}
+ protected CassandraBridge bridge()
+ {
+ if (bridge == null)
+ {
+ bridge = CassandraBridgeFactory.get(getLowestCassandraVersion());
Review Comment:
In that case, why not just call `CassandraBridgeFactory.get(getLowestCassandraVersion())`? Given the value effectively cached already.
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#issuecomment-1846610941
> lgtm overall. A few nits. Feel free to ignore.
Thanks for the review. I've addressed your comments.
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#issuecomment-1847620443
Squashed and lowered concurrency for JDK8 tests
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh closed pull request #20: CASSANDRA-19031: Fix bulk writing when using identifiers that need quotes
URL: https://github.com/apache/cassandra-analytics/pull/20
--
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-19031: Fix bulk writing when using identifiers that need quotes [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #20:
URL: https://github.com/apache/cassandra-analytics/pull/20#discussion_r1419969685
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/CassandraClusterInfo.java:
##########
@@ -535,6 +548,15 @@ protected boolean isReplacement(RingEntry ringEntry)
return false;
}
+ protected CassandraBridge bridge()
+ {
+ if (bridge == null)
+ {
+ bridge = CassandraBridgeFactory.get(getLowestCassandraVersion());
Review Comment:
yeah, having a local cache saves look ups from the map. But lookups are fast anyway, so I think we can remove the local field used as a cache
--
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