Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Apr 12, 2024
1 parent 6303057 commit adb37a0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public boolean isBangEqualAllowed()
return true;
}

@Override
public boolean allowLenientCoercion()
{
return true ;
}

@Override
public boolean isSortByOrdinal()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
package org.apache.druid.sql.calcite.planner.convertlet;

import com.google.common.collect.ImmutableList;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlDataTypeSpec;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.fun.SqlCastFunction;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.type.SqlTypeUtil;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql2rel.SqlRexContext;
import org.apache.calcite.sql2rel.SqlRexConvertlet;
import org.apache.calcite.sql2rel.SqlRexConvertletTable;
import org.apache.calcite.sql2rel.StandardConvertletTable;
import org.apache.druid.sql.calcite.expression.builtin.NestedDataOperatorConversions;
import org.apache.druid.sql.calcite.planner.PlannerContext;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -79,6 +89,51 @@ public DruidConvertletTable(final PlannerContext plannerContext)
@Override
public SqlRexConvertlet get(SqlCall call)
{
if(false && call.getKind() == SqlKind.CAST ) {
@Nullable
SqlRexConvertlet def = StandardConvertletTable.INSTANCE.get(call);
return new SqlRexConvertlet()
{

@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call)
{
if(false) {
SqlNode left=call.getOperandList().get(0);
SqlNode right=call.getOperandList().get(1);
final RexNode arg = cx.convertExpression(left);
final SqlDataTypeSpec dataType = (SqlDataTypeSpec) right;
SqlValidator validator= cx.getValidator();
RelDataType type =
SqlCastFunction.deriveType(cx.getTypeFactory(), arg.getType(),
dataType.deriveType(validator), false);
if (arg.getType().getSqlTypeName() == SqlTypeName.BOOLEAN && SqlTypeUtil.isIntType(type)) {
validator.setValidatedNodeType(left, type);
return cx.convertExpression(left);
}
}
SqlNode left=call.getOperandList().get(0);
SqlNode right=call.getOperandList().get(1);
SqlValidator validator= cx.getValidator();
final SqlDataTypeSpec dataType = (SqlDataTypeSpec) right;
if(SqlTypeUtil.isNumeric(dataType.deriveType(validator))) {
final RexNode arg = cx.convertExpression(left);
RelDataType type =
SqlCastFunction.deriveType(cx.getTypeFactory(), arg.getType(),
dataType.deriveType(validator), false);
if (arg.getType().getSqlTypeName() == SqlTypeName.BOOLEAN && SqlTypeUtil.isNumeric(type)) {
validator.setValidatedNodeType(call, type);
validator.setValidatedNodeType(left, type);
return cx.convertExpression(left);
}
}


return def.convertCall(cx, call);
}
};

}
if (call.getKind() == SqlKind.EXTRACT && call.getOperandList().get(1).getKind() != SqlKind.LITERAL) {
// Avoid using the standard convertlet for EXTRACT(TIMEUNIT FROM col), since we want to handle it directly
// in ExtractOperationConversion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5172,7 +5172,7 @@ public void testCaseFilteredAggregationWithGroupBy()
testQuery(
"SELECT\n"
+ " cnt,\n"
+ " SUM(CASE WHEN dim1 <> '1' THEN 1 ELSE 0 END) + SUM(cnt)\n"
+ " SUM(CAST((dim1 <> '1') AS INTEGER)) + SUM(cnt)\n"
+ "FROM druid.foo\n"
+ "GROUP BY cnt",
ImmutableList.of(
Expand All @@ -5181,6 +5181,13 @@ public void testCaseFilteredAggregationWithGroupBy()
.setInterval(querySegmentSpec(Filtration.eternity()))
.setGranularity(Granularities.ALL)
.setDimensions(dimensions(new DefaultDimensionSpec("cnt", "d0", ColumnType.LONG)))
// .setVirtualColumns(
// expressionVirtualColumn(
// "v0",
// "case_searched((\"dim1\" != '1'),1,0)",
// ColumnType.LONG
// )
// )
.setAggregatorSpecs(aggregators(
new FilteredAggregatorFactory(
new CountAggregatorFactory("a0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6197,7 +6197,6 @@ public void test_aggregates_aggOWnFn_50()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("aggregates/winFnQry_10")
@Test
public void test_aggregates_winFnQry_10()
Expand Down

0 comments on commit adb37a0

Please sign in to comment.