You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2021/08/10 20:59:39 UTC

[GitHub] [solr] thelabdude commented on a change in pull request #252: SOLR-9853: Improve SQL handling of multi-valued fields: project, group by, where filters

thelabdude commented on a change in pull request #252:
URL: https://github.com/apache/solr/pull/252#discussion_r686318203



##########
File path: solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java
##########
@@ -166,51 +193,54 @@ RelProtoDataType getRelDataType(String collection) {
       }
 
       RelDataType type;
-      switch (luceneFieldType) {
-        case "string":
-          type = typeFactory.createJavaType(String.class);
-          break;
-        case "tint":
-        case "tlong":
-        case "int":
-        case "long":
-        case "pint":
-        case "plong":
-          type = typeFactory.createJavaType(Long.class);
-          break;
-        case "tfloat":
-        case "tdouble":
-        case "float":
-        case "double":
-        case "pfloat":
-        case "pdouble":
-          type = typeFactory.createJavaType(Double.class);
-          break;
-        case "pdate":
-          type = typeFactory.createJavaType(Date.class);
-          break;
-        default:
-          Class<?> javaClass = javaClassForTypeMap.get(luceneFieldType);
-          if (javaClass == null) {
-            javaClass = guessJavaClassForFieldType(schema.getFieldTypeInfo().get(luceneFieldType));
-            javaClassForTypeMap.put(luceneFieldType, javaClass);
-          }
-          type = typeFactory.createJavaType(javaClass);
-      }
 
-      /*
-      EnumSet<FieldFlag> flags = luceneFieldInfo.parseFlags(luceneFieldInfo.getSchema());
-      if(flags != null && flags.contains(FieldFlag.MULTI_VALUED)) {
-        type = typeFactory.createArrayType(type, -1);
+      // We have to pass multi-valued fields through Calcite as SQL Type ANY
+      // Array doesn't work for aggregations! Calcite doesn't like GROUP BY on an ARRAY field
+      // but Solr happily computes aggs on a multi-valued field, so we have a paradigm mis-match and
+      // ANY is the best way to retain use of operators on multi-valued fields while still being able
+      // to GROUP BY and project the multi-valued fields in results
+      EnumSet<FieldFlag> flags = getFieldFlags(luceneFieldInfo);
+      if (flags != null && flags.contains(FieldFlag.MULTI_VALUED)) {
+        type = typeFactory.createSqlType(SqlTypeName.ANY);

Review comment:
       This is the crux of the change for this PR. If multi-valued, then we use type `ANY` which allows us to return multi-valued fields as a List, filter, and group by.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org