org.apache.calcite.adapter.enumerable.NullPolicy Java Examples

The following examples show how to use org.apache.calcite.adapter.enumerable.NullPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SamzaSqlScalarFunctionImpl.java    From samza with Apache License 2.0 6 votes vote down vote up
@Override
public CallImplementor getImplementor() {
  return RexImpTable.createImplementor((translator, call, translatedOperands) -> {
    final Expression sqlContext = Expressions.parameter(SamzaSqlExecutionContext.class, "sqlContext");
    final Expression samzaContext = Expressions.parameter(SamzaSqlExecutionContext.class, "context");
    final Expression getUdfInstance = Expressions.call(ScalarUdf.class, sqlContext, getUdfMethod,
        Expressions.constant(udfMethod.getDeclaringClass().getName()), Expressions.constant(udfName), samzaContext);

    List<Expression> convertedOperands = new ArrayList<>();
    // SAMZA: 2230 To allow UDFS to accept Untyped arguments.
    // We explicitly Convert the untyped arguments to type that the UDf expects.
    for (int index = 0; index < translatedOperands.size(); index++) {
      if (!udfMetadata.isDisableArgCheck() && translatedOperands.get(index).type == Object.class
          && udfMethod.getParameters()[index].getType() != Object.class) {
        convertedOperands.add(Expressions.convert_(translatedOperands.get(index), udfMethod.getParameters()[index].getType()));
      } else {
        convertedOperands.add(translatedOperands.get(index));
      }
    }

    final Expression callExpression = Expressions.call(Expressions.convert_(getUdfInstance, udfMethod.getDeclaringClass()), udfMethod,
        convertedOperands);
    return callExpression;
  }, NullPolicy.NONE, false);
}
 
Example #2
Source File: TableFunctionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static CallImplementor createImplementor(final Method method) {
  return RexImpTable.createImplementor(
      new ReflectiveCallNotNullImplementor(method) {
        public Expression implement(RexToLixTranslator translator,
            RexCall call, List<Expression> translatedOperands) {
          Expression expr = super.implement(translator, call,
              translatedOperands);
          final Class<?> returnType = method.getReturnType();
          if (QueryableTable.class.isAssignableFrom(returnType)) {
            Expression queryable = Expressions.call(
                Expressions.convert_(expr, QueryableTable.class),
                BuiltInMethod.QUERYABLE_TABLE_AS_QUERYABLE.method,
                Expressions.call(DataContext.ROOT,
                    BuiltInMethod.DATA_CONTEXT_GET_QUERY_PROVIDER.method),
                Expressions.constant(null, SchemaPlus.class),
                Expressions.constant(call.getOperator().getName(), String.class));
            expr = Expressions.call(queryable,
                BuiltInMethod.QUERYABLE_AS_ENUMERABLE.method);
          } else {
            expr = Expressions.call(expr,
                BuiltInMethod.SCANNABLE_TABLE_SCAN.method, DataContext.ROOT);
          }
          return expr;
        }
      }, NullPolicy.NONE, false);
}
 
Example #3
Source File: HiveSqlOperatorTable.java    From marble with Apache License 2.0 5 votes vote down vote up
private void defineImplementors() {
  //define implementors for hive operators
  final List<SqlOperator> operatorList = getOperatorList();
  RexImpTable.INSTANCE.defineImplementors((map, aggMap, winAggMap) -> {
    for (SqlOperator sqlOperator : operatorList) {
      if (sqlOperator instanceof HiveSqlAggFunction) {
        HiveSqlAggFunction aggFunction = (HiveSqlAggFunction) sqlOperator;
        aggMap.put(aggFunction, () -> new HiveUDAFImplementor(aggFunction));
      } else {
        /**since SqlOperator is identified by name and kind ,see
         *  {@link SqlOperator#equals(Object)} and
         *  {@link SqlOperator#hashCode()},
         *  we can override implementors of operators that declared in
         *  SqlStdOperatorTable
         *  */
        CallImplementor callImplementor;
        if (sqlOperator.getName().equals("NOT RLIKE") || sqlOperator.getName()
            .equals("NOT REGEXP")) {
          callImplementor =
              RexImpTable.createImplementor(
                  RexImpTable.NotImplementor.of(
                      new HiveUDFImplementor()), NullPolicy.STRICT, false);
        } else {
          callImplementor =
              RexImpTable.createImplementor(
                  new HiveUDFImplementor(), NullPolicy.NONE, false);
        }
        map.put(sqlOperator, callImplementor);

      }

    }
    // directly override some implementors of SqlOperator that declared in
    // SqlStdOperatorTable
    map.put(SqlStdOperatorTable.ITEM,
        new RexImpTable.ItemImplementor(true));
  });


}
 
Example #4
Source File: ScalarFunctionImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static NullPolicy getNullPolicy(Method m) {
  if (m.getAnnotation(Strict.class) != null) {
    return NullPolicy.STRICT;
  } else if (m.getAnnotation(SemiStrict.class) != null) {
    return NullPolicy.SEMI_STRICT;
  } else if (m.getDeclaringClass().getAnnotation(Strict.class) != null) {
    return NullPolicy.STRICT;
  } else if (m.getDeclaringClass().getAnnotation(SemiStrict.class) != null) {
    return NullPolicy.SEMI_STRICT;
  } else {
    return NullPolicy.NONE;
  }
}
 
Example #5
Source File: CollectionsFunctions.java    From mat-calcite-plugin with Apache License 2.0 4 votes vote down vote up
BaseImplementableFunction(Method method) {
    super(method);
    implementor = RexImpTable.createImplementor(new ReflectiveCallNotNullImplementor(method), NullPolicy.NONE, false);
}
 
Example #6
Source File: ScalarFunctionImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static CallImplementor createImplementor(final Method method) {
  final NullPolicy nullPolicy = getNullPolicy(method);
  return RexImpTable.createImplementor(
      new ReflectiveCallNotNullImplementor(method), nullPolicy, false);
}