Search in sources :

Example 6 with SqlFunction

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project drill by axbaretto.

the class DrillOperatorTable method populateWrappedCalciteOperators.

private void populateWrappedCalciteOperators() {
    for (SqlOperator calciteOperator : inner.getOperatorList()) {
        final SqlOperator wrapper;
        if (calciteOperator instanceof SqlAggFunction) {
            wrapper = new DrillCalciteSqlAggFunctionWrapper((SqlAggFunction) calciteOperator, getFunctionListWithInference(calciteOperator.getName()));
        } else if (calciteOperator instanceof SqlFunction) {
            wrapper = new DrillCalciteSqlFunctionWrapper((SqlFunction) calciteOperator, getFunctionListWithInference(calciteOperator.getName()));
        } else {
            final String drillOpName = FunctionCallFactory.replaceOpWithFuncName(calciteOperator.getName());
            final List<DrillFuncHolder> drillFuncHolders = getFunctionListWithInference(drillOpName);
            if (drillFuncHolders.isEmpty() || calciteOperator == SqlStdOperatorTable.UNARY_MINUS || calciteOperator == SqlStdOperatorTable.UNARY_PLUS) {
                continue;
            }
            wrapper = new DrillCalciteSqlOperatorWrapper(calciteOperator, drillOpName, drillFuncHolders);
        }
        calciteToWrapper.put(calciteOperator, wrapper);
    }
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) List(java.util.List) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 7 with SqlFunction

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project flink by apache.

the class SqlValidatorImpl method validateCall.

public void validateCall(SqlCall call, SqlValidatorScope scope) {
    final SqlOperator operator = call.getOperator();
    if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !this.config.sqlConformance().allowNiladicParentheses()) {
        // SqlIdentifier.)
        throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null);
    }
    SqlValidatorScope operandScope = scope.getOperandScope(call);
    if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) {
        throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
    }
    // Delegate validation to the operator.
    operator.validateCall(call, this, scope, operandScope);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 8 with SqlFunction

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project flink by apache.

the class LegacyScalarFunctionConvertRule method convert.

@Override
public Optional<RexNode> convert(CallExpression call, ConvertContext context) {
    FunctionDefinition def = call.getFunctionDefinition();
    if (def instanceof ScalarFunctionDefinition) {
        ScalarFunction scalaFunc = ((ScalarFunctionDefinition) def).getScalarFunction();
        FunctionIdentifier identifier = call.getFunctionIdentifier().orElse(FunctionIdentifier.of(generateInlineFunctionName(scalaFunc)));
        SqlFunction sqlFunction = UserDefinedFunctionUtils.createScalarSqlFunction(identifier, scalaFunc.toString(), scalaFunc, context.getTypeFactory());
        return Optional.of(context.getRelBuilder().call(sqlFunction, toRexNodes(context, call.getChildren())));
    }
    return Optional.empty();
}
Also used : FunctionIdentifier(org.apache.flink.table.functions.FunctionIdentifier) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) ScalarFunction(org.apache.flink.table.functions.ScalarFunction) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 9 with SqlFunction

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project druid by druid-io.

the class ExpressionsTest method testRoundWithNanShouldRoundTo0.

@Test
public void testRoundWithNanShouldRoundTo0() {
    final SqlFunction roundFunction = new RoundOperatorConversion().calciteOperator();
    testHelper.testExpression(roundFunction, testHelper.makeInputRef("nan"), DruidExpression.ofExpression(ColumnType.DOUBLE, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.DOUBLE, "nan"))), 0D);
    testHelper.testExpression(roundFunction, testHelper.makeInputRef("fnan"), DruidExpression.ofExpression(ColumnType.FLOAT, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "fnan"))), 0D);
}
Also used : RoundOperatorConversion(org.apache.druid.sql.calcite.expression.builtin.RoundOperatorConversion) SqlFunction(org.apache.calcite.sql.SqlFunction) Test(org.junit.Test)

Example 10 with SqlFunction

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction in project druid by druid-io.

the class ExpressionsTest method testRoundWithInfinityShouldRoundTo0.

@Test
public void testRoundWithInfinityShouldRoundTo0() {
    final SqlFunction roundFunction = new RoundOperatorConversion().calciteOperator();
    // CHECKSTYLE.OFF: Regexp
    testHelper.testExpression(roundFunction, testHelper.makeInputRef("inf"), DruidExpression.ofExpression(ColumnType.DOUBLE, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.DOUBLE, "inf"))), Double.MAX_VALUE);
    testHelper.testExpression(roundFunction, testHelper.makeInputRef("-inf"), DruidExpression.ofExpression(ColumnType.DOUBLE, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.DOUBLE, "-inf"))), -1 * Double.MAX_VALUE);
    testHelper.testExpression(roundFunction, testHelper.makeInputRef("finf"), DruidExpression.ofExpression(ColumnType.FLOAT, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "finf"))), Double.MAX_VALUE);
    testHelper.testExpression(roundFunction, testHelper.makeInputRef("-finf"), DruidExpression.ofExpression(ColumnType.FLOAT, DruidExpression.functionCall("round"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "-finf"))), -1 * Double.MAX_VALUE);
// CHECKSTYLE.ON: Regexp
}
Also used : RoundOperatorConversion(org.apache.druid.sql.calcite.expression.builtin.RoundOperatorConversion) SqlFunction(org.apache.calcite.sql.SqlFunction) Test(org.junit.Test)

Aggregations

SqlFunction (org.apache.calcite.sql.SqlFunction)30 SqlOperator (org.apache.calcite.sql.SqlOperator)13 ArrayList (java.util.ArrayList)7 RexNode (org.apache.calcite.rex.RexNode)6 RoundOperatorConversion (org.apache.druid.sql.calcite.expression.builtin.RoundOperatorConversion)6 Test (org.junit.Test)6 SqlCall (org.apache.calcite.sql.SqlCall)5 ImmutableList (com.google.common.collect.ImmutableList)4 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)4 BigDecimal (java.math.BigDecimal)3 RexCall (org.apache.calcite.rex.RexCall)3 RexLiteral (org.apache.calcite.rex.RexLiteral)3 SqlNode (org.apache.calcite.sql.SqlNode)3 List (java.util.List)2 TimeUnitRange (org.apache.calcite.avatica.util.TimeUnitRange)2 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 RexBuilder (org.apache.calcite.rex.RexBuilder)2 SqlAggFunction (org.apache.calcite.sql.SqlAggFunction)2 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)2