dcapwell commented on code in PR #3416:
URL: https://github.com/apache/cassandra/pull/3416#discussion_r1674920679
##########
test/unit/org/apache/cassandra/utils/CassandraGenerators.java:
##########
@@ -825,4 +876,145 @@ public static Gen<DecoratedKey>
decoratedKeys(Gen<IPartitioner> partitionerGen,
{
return rs ->
partitionerGen.generate(rs).decorateKey(keyGen.generate(rs));
}
+
+ public static String insertCqlAllColumns(TableMetadata metadata)
Review Comment:
I prob should migrate all usage to the `ast.Statement`, this was kinda a
limited hack and switching to the ast made things far better covered
##########
test/unit/org/apache/cassandra/utils/CassandraGenerators.java:
##########
@@ -825,4 +876,145 @@ public static Gen<DecoratedKey>
decoratedKeys(Gen<IPartitioner> partitionerGen,
{
return rs ->
partitionerGen.generate(rs).decorateKey(keyGen.generate(rs));
}
+
+ public static String insertCqlAllColumns(TableMetadata metadata)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("INSERT INTO ").append(metadata.toString()).append(" (");
+ Iterator<ColumnMetadata> cols = metadata.allColumnsInSelectOrder();
+ while (cols.hasNext())
+ sb.append(cols.next().name.toCQLString()).append(", ");
+ sb.setLength(sb.length() - 2); // remove last ", "
+ sb.append(") VALUES (");
+ for (int i = 0; i < metadata.columns().size(); i++)
+ {
+ if (i > 0)
+ sb.append(", ");
+ sb.append('?');
+ }
+ sb.append(')');
+ return sb.toString();
+ }
+
+ public static void visitUDTs(TableMetadata metadata, Consumer<UserType> fn)
+ {
+ Set<UserType> udts = CassandraGenerators.extractUDTs(metadata);
+ if (!udts.isEmpty())
+ {
+ Deque<UserType> pending = new ArrayDeque<>(udts);
+ Set<ByteBuffer> visited = new HashSet<>();
+ while (!pending.isEmpty())
+ {
+ UserType next = pending.poll();
+ Set<UserType> subTypes =
AbstractTypeGenerators.extractUDTs(next);
+ subTypes.remove(next); // it includes self
+ if (subTypes.isEmpty() || subTypes.stream().allMatch(t ->
visited.contains(t.name)))
+ {
+ fn.accept(next);
+ visited.add(next.name);
+ }
+ else
+ {
+ pending.add(next);
+ }
+ }
+ }
+ }
+
+ public static class DataGeneratorBuilder
Review Comment:
I prob should migrate all usage to the `ast.Statement`, this was kinda a
limited hack and switching to the ast made things far better covered
--
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]