mirror of https://github.com/apache/druid.git
use CastToObjectVectorProcessor for cast to string (#17148)
This commit is contained in:
parent
83299e9882
commit
0ec7eb3ae5
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue