github-code-scanning[bot] commented on code in PR #14542:
URL: https://github.com/apache/druid/pull/14542#discussion_r1264306335


##########
processing/src/main/java/org/apache/druid/segment/AutoTypeColumnIndexer.java:
##########
@@ -223,28 +224,45 @@
   )
   {
     final int dimIndex = desc.getIndex();
+    if (fieldIndexers.size() == 0 && isConstant && !hasNestedData) {
+      return DimensionSelector.constant(null, spec.getExtractionFn());
+    }
     final ColumnValueSelector<?> rootLiteralSelector = 
getRootLiteralValueSelector(currEntry, dimIndex);
     if (rootLiteralSelector != null) {
       final FieldIndexer root = 
fieldIndexers.get(NestedPathFinder.JSON_PATH_ROOT);
-      final ColumnType rootType = root.getTypes().getSingleType();
+      final ColumnType rootType = root.isSingleType() ? 
root.getTypes().getSingleType() : getLogicalType();
       if (rootType.isArray()) {
         throw new UOE(
             "makeDimensionSelector is not supported, column [%s] is [%s] typed 
and should only use makeColumnValueSelector",
             spec.getOutputName(),
             rootType
         );
       }
+      if (spec.getExtractionFn() == null) {

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [DimensionSpec.getExtractionFn](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5284)



##########
processing/src/main/java/org/apache/druid/segment/AutoTypeColumnIndexer.java:
##########
@@ -223,28 +224,45 @@
   )
   {
     final int dimIndex = desc.getIndex();
+    if (fieldIndexers.size() == 0 && isConstant && !hasNestedData) {
+      return DimensionSelector.constant(null, spec.getExtractionFn());
+    }
     final ColumnValueSelector<?> rootLiteralSelector = 
getRootLiteralValueSelector(currEntry, dimIndex);
     if (rootLiteralSelector != null) {
       final FieldIndexer root = 
fieldIndexers.get(NestedPathFinder.JSON_PATH_ROOT);
-      final ColumnType rootType = root.getTypes().getSingleType();
+      final ColumnType rootType = root.isSingleType() ? 
root.getTypes().getSingleType() : getLogicalType();
       if (rootType.isArray()) {
         throw new UOE(
             "makeDimensionSelector is not supported, column [%s] is [%s] typed 
and should only use makeColumnValueSelector",
             spec.getOutputName(),
             rootType
         );
       }
+      if (spec.getExtractionFn() == null) {
+        return new BaseSingleValueDimensionSelector()
+        {
+          @Nullable
+          @Override
+          protected String getValue()
+          {
+            return Evals.asString(rootLiteralSelector.getObject());
+          }
+
+          @Override
+          public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+          {
+
+          }
+        };
+      }
       return new BaseSingleValueDimensionSelector()
       {
         @Nullable
         @Override
         protected String getValue()
         {
-          final Object o = rootLiteralSelector.getObject();
-          if (o == null) {
-            return null;
-          }
-          return o.toString();
+          final String s = Evals.asString(rootLiteralSelector.getObject());
+          return spec.getExtractionFn().apply(s);

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [DimensionSpec.getExtractionFn](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5285)



-- 
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]

Reply via email to