You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by cw...@apache.org on 2024/09/24 22:21:39 UTC

(druid) branch master updated: use CastToObjectVectorProcessor for cast to string (#17148)

This is an automated email from the ASF dual-hosted git repository.

cwylie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ec7eb3ae5f use CastToObjectVectorProcessor for cast to string (#17148)
0ec7eb3ae5f is described below

commit 0ec7eb3ae5ffc9caf852bd63551d03660d624e04
Author: Clint Wylie <cw...@apache.org>
AuthorDate: Tue Sep 24 15:21:33 2024 -0700

    use CastToObjectVectorProcessor for cast to string (#17148)
---
 .../expr/vector/CastToStringVectorProcessor.java   | 52 ----------------------
 .../expr/vector/CastToTypeVectorProcessor.java     |  3 --
 .../druid/math/expr/VectorExprSanityTest.java      | 10 +++++
 3 files changed, 10 insertions(+), 55 deletions(-)

diff --git a/processing/src/main/java/org/apache/druid/math/expr/vector/CastToStringVectorProcessor.java b/processing/src/main/java/org/apache/druid/math/expr/vector/CastToStringVectorProcessor.java
deleted file mode 100644
index e3d5f06f8a1..00000000000
--- a/processing/src/main/java/org/apache/druid/math/expr/vector/CastToStringVectorProcessor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.druid.math.expr.vector;
-
-import org.apache.druid.math.expr.Evals;
-import org.apache.druid.math.expr.Expr;
-import org.apache.druid.math.expr.ExpressionType;
-
-public final class CastToStringVectorProcessor extends CastToTypeVectorProcessor<Object[]>
-{
-  private final Object[] output;
-
-  public CastToStringVectorProcessor(ExprVectorProcessor<?> delegate, int maxVectorSize)
-  {
-    super(delegate);
-    this.output = new Object[maxVectorSize];
-  }
-
-  @Override
-  public ExprEvalVector<Object[]> evalVector(Expr.VectorInputBinding bindings)
-  {
-    ExprEvalVector<?> result = delegate.evalVector(bindings);
-    final Object[] objects = result.getObjectVector();
-    for (int i = 0; i < bindings.getCurrentVectorSize(); i++) {
-      output[i] = Evals.asString(objects[i]);
-    }
-    return new ExprEvalObjectVector(output, ExpressionType.STRING);
-  }
-
-  @Override
-  public ExpressionType getOutputType()
-  {
-    return ExpressionType.STRING;
-  }
-}
diff --git a/processing/src/main/java/org/apache/druid/math/expr/vector/CastToTypeVectorProcessor.java b/processing/src/main/java/org/apache/druid/math/expr/vector/CastToTypeVectorProcessor.java
index c6448b67ed2..62f2cf505ff 100644
--- a/processing/src/main/java/org/apache/druid/math/expr/vector/CastToTypeVectorProcessor.java
+++ b/processing/src/main/java/org/apache/druid/math/expr/vector/CastToTypeVectorProcessor.java
@@ -42,9 +42,6 @@ public abstract class CastToTypeVectorProcessor<TOutput> implements ExprVectorPr
       caster = castInput;
     } else {
       switch (castToType.getType()) {
-        case STRING:
-          caster = new CastToStringVectorProcessor(castInput, maxVectorSize);
-          break;
         case LONG:
           caster = new CastToLongVectorProcessor(castInput);
           break;
diff --git a/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java b/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java
index 5a32e8f505d..cf513b4ffba 100644
--- a/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java
+++ b/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java
@@ -271,6 +271,16 @@ public class VectorExprSanityTest extends InitializedNullHandlingTest
     testExpression("array(s1, l2)", types);
   }
 
+  @Test
+  public void testCastArraysRoundTrip()
+  {
+    testExpression("cast(cast(s1, 'ARRAY<STRING>'), 'STRING')", types);
+    testExpression("cast(cast(d1, 'ARRAY<DOUBLE>'), 'DOUBLE')", types);
+    testExpression("cast(cast(d1, 'ARRAY<STRING>'), 'DOUBLE')", types);
+    testExpression("cast(cast(l1, 'ARRAY<LONG>'), 'LONG')", types);
+    testExpression("cast(cast(l1, 'ARRAY<STRING>'), 'LONG')", types);
+  }
+
   @Test
   public void testJsonFns()
   {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org