You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "skoppu22 (via GitHub)" <gi...@apache.org> on 2025/05/01 10:43:58 UTC
[PR] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
skoppu22 opened a new pull request, #109:
URL: https://github.com/apache/cassandra-analytics/pull/109
Currently Cassandra bulk writer not properly supporting UDTs inside collections. Also complex structures like collections inside UDTs are not supported properly. Adding support for these cases.
Note: Tuples with UDTs are not yet supported properly, it will be taken care in another Jira/PR
Circle CI passed: https://app.circleci.com/pipelines/github/skoppu22/cassandra-analytics/7/workflows/d4c1de5b-64b2-4ac5-96ee-e5a39b90ad85
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2074359925
##########
cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/testing/TestUtils.java:
##########
@@ -36,7 +36,7 @@ public final class TestUtils
private static final AtomicInteger TEST_TABLE_ID = new AtomicInteger(0);
// public static final int ROW_COUNT = 10_000;
- public static final int ROW_COUNT = 1_000;
+ public static final int ROW_COUNT = 100;
Review Comment:
can you revert the change? I assume you lower the row count for local testing.
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -389,19 +391,52 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
private Object maybeConvertUdt(Object value)
{
+ if (value instanceof List)
+ {
+ List<Object> resultList = new ArrayList<>();
+ for (Object entry : (List<?>) value)
+ {
+ resultList.add(maybeConvertUdt(entry));
+ }
+
+ return resultList;
+ }
+
+ if (value instanceof Set)
+ {
+ Set<Object> resultList = new HashSet<>();
+ for (Object entry : (Set<?>) value)
+ {
+ resultList.add(maybeConvertUdt(entry));
+ }
+
+ return resultList;
+ }
+
+ if (value instanceof Map)
+ {
+ Map<Object, Object> resultMap = new HashMap<>();
+ for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet())
+ {
+ resultMap.put(maybeConvertUdt(entry.getKey()), maybeConvertUdt(entry.getValue()));
+ }
+
+ return resultMap;
+ }
Review Comment:
those 3 branches will copy the list unnecessarily if they do _not_ contain UDT in the table schema. It would produce a lot of short-lived objects. Note that there are millions or more rows to write.
One idea to skip the unnecessary conversion is to check the table schema.
1. `RecordWriter` has access to the table schema, e.g. `CqlTable`.
2. `CqlTable` can mark the columns where contain UDT.
3. Instead of calling `maybeConvertUdt` on every column in each row, first check whether `maybeConvertUdt` should be invoked for this column. Now, since you know which columns contain UDT, you can even drop "maybe" from the method name. It would clarify the code too.
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -59,6 +59,59 @@ class BulkWriteUdtTest extends SharedClusterSparkIntegrationTestBase
+ " id BIGINT PRIMARY KEY,\n"
+ " nested " + NESTED_FIELD_UDT_NAME + ");";
+ // UDT with list, set and map in it
+ public static final String UDT_WITH_COLLECTIONS_TYPE_NAME = "udt_with_collections";
+ public static final String UDT_WITH_COLLECTIONS_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_COLLECTIONS_TYPE_NAME +
+ " (f1 list<text>, f2 set<int>, f3 map<int, text>);";
+
+ // table with list of UDTs, and UDT itself has collections in it
+ public static final QualifiedName LIST_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "list_of_udt_src");
+ public static final QualifiedName LIST_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "list_of_udt_dest");
+ public static final String LIST_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " udtlist frozen<list<frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">>>)";
+
+ // table with set of UDTs, and UDT itself has collections in it
+ public static final QualifiedName SET_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "set_of_udt_src");
+ public static final QualifiedName SET_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "set_of_udt_dest");
+ public static final String SET_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " udtset frozen<set<frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">>>)";
+
+ // table with map of UDTs, and UDT itself has collections in it
+ public static final QualifiedName MAP_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "map_of_udt_src");
+ public static final QualifiedName MAP_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "map_of_udt_dest");
+ public static final String MAP_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " udtmap frozen<map<frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">, frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">>>)";
+
+ // udt with list of UDTs inside it
+ public static final String UDT_WITH_LIST_OF_UDT_TYPE_NAME = "udt_with_list_of_udt_type";
+ public static final String UDT_WITH_LIST_OF_UDT_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_LIST_OF_UDT_TYPE_NAME +
+ " (innerudt list<frozen<" + TWO_FIELD_UDT_NAME + ">>);";
+ public static final QualifiedName UDT_WITH_LIST_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_list_of_udt_src");
+ public static final QualifiedName UDT_WITH_LIST_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_list_of_udt_dest");
+
+ // udt with set of UDTs inside it
+ public static final String UDT_WITH_SET_OF_UDT_TYPE_NAME = "udt_with_set_of_udt_type";
+ public static final String UDT_WITH_SET_OF_UDT_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_SET_OF_UDT_TYPE_NAME +
+ " (innerudt set<frozen<" + TWO_FIELD_UDT_NAME + ">>);";
+ public static final QualifiedName UDT_WITH_SET_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_set_of_udt_src");
+ public static final QualifiedName UDT_WITH_SET_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_set_of_udt_dest");
+
+ // udt with map of UDTs inside it
+ public static final String UDT_WITH_MAP_OF_UDT_TYPE_NAME = "udt_with_map_of_udt_type";
+ public static final String UDT_WITH_MAP_OF_UDT_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_MAP_OF_UDT_TYPE_NAME +
+ " (innerudt map<frozen<" + TWO_FIELD_UDT_NAME + ">, frozen<" + TWO_FIELD_UDT_NAME + ">>);";
+ public static final QualifiedName UDT_WITH_MAP_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_map_of_udt_src");
+ public static final QualifiedName UDT_WITH_MAP_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_map_of_udt_dest");
+
+ // Table with UDT which contains either a list or set or map of UDTs inside it
+ public static final String UDT_WITH_COLLECTION_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " outerudt frozen<%s>)";
+
+
Review Comment:
There is no test covering the scenario of UDTs in tuple. Are you going to update this patch or address in a follow-up? (I am OK with either of them)
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -32,7 +32,7 @@
import org.apache.spark.sql.SparkSession;
import org.jetbrains.annotations.NotNull;
-import static org.apache.cassandra.testing.TestUtils.DC1_RF3;
+import static org.apache.cassandra.testing.TestUtils.DC1_RF1;
Review Comment:
Curious about the reason of the change? If unnecessary, please revert.
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -88,17 +141,298 @@ void testWriteWithNestedUdt()
assertThat(result.hasNext()).isTrue();
validateWritesWithDriverResultSet(df.collectAsList(),
queryAllDataWithDriver(NESTED_TABLE_NAME),
- BulkWriteUdtTest::defaultRowFormatter);
+ BulkWriteUdtTest::udtRowFormatter);
+ }
+
+ @Test
+ void testListOfUdts()
+ {
+ int numRowsInserted = populateListOfUdts();
+
+ // Create a spark frame with the data inserted during the setup
+ Dataset<Row> sourceData = bulkReaderDataFrame(LIST_OF_UDT_SOURCE_TABLE).load();
+ assertThat(sourceData.count()).isEqualTo(numRowsInserted);
+
+ // Insert the dataset containing list of UDTs, and UDT itself has collections in it
+ bulkWriterDataFrameWriter(sourceData, LIST_OF_UDT_DEST_TABLE).save();
+ validateWritesWithDriverResultSet(sourceData.collectAsList(),
+ queryAllDataWithDriver(LIST_OF_UDT_DEST_TABLE),
+ BulkWriteUdtTest::listOfUdtRowFormatter);
+ }
+
+ private int populateListOfUdts()
+ {
+ // table(id, list<udt(list<>, set<>, map<>)>)
+ // insert list of UDTs, and each UDT has a list, set and map
+ String insertIntoListOfUdts = "INSERT INTO %s (id, udtlist) VALUES (%d, [{f1:['value %d'], f2:{%d}, f3:{%d : 'value %d'}}])";
+
+ int i = 0;
+ for (; i < ROW_COUNT; i++)
+ {
+ cluster.schemaChangeIgnoringStoppedInstances(String.format(insertIntoListOfUdts, LIST_OF_UDT_SOURCE_TABLE, i, i, i, i, i));
+ }
+
+ // test null cases
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id) values (%d)",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtlist) values (%d, null)",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtlist) values (%d, [{f1:null, f2:null, f3:null}])",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+
+ return i;
+ }
+
+ @Test
+ void testSetOfUdts()
+ {
+ int numRowsInserted = populateSetOfUdts();
+ // Create a spark frame with the data inserted during the setup
+ Dataset<Row> sourceData = bulkReaderDataFrame(SET_OF_UDT_SOURCE_TABLE).load();
+ assertThat(sourceData.count()).isEqualTo(numRowsInserted);
+
+ // Insert the dataset containing set of UDTs, and UDT itself has collections in it
+ bulkWriterDataFrameWriter(sourceData, SET_OF_UDT_DEST_TABLE).save();
+ validateWritesWithDriverResultSet(sourceData.collectAsList(),
+ queryAllDataWithDriver(SET_OF_UDT_DEST_TABLE),
+ BulkWriteUdtTest::setOfUdtRowFormatter);
+ }
+
+ private int populateSetOfUdts()
+ {
+ // table(id, set<udt(list<>, set<>, map<>)>)
+ // insert set of UDTs, and UDT has a list, set and map inside it
+ String insertIntoSetOfUdts = "INSERT INTO %s (id, udtset) VALUES (%d, " +
+ "{{f1:['value %d'], f2:{%d}, f3:{%d : 'value %d'}}})";
+
+ int i = 0;
+ for (; i < ROW_COUNT; i++)
+ {
+ cluster.schemaChangeIgnoringStoppedInstances(String.format(insertIntoSetOfUdts, SET_OF_UDT_SOURCE_TABLE,
+ i, i, i, i, i));
+ }
+
+ // test null cases
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id) values (%d)",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtset) values (%d, null)",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtset) values (%d, " +
+ "{{f1:null, f2:null, f3:null}})",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+
Review Comment:
`schemaChangeIgnoringStoppedInstances` is to change schema. It is not a proper use of the api to insert data.
I think you want to use `cluster.coordinator(1).executeWithResult(QUERY)` 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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2099856754
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/SharedClusterSparkIntegrationTestBase.java:
##########
@@ -171,28 +173,35 @@ public void checkSmallDataFrameEquality(Dataset<Row> expected, Dataset<Row> actu
}
}
- public void validateWritesWithDriverResultSet(List<Row> sourceData, ResultSet queriedData,
- Function<com.datastax.driver.core.Row, String> rowFormatter)
+ public void validateWritesWithDriverResultSet(List<Row> sparkData, ResultSet driverData,
+ Function<com.datastax.driver.core.Row, String> driverRowFormatter)
{
- Set<String> actualEntries = new HashSet<>();
- queriedData.forEach(row -> actualEntries.add(rowFormatter.apply(row)));
+ Set<String> driverEntries = new HashSet<>();
+ driverData.forEach(row -> driverEntries.add(driverRowFormatter
+ .apply(row)
+ // Driver Codec writes "NULL" for null value. Spark DF writes "null".
+ .replace("NULL", "null")
+ // driver writes lists as [] and sets as {},
+ // whereas spark entries have the same type WrappedArray for both lists and sets
+ .replace('[', '{')
+ .replace(']', '}')));
Review Comment:
Moved out collections specific formatting to corresponding formatter, to avoid other tests getting impacted by chance
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2095787453
##########
cassandra-analytics-common/src/main/java/org/apache/cassandra/spark/data/CqlTable.java:
##########
@@ -242,6 +246,31 @@ public int indexCount()
return indexCount;
}
+ /**
+ * Check each column of the table for UDT type somewhere nested inside it and maintain map of true/false accordingly
+ * @return map of column name to true/false
+ */
+ private Map<String, Boolean> determineColumnsWithUdts()
+ {
+ Map<String, Boolean> columnsWithUdts = new HashMap<>();
+ for (Map.Entry<String, CqlField> field : fieldsMap.entrySet())
+ {
+ columnsWithUdts.put(field.getKey(), !(field.getValue().type().udts().isEmpty()));
+ }
+
+ return columnsWithUdts;
+ }
+
+ /**
+ * Determines if a column has UDT type somewhere nested inside it
+ * @param fieldName name of the column
+ * @return true if the column has UDT type , false otherwise
+ */
+ public boolean containsUdt(String fieldName)
Review Comment:
We use the word UDT extensively all over the repo. Better to keep the name containsUdt to be inline with remaining code.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2095850224
##########
cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/testing/TestUtils.java:
##########
@@ -36,7 +36,7 @@ public final class TestUtils
private static final AtomicInteger TEST_TABLE_ID = new AtomicInteger(0);
// public static final int ROW_COUNT = 10_000;
- public static final int ROW_COUNT = 1_000;
+ public static final int ROW_COUNT = 100;
Review Comment:
I am seeing quite slower runs, sometimes timeouts only when running under Intellij. Reverted this change.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2101256916
##########
CHANGES.txt:
##########
@@ -1,4 +1,5 @@
1.0.0
+ * Bulk writer needs to support collections with UDTs
Review Comment:
can we add the ticket here?
```suggestion
* Bulk writer needs to support collections with UDTs (CASSANALYTICS-49)
```
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2095806449
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -380,28 +382,69 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
{
Preconditions.checkArgument(values.length == columnNames.length,
"Number of values does not match the number of columns " + values.length + ", " + columnNames.length);
+
for (int i = 0; i < columnNames.length; i++)
{
- map.put(columnNames[i], maybeConvertUdt(values[i]));
+ if (cqlTable().containsUdt(columnNames[i]))
Review Comment:
cqlTable() already uses a class local variable `cqlTable`, populates it only once if it is not set and references the same in subsequent invocations. Using a local variable here in this caller only avoids the function call, but compiler must be smart enough to avoid subsequent calls I believe. Also `cqlTable` is volatile, there must be a reason for making it volatile, so better we reference the same. Infact we can reference that class local variable `cqlTable` directly here by calling cqlTable() only once in the class init, but I wouldn't do that without understanding why it was implemented this way previously.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2096203009
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -380,28 +382,69 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
{
Preconditions.checkArgument(values.length == columnNames.length,
"Number of values does not match the number of columns " + values.length + ", " + columnNames.length);
+
for (int i = 0; i < columnNames.length; i++)
{
- map.put(columnNames[i], maybeConvertUdt(values[i]));
+ if (cqlTable().containsUdt(columnNames[i]))
Review Comment:
> Infact we can reference that class local variable cqlTable directly here by calling cqlTable() only once in the class init
This sounds good. Given that the writer requires cqlTable to be initialized, the initialization can be done eagerly.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2095858316
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/SharedClusterSparkIntegrationTestBase.java:
##########
@@ -171,28 +173,35 @@ public void checkSmallDataFrameEquality(Dataset<Row> expected, Dataset<Row> actu
}
}
- public void validateWritesWithDriverResultSet(List<Row> sourceData, ResultSet queriedData,
- Function<com.datastax.driver.core.Row, String> rowFormatter)
+ public void validateWritesWithDriverResultSet(List<Row> sparkData, ResultSet driverData,
+ Function<com.datastax.driver.core.Row, String> driverRowFormatter)
{
- Set<String> actualEntries = new HashSet<>();
- queriedData.forEach(row -> actualEntries.add(rowFormatter.apply(row)));
+ Set<String> driverEntries = new HashSet<>();
+ driverData.forEach(row -> driverEntries.add(driverRowFormatter
+ .apply(row)
+ // Driver Codec writes "NULL" for null value. Spark DF writes "null".
+ .replace("NULL", "null")
+ // driver writes lists as [] and sets as {},
+ // whereas spark entries have the same type WrappedArray for both lists and sets
+ .replace('[', '{')
+ .replace(']', '}')));
Review Comment:
Which function do you mean? We repeat the same logic for all driver entries formatters for UDTs (and also Tuples which is coming up today). So keeping it in one place instead of repeating the same in each formatter.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2081801395
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -389,19 +391,52 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
private Object maybeConvertUdt(Object value)
{
+ if (value instanceof List)
+ {
+ List<Object> resultList = new ArrayList<>();
+ for (Object entry : (List<?>) value)
+ {
+ resultList.add(maybeConvertUdt(entry));
+ }
+
+ return resultList;
+ }
+
+ if (value instanceof Set)
+ {
+ Set<Object> resultList = new HashSet<>();
+ for (Object entry : (Set<?>) value)
+ {
+ resultList.add(maybeConvertUdt(entry));
+ }
+
+ return resultList;
+ }
+
+ if (value instanceof Map)
+ {
+ Map<Object, Object> resultMap = new HashMap<>();
+ for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet())
+ {
+ resultMap.put(maybeConvertUdt(entry.getKey()), maybeConvertUdt(entry.getValue()));
+ }
+
+ return resultMap;
+ }
Review Comment:
- Updated CqlTable to maintain columns with UDTs and check it before calling maybeConvertUdt
- There’s still a chance of creating unnecessary lists, sets, or maps, like udt<list<udt<set<map>>>>. We create new sets and maps without knowing if there are more UDTs inside. I tried counting UDTs in a column (inside determineColumnsWithUdts) to avoid this, but it may not work for all cases. It doesn’t differentiate when the same UDT type is used multiple times, like in map<udtType1, udtType1>, where the UDT count is 1 instead of 2. This is fine for Maps, but it could break things in non-Map cases.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2075299058
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -32,7 +32,7 @@
import org.apache.spark.sql.SparkSession;
import org.jetbrains.annotations.NotNull;
-import static org.apache.cassandra.testing.TestUtils.DC1_RF3;
+import static org.apache.cassandra.testing.TestUtils.DC1_RF1;
Review Comment:
This should be reverted, was needed only for local testing
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2081781154
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -88,17 +141,298 @@ void testWriteWithNestedUdt()
assertThat(result.hasNext()).isTrue();
validateWritesWithDriverResultSet(df.collectAsList(),
queryAllDataWithDriver(NESTED_TABLE_NAME),
- BulkWriteUdtTest::defaultRowFormatter);
+ BulkWriteUdtTest::udtRowFormatter);
+ }
+
+ @Test
+ void testListOfUdts()
+ {
+ int numRowsInserted = populateListOfUdts();
+
+ // Create a spark frame with the data inserted during the setup
+ Dataset<Row> sourceData = bulkReaderDataFrame(LIST_OF_UDT_SOURCE_TABLE).load();
+ assertThat(sourceData.count()).isEqualTo(numRowsInserted);
+
+ // Insert the dataset containing list of UDTs, and UDT itself has collections in it
+ bulkWriterDataFrameWriter(sourceData, LIST_OF_UDT_DEST_TABLE).save();
+ validateWritesWithDriverResultSet(sourceData.collectAsList(),
+ queryAllDataWithDriver(LIST_OF_UDT_DEST_TABLE),
+ BulkWriteUdtTest::listOfUdtRowFormatter);
+ }
+
+ private int populateListOfUdts()
+ {
+ // table(id, list<udt(list<>, set<>, map<>)>)
+ // insert list of UDTs, and each UDT has a list, set and map
+ String insertIntoListOfUdts = "INSERT INTO %s (id, udtlist) VALUES (%d, [{f1:['value %d'], f2:{%d}, f3:{%d : 'value %d'}}])";
+
+ int i = 0;
+ for (; i < ROW_COUNT; i++)
+ {
+ cluster.schemaChangeIgnoringStoppedInstances(String.format(insertIntoListOfUdts, LIST_OF_UDT_SOURCE_TABLE, i, i, i, i, i));
+ }
+
+ // test null cases
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id) values (%d)",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtlist) values (%d, null)",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtlist) values (%d, [{f1:null, f2:null, f3:null}])",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+
+ return i;
+ }
+
+ @Test
+ void testSetOfUdts()
+ {
+ int numRowsInserted = populateSetOfUdts();
+ // Create a spark frame with the data inserted during the setup
+ Dataset<Row> sourceData = bulkReaderDataFrame(SET_OF_UDT_SOURCE_TABLE).load();
+ assertThat(sourceData.count()).isEqualTo(numRowsInserted);
+
+ // Insert the dataset containing set of UDTs, and UDT itself has collections in it
+ bulkWriterDataFrameWriter(sourceData, SET_OF_UDT_DEST_TABLE).save();
+ validateWritesWithDriverResultSet(sourceData.collectAsList(),
+ queryAllDataWithDriver(SET_OF_UDT_DEST_TABLE),
+ BulkWriteUdtTest::setOfUdtRowFormatter);
+ }
+
+ private int populateSetOfUdts()
+ {
+ // table(id, set<udt(list<>, set<>, map<>)>)
+ // insert set of UDTs, and UDT has a list, set and map inside it
+ String insertIntoSetOfUdts = "INSERT INTO %s (id, udtset) VALUES (%d, " +
+ "{{f1:['value %d'], f2:{%d}, f3:{%d : 'value %d'}}})";
+
+ int i = 0;
+ for (; i < ROW_COUNT; i++)
+ {
+ cluster.schemaChangeIgnoringStoppedInstances(String.format(insertIntoSetOfUdts, SET_OF_UDT_SOURCE_TABLE,
+ i, i, i, i, i));
+ }
+
+ // test null cases
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id) values (%d)",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtset) values (%d, null)",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtset) values (%d, " +
+ "{{f1:null, f2:null, f3:null}})",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+
Review Comment:
- schemaChangeIgnoringStoppedInstances also uses executeWithResult internally, but it uses Monitor additionally.
- Changed to use execute for insert and select queries
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2095817571
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -380,28 +382,69 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
{
Preconditions.checkArgument(values.length == columnNames.length,
"Number of values does not match the number of columns " + values.length + ", " + columnNames.length);
+
for (int i = 0; i < columnNames.length; i++)
{
- map.put(columnNames[i], maybeConvertUdt(values[i]));
+ if (cqlTable().containsUdt(columnNames[i]))
Review Comment:
I see @yifan-c added cqlTable. @yifan-c Can we call cqlTable() only once in the class init and reference the class local variable in rest of the class? I see `cqlTable` is volatile, but it is assigned only once when it is null. Does it need to be really volatile?
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2095806449
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -380,28 +382,69 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
{
Preconditions.checkArgument(values.length == columnNames.length,
"Number of values does not match the number of columns " + values.length + ", " + columnNames.length);
+
for (int i = 0; i < columnNames.length; i++)
{
- map.put(columnNames[i], maybeConvertUdt(values[i]));
+ if (cqlTable().containsUdt(columnNames[i]))
Review Comment:
cqlTable() already uses a class local variable `cqlTable`, populates it only once if it is not set and references the same in subsequent invocations. Using a local variable here in this caller only avoids the function call, but compiler must be smart enough to avoid subsequent calls I believe. Also `cqlTable` is volatile, there must be a reason for making it volatile, so better we reference the same. Infact we can reference that class local variable `cqlTable` directly here calling cqlTable(), but I would avoid that to be safe from future breaking changes if any.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2096087782
##########
cassandra-analytics-common/src/main/java/org/apache/cassandra/spark/data/CqlTable.java:
##########
@@ -242,6 +246,31 @@ public int indexCount()
return indexCount;
}
+ /**
+ * Check each column of the table for UDT type somewhere nested inside it and maintain map of true/false accordingly
+ * @return map of column name to true/false
+ */
+ private Map<String, Boolean> determineColumnsWithUdts()
+ {
+ Map<String, Boolean> columnsWithUdts = new HashMap<>();
+ for (Map.Entry<String, CqlField> field : fieldsMap.entrySet())
+ {
+ columnsWithUdts.put(field.getKey(), !(field.getValue().type().udts().isEmpty()));
+ }
+
+ return columnsWithUdts;
+ }
+
+ /**
+ * Determines if a column has UDT type somewhere nested inside it
+ * @param fieldName name of the column
+ * @return true if the column has UDT type , false otherwise
+ */
+ public boolean containsUdt(String fieldName)
Review Comment:
Sounds good. Given that you added the detailed javadoc (awesome!), I have no concern.
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2075300073
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -59,6 +59,59 @@ class BulkWriteUdtTest extends SharedClusterSparkIntegrationTestBase
+ " id BIGINT PRIMARY KEY,\n"
+ " nested " + NESTED_FIELD_UDT_NAME + ");";
+ // UDT with list, set and map in it
+ public static final String UDT_WITH_COLLECTIONS_TYPE_NAME = "udt_with_collections";
+ public static final String UDT_WITH_COLLECTIONS_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_COLLECTIONS_TYPE_NAME +
+ " (f1 list<text>, f2 set<int>, f3 map<int, text>);";
+
+ // table with list of UDTs, and UDT itself has collections in it
+ public static final QualifiedName LIST_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "list_of_udt_src");
+ public static final QualifiedName LIST_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "list_of_udt_dest");
+ public static final String LIST_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " udtlist frozen<list<frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">>>)";
+
+ // table with set of UDTs, and UDT itself has collections in it
+ public static final QualifiedName SET_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "set_of_udt_src");
+ public static final QualifiedName SET_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "set_of_udt_dest");
+ public static final String SET_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " udtset frozen<set<frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">>>)";
+
+ // table with map of UDTs, and UDT itself has collections in it
+ public static final QualifiedName MAP_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "map_of_udt_src");
+ public static final QualifiedName MAP_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "map_of_udt_dest");
+ public static final String MAP_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " udtmap frozen<map<frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">, frozen<" + UDT_WITH_COLLECTIONS_TYPE_NAME + ">>>)";
+
+ // udt with list of UDTs inside it
+ public static final String UDT_WITH_LIST_OF_UDT_TYPE_NAME = "udt_with_list_of_udt_type";
+ public static final String UDT_WITH_LIST_OF_UDT_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_LIST_OF_UDT_TYPE_NAME +
+ " (innerudt list<frozen<" + TWO_FIELD_UDT_NAME + ">>);";
+ public static final QualifiedName UDT_WITH_LIST_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_list_of_udt_src");
+ public static final QualifiedName UDT_WITH_LIST_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_list_of_udt_dest");
+
+ // udt with set of UDTs inside it
+ public static final String UDT_WITH_SET_OF_UDT_TYPE_NAME = "udt_with_set_of_udt_type";
+ public static final String UDT_WITH_SET_OF_UDT_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_SET_OF_UDT_TYPE_NAME +
+ " (innerudt set<frozen<" + TWO_FIELD_UDT_NAME + ">>);";
+ public static final QualifiedName UDT_WITH_SET_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_set_of_udt_src");
+ public static final QualifiedName UDT_WITH_SET_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_set_of_udt_dest");
+
+ // udt with map of UDTs inside it
+ public static final String UDT_WITH_MAP_OF_UDT_TYPE_NAME = "udt_with_map_of_udt_type";
+ public static final String UDT_WITH_MAP_OF_UDT_TYPE_CREATE = "CREATE TYPE " + TEST_KEYSPACE + "." + UDT_WITH_MAP_OF_UDT_TYPE_NAME +
+ " (innerudt map<frozen<" + TWO_FIELD_UDT_NAME + ">, frozen<" + TWO_FIELD_UDT_NAME + ">>);";
+ public static final QualifiedName UDT_WITH_MAP_OF_UDT_SOURCE_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_map_of_udt_src");
+ public static final QualifiedName UDT_WITH_MAP_OF_UDT_DEST_TABLE = new QualifiedName(TEST_KEYSPACE, "udt_with_map_of_udt_dest");
+
+ // Table with UDT which contains either a list or set or map of UDTs inside it
+ public static final String UDT_WITH_COLLECTION_OF_UDT_TABLE_CREATE = "CREATE TABLE %s.%s (\n"
+ + " id BIGINT PRIMARY KEY,\n"
+ + " outerudt frozen<%s>)";
+
+
Review Comment:
As I mentioned in the PR description, there is lot more to be done to handle Tuples, support for Tuples will come in another PR/task
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2075295112
##########
cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/testing/TestUtils.java:
##########
@@ -36,7 +36,7 @@ public final class TestUtils
private static final AtomicInteger TEST_TABLE_ID = new AtomicInteger(0);
// public static final int ROW_COUNT = 10_000;
- public static final int ROW_COUNT = 1_000;
+ public static final int ROW_COUNT = 100;
Review Comment:
Some tests were timing out when ran on local, especially when ran from Intellij, so had to reduce it. Can we just continue with lesser number of rows so we don't need to change this on local everytime we run?
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c merged PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2096092205
##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/RecordWriter.java:
##########
@@ -380,28 +382,69 @@ private Map<String, Object> getBindValuesForColumns(Map<String, Object> map, Str
{
Preconditions.checkArgument(values.length == columnNames.length,
"Number of values does not match the number of columns " + values.length + ", " + columnNames.length);
+
for (int i = 0; i < columnNames.length; i++)
{
- map.put(columnNames[i], maybeConvertUdt(values[i]));
+ if (cqlTable().containsUdt(columnNames[i]))
Review Comment:
I think we want to avoid having a call to a method in a tight loop. So it's better to get a reference of this variable before the loop
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#issuecomment-2891821490
Please update `CHANGES.txt`
--
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] CASSANALYTICS-49: Support UDTs inside collections [cassandra-analytics]
Posted by "skoppu22 (via GitHub)" <gi...@apache.org>.
skoppu22 commented on code in PR #109:
URL: https://github.com/apache/cassandra-analytics/pull/109#discussion_r2081780842
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -32,7 +32,7 @@
import org.apache.spark.sql.SparkSession;
import org.jetbrains.annotations.NotNull;
-import static org.apache.cassandra.testing.TestUtils.DC1_RF3;
+import static org.apache.cassandra.testing.TestUtils.DC1_RF1;
Review Comment:
Done
##########
cassandra-analytics-integration-tests/src/test/java/org/apache/cassandra/analytics/BulkWriteUdtTest.java:
##########
@@ -88,17 +141,298 @@ void testWriteWithNestedUdt()
assertThat(result.hasNext()).isTrue();
validateWritesWithDriverResultSet(df.collectAsList(),
queryAllDataWithDriver(NESTED_TABLE_NAME),
- BulkWriteUdtTest::defaultRowFormatter);
+ BulkWriteUdtTest::udtRowFormatter);
+ }
+
+ @Test
+ void testListOfUdts()
+ {
+ int numRowsInserted = populateListOfUdts();
+
+ // Create a spark frame with the data inserted during the setup
+ Dataset<Row> sourceData = bulkReaderDataFrame(LIST_OF_UDT_SOURCE_TABLE).load();
+ assertThat(sourceData.count()).isEqualTo(numRowsInserted);
+
+ // Insert the dataset containing list of UDTs, and UDT itself has collections in it
+ bulkWriterDataFrameWriter(sourceData, LIST_OF_UDT_DEST_TABLE).save();
+ validateWritesWithDriverResultSet(sourceData.collectAsList(),
+ queryAllDataWithDriver(LIST_OF_UDT_DEST_TABLE),
+ BulkWriteUdtTest::listOfUdtRowFormatter);
+ }
+
+ private int populateListOfUdts()
+ {
+ // table(id, list<udt(list<>, set<>, map<>)>)
+ // insert list of UDTs, and each UDT has a list, set and map
+ String insertIntoListOfUdts = "INSERT INTO %s (id, udtlist) VALUES (%d, [{f1:['value %d'], f2:{%d}, f3:{%d : 'value %d'}}])";
+
+ int i = 0;
+ for (; i < ROW_COUNT; i++)
+ {
+ cluster.schemaChangeIgnoringStoppedInstances(String.format(insertIntoListOfUdts, LIST_OF_UDT_SOURCE_TABLE, i, i, i, i, i));
+ }
+
+ // test null cases
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id) values (%d)",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtlist) values (%d, null)",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtlist) values (%d, [{f1:null, f2:null, f3:null}])",
+ LIST_OF_UDT_SOURCE_TABLE, i++));
+
+ return i;
+ }
+
+ @Test
+ void testSetOfUdts()
+ {
+ int numRowsInserted = populateSetOfUdts();
+ // Create a spark frame with the data inserted during the setup
+ Dataset<Row> sourceData = bulkReaderDataFrame(SET_OF_UDT_SOURCE_TABLE).load();
+ assertThat(sourceData.count()).isEqualTo(numRowsInserted);
+
+ // Insert the dataset containing set of UDTs, and UDT itself has collections in it
+ bulkWriterDataFrameWriter(sourceData, SET_OF_UDT_DEST_TABLE).save();
+ validateWritesWithDriverResultSet(sourceData.collectAsList(),
+ queryAllDataWithDriver(SET_OF_UDT_DEST_TABLE),
+ BulkWriteUdtTest::setOfUdtRowFormatter);
+ }
+
+ private int populateSetOfUdts()
+ {
+ // table(id, set<udt(list<>, set<>, map<>)>)
+ // insert set of UDTs, and UDT has a list, set and map inside it
+ String insertIntoSetOfUdts = "INSERT INTO %s (id, udtset) VALUES (%d, " +
+ "{{f1:['value %d'], f2:{%d}, f3:{%d : 'value %d'}}})";
+
+ int i = 0;
+ for (; i < ROW_COUNT; i++)
+ {
+ cluster.schemaChangeIgnoringStoppedInstances(String.format(insertIntoSetOfUdts, SET_OF_UDT_SOURCE_TABLE,
+ i, i, i, i, i));
+ }
+
+ // test null cases
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id) values (%d)",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtset) values (%d, null)",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+ cluster.schemaChangeIgnoringStoppedInstances(String.format("insert into %s (id, udtset) values (%d, " +
+ "{{f1:null, f2:null, f3:null}})",
+ SET_OF_UDT_SOURCE_TABLE, i++));
+
Review Comment:
Changed to use execute()
--
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