adelapena commented on code in PR #2310:
URL: https://github.com/apache/cassandra/pull/2310#discussion_r1226550265
##########
src/java/org/apache/cassandra/cql3/selection/Selectable.java:
##########
@@ -721,6 +721,91 @@ public Selectable prepare(TableMetadata cfm)
/**
* <code>Selectable</code> for literal Lists.
*/
+ public static class WithArrayLiteral implements Selectable
+ {
+ /**
+ * The list elements
+ */
+ private final List<Selectable> selectables;
+
+ public WithArrayLiteral(List<Selectable> selectables)
+ {
+ this.selectables = selectables;
+ }
+
+ private Selectable target(AbstractType<?> target)
+ {
+ // when the target isn't known, fallback to list; cases like
"SELECT [1, 2]" can't be known, but used to be list type!
+ // If a vector is actually desired, then can use type cast/hints:
"SELECT (vector<int, 2>) [k, v1]"
+ if (target == null)
+ return new WithList(selectables);
+ if (target instanceof ListType)
+ return new WithList(selectables);
+ else if (target instanceof VectorType)
+ return new WithVector(selectables);
+ throw new IllegalArgumentException("Unsupported target type: " +
target.asCQL3Type());
+ }
+
+ @Override
+ public TestResult testAssignment(String keyspace, ColumnSpecification
receiver)
+ {
+ return target(receiver == null ? null :
receiver.type).testAssignment(keyspace, receiver);
+ }
+
+ @Override
+ public Factory newSelectorFactory(TableMetadata cfm,
+ AbstractType<?> expectedType,
+ List<ColumnMetadata> defs,
+ VariableSpecifications boundNames)
+ {
+ return target(expectedType).newSelectorFactory(cfm, expectedType,
defs, boundNames);
+ }
+
+ @Override
+ public AbstractType<?> getExactTypeIfKnown(String keyspace)
+ {
+ // TODO try to pass in a target to this API
+ // default to list when type is being infered
+ return new WithList(selectables).getExactTypeIfKnown(keyspace);
+ }
+
+ @Override
+ public AbstractType<?> getCompatibleTypeIfKnown(String keyspace)
+ {
+ // TODO try to pass in a target to this API
+ // default to list when type is being infered
Review Comment:
I guess we can do it when vector functions are added. It doesn't seem very
involved, I gave it a try to make this work with dynamic function factories:
https://github.com/adelapena/cassandra/commit/275ad5c78a07dbfb2ab313ed17b9f580411e62ed#diff-0e5a142c13247885605175ace136c549391fb6c778877f91f589fd94131c241b
--
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]