Search in sources :

Example 16 with SqlOperator

use of org.apache.calcite.sql.SqlOperator in project hive by apache.

the class SqlFunctionConverter method getCalciteFn.

public static SqlOperator getCalciteFn(String hiveUdfName, ImmutableList<RelDataType> calciteArgTypes, RelDataType calciteRetType, boolean deterministic, boolean dynamicFunction) throws CalciteSemanticException {
    if (hiveUdfName != null && hiveUdfName.trim().equals("<=>")) {
        // this.So, bail out for now.
        throw new CalciteSemanticException("<=> is not yet supported for cbo.", UnsupportedFeature.Less_than_equal_greater_than);
    }
    SqlOperator calciteOp;
    CalciteUDFInfo uInf = getUDFInfo(hiveUdfName, calciteArgTypes, calciteRetType);
    switch(hiveUdfName) {
        // TODO: Perhaps we should do this for all functions, not just +,-
        case "-":
            calciteOp = new SqlMonotonicBinaryOperator("-", SqlKind.MINUS, 40, true, uInf.returnTypeInference, uInf.operandTypeInference, OperandTypes.MINUS_OPERATOR);
            break;
        case "+":
            calciteOp = new SqlMonotonicBinaryOperator("+", SqlKind.PLUS, 40, true, uInf.returnTypeInference, uInf.operandTypeInference, OperandTypes.PLUS_OPERATOR);
            break;
        default:
            calciteOp = hiveToCalcite.get(hiveUdfName);
            if (null == calciteOp) {
                calciteOp = new CalciteSqlFn(uInf.udfName, SqlKind.OTHER_FUNCTION, uInf.returnTypeInference, uInf.operandTypeInference, uInf.operandTypeChecker, SqlFunctionCategory.USER_DEFINED_FUNCTION, deterministic, dynamicFunction);
            }
            break;
    }
    return calciteOp;
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlMonotonicBinaryOperator(org.apache.calcite.sql.fun.SqlMonotonicBinaryOperator) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)

Example 17 with SqlOperator

use of org.apache.calcite.sql.SqlOperator in project hive by apache.

the class DruidSqlOperatorConverter method getDefaultMap.

public static final Map<SqlOperator, org.apache.calcite.adapter.druid.DruidSqlOperatorConverter> getDefaultMap() {
    if (druidOperatorMap == null) {
        druidOperatorMap = new HashMap<SqlOperator, org.apache.calcite.adapter.druid.DruidSqlOperatorConverter>();
        DruidQuery.DEFAULT_OPERATORS_LIST.stream().forEach(op -> druidOperatorMap.put(op.calciteOperator(), op));
        // Override Hive specific operators
        druidOperatorMap.putAll(Maps.asMap(HiveFloorDate.ALL_FUNCTIONS, (Function<SqlFunction, org.apache.calcite.adapter.druid.DruidSqlOperatorConverter>) input -> new FloorOperatorConversion()));
        druidOperatorMap.putAll(Maps.asMap(HiveExtractDate.ALL_FUNCTIONS, (Function<SqlFunction, org.apache.calcite.adapter.druid.DruidSqlOperatorConverter>) input -> new ExtractOperatorConversion()));
        druidOperatorMap.put(HiveConcat.INSTANCE, new DirectOperatorConversion(HiveConcat.INSTANCE, "concat"));
        druidOperatorMap.put(SqlStdOperatorTable.SUBSTRING, new DruidSqlOperatorConverter.DruidSubstringOperatorConversion());
    }
    return druidOperatorMap;
}
Also used : ExtractOperatorConversion(org.apache.calcite.adapter.druid.ExtractOperatorConversion) SqlOperator(org.apache.calcite.sql.SqlOperator) DirectOperatorConversion(org.apache.calcite.adapter.druid.DirectOperatorConversion) Function(com.google.common.base.Function) SqlFunction(org.apache.calcite.sql.SqlFunction) FloorOperatorConversion(org.apache.calcite.adapter.druid.FloorOperatorConversion)

Aggregations

SqlOperator (org.apache.calcite.sql.SqlOperator)17 ArrayList (java.util.ArrayList)7 RexNode (org.apache.calcite.rex.RexNode)7 RelDataType (org.apache.calcite.rel.type.RelDataType)5 RelNode (org.apache.calcite.rel.RelNode)3 SqlFunction (org.apache.calcite.sql.SqlFunction)3 SqlKind (org.apache.calcite.sql.SqlKind)3 TreeMap (java.util.TreeMap)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 RexBuilder (org.apache.calcite.rex.RexBuilder)2 RexCall (org.apache.calcite.rex.RexCall)2 RexInputRef (org.apache.calcite.rex.RexInputRef)2 RexLiteral (org.apache.calcite.rex.RexLiteral)2 DrillSqlOperator (org.apache.drill.exec.planner.sql.DrillSqlOperator)2 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)2 HiveRelNode (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode)2 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1