-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add native filter conversion for SCALAR_IN_ARRAY. (#16312)
* Add native filter conversion for SCALAR_IN_ARRAY. Main changes: 1) Add an implementation of "toDruidFilter" in ScalarInArrayOperatorConversion. 2) Split up Expressions.literalToDruidExpression into two functions, so the first half (literalToExprEval) can be used by ScalarInArrayOperatorConversion to more efficiently create the list of match values. * Fix type in time arithmetic conversion. * Test updates. * Update test cases to use null instead of '' in default-value mode. * Switch test from msqIncompatible to compatible with a different result. * Update one more test. * Fix test. * Update tests. * Use ExprEvalWrapper to differentiate between empty string and null. * Fix tests some more. * Fix test. * Additional comment. * Style adjustment. * Fix tests. * trueValue -> actualValue. * Use different approach, DruidLiteral instead of ExprEvalWrapper. * Revert changes in ArrayOfDoublesSketchSqlAggregatorTest.
- Loading branch information
Showing
10 changed files
with
723 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
sql/src/main/java/org/apache/druid/sql/calcite/expression/DruidLiteral.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.sql.calcite.expression; | ||
|
||
import org.apache.druid.common.config.NullHandling; | ||
import org.apache.druid.math.expr.ExprEval; | ||
import org.apache.druid.math.expr.ExpressionType; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Literal value, plus a {@link ExpressionType} that represents how to interpret the literal value. | ||
* | ||
* These are similar to {@link ExprEval}, but not identical: unlike {@link ExprEval}, string values in this class | ||
* are not normalized through {@link NullHandling#emptyToNullIfNeeded(String)}. This allows us to differentiate | ||
* between null and empty-string literals even when {@link NullHandling#replaceWithDefault()}. | ||
*/ | ||
public class DruidLiteral | ||
{ | ||
@Nullable | ||
private final ExpressionType type; | ||
|
||
@Nullable | ||
private final Object value; | ||
|
||
DruidLiteral(final ExpressionType type, @Nullable final Object value) | ||
{ | ||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
@Nullable | ||
public ExpressionType type() | ||
{ | ||
return type; | ||
} | ||
|
||
@Nullable | ||
public Object value() | ||
{ | ||
return value; | ||
} | ||
|
||
public DruidLiteral castTo(final ExpressionType toType) | ||
{ | ||
if (type.equals(toType)) { | ||
return this; | ||
} | ||
|
||
final ExprEval<?> castEval = ExprEval.ofType(type, value).castTo(toType); | ||
return new DruidLiteral(castEval.type(), castEval.value()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.