Java Code Examples for org.apache.calcite.sql.SqlSyntax

The following examples show how to use org.apache.calcite.sql.SqlSyntax. These examples are extracted from open source projects. 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 Project: Bats   Source File: HiveSqlDialect.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void unparseCall(final SqlWriter writer, final SqlCall call, final int leftPrec,
    final int rightPrec) {
  switch (call.getKind()) {
  case POSITION:
    final SqlWriter.Frame frame = writer.startFunCall("INSTR");
    writer.sep(",");
    call.operand(1).unparse(writer, leftPrec, rightPrec);
    writer.sep(",");
    call.operand(0).unparse(writer, leftPrec, rightPrec);
    if (3 == call.operandCount()) {
      throw new RuntimeException("3rd operand Not Supported for Function INSTR in Hive");
    }
    writer.endFunCall(frame);
    break;
  case MOD:
    SqlOperator op = SqlStdOperatorTable.PERCENT_REMAINDER;
    SqlSyntax.BINARY.unparse(writer, op, call, leftPrec, rightPrec);
    break;
  default:
    super.unparseCall(writer, call, leftPrec, rightPrec);
  }
}
 
Example 2
Source Project: Bats   Source File: ListSqlOperatorTable.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupOperatorOverloads(SqlIdentifier opName,
    SqlFunctionCategory category,
    SqlSyntax syntax,
    List<SqlOperator> operatorList) {
  for (SqlOperator operator : this.operatorList) {
    if (operator.getSyntax() != syntax) {
      continue;
    }
    if (!opName.isSimple()
        || !operator.isName(opName.getSimple())) {
      continue;
    }
    if (category != null
        && category != category(operator)
        && !category.isUserDefinedNotSpecificFunction()) {
      continue;
    }
    operatorList.add(operator);
  }
}
 
Example 3
Source Project: Bats   Source File: CalciteCatalogReader.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupOperatorOverloads(final SqlIdentifier opName,
    SqlFunctionCategory category,
    SqlSyntax syntax,
    List<SqlOperator> operatorList) {
  if (syntax != SqlSyntax.FUNCTION) {
    return;
  }

  final Predicate<Function> predicate;
  if (category == null) {
    predicate = function -> true;
  } else if (category.isTableFunction()) {
    predicate = function ->
        function instanceof TableMacro
            || function instanceof TableFunction;
  } else {
    predicate = function ->
        !(function instanceof TableMacro
            || function instanceof TableFunction);
  }
  getFunctionsFrom(opName.names)
      .stream()
      .filter(predicate)
      .map(function -> toOp(opName, function))
      .forEachOrdered(operatorList::add);
}
 
Example 4
Source Project: Bats   Source File: RexCallImpl.java    License: Apache License 2.0 6 votes vote down vote up
protected String computeDigest(boolean withType) {
    final StringBuilder sb = new StringBuilder(op.getName());
    if ((operands.size() == 0) && (op.getSyntax() == SqlSyntax.FUNCTION_ID)) {
        // Don't print params for empty arg list. For example, we want
        // "SYSTEM_USER", not "SYSTEM_USER()".
    } else {
        sb.append("(");
        appendOperands(sb);
        sb.append(")");
    }
    if (withType) {
        sb.append(":");

        // NOTE jvs 16-Jan-2005: for digests, it is very important
        // to use the full type string.
        sb.append(type.getFullTypeString());
    }
    return sb.toString();
}
 
Example 5
Source Project: Bats   Source File: DrillOperatorTable.java    License: Apache License 2.0 6 votes vote down vote up
private void populateFromTypeInference(SqlIdentifier opName, SqlFunctionCategory category,
                                       SqlSyntax syntax, List<SqlOperator> operatorList) {
  final List<SqlOperator> calciteOperatorList = Lists.newArrayList();
  inner.lookupOperatorOverloads(opName, category, syntax, calciteOperatorList);
  if (!calciteOperatorList.isEmpty()) {
    for (SqlOperator calciteOperator : calciteOperatorList) {
      if (calciteToWrapper.containsKey(calciteOperator)) {
        operatorList.add(calciteToWrapper.get(calciteOperator));
      } else {
        operatorList.add(calciteOperator);
      }
    }
  } else {
    // if no function is found, check in Drill UDFs
    if (operatorList.isEmpty() && (syntax == SqlSyntax.FUNCTION || syntax == SqlSyntax.FUNCTION_ID) && opName.isSimple()) {
      List<SqlOperator> drillOps = drillOperatorsWithInferenceMap.get(opName.getSimple().toLowerCase());
      if (drillOps != null && !drillOps.isEmpty()) {
        operatorList.addAll(drillOps);
      }
    }
  }
}
 
Example 6
Source Project: flink   Source File: SqlValidatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable public SqlCall makeNullaryCall(SqlIdentifier id) {
	if (id.names.size() == 1 && !id.isComponentQuoted(0)) {
		final List<SqlOperator> list = new ArrayList<>();
		opTab.lookupOperatorOverloads(id, null, SqlSyntax.FUNCTION, list,
				catalogReader.nameMatcher());
		for (SqlOperator operator : list) {
			if (operator.getSyntax() == SqlSyntax.FUNCTION_ID) {
				// Even though this looks like an identifier, it is a
				// actually a call to a function. Construct a fake
				// call to this function, so we can use the regular
				// operator validation.
				return new SqlBasicCall(operator, SqlNode.EMPTY_ARRAY,
						id.getParserPosition(), true, null);
			}
		}
	}
	return null;
}
 
Example 7
Source Project: flink   Source File: FunctionCatalogOperatorTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupOperatorOverloads(
		SqlIdentifier opName,
		SqlFunctionCategory category,
		SqlSyntax syntax,
		List<SqlOperator> operatorList,
		SqlNameMatcher nameMatcher) {
	if (!opName.isSimple()) {
		return;
	}

	// We lookup only user functions via CatalogOperatorTable. Built in functions should
	// go through BasicOperatorTable
	if (isNotUserFunction(category)) {
		return;
	}

	String name = opName.getSimple();
	Optional<FunctionLookup.Result> candidateFunction = functionCatalog.lookupFunction(name);

	candidateFunction.flatMap(lookupResult ->
		convertToSqlFunction(category, name, lookupResult.getFunctionDefinition())
	).ifPresent(operatorList::add);
}
 
Example 8
Source Project: flink   Source File: FunctionCatalogOperatorTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupOperatorOverloads(
		SqlIdentifier opName,
		SqlFunctionCategory category,
		SqlSyntax syntax,
		List<SqlOperator> operatorList,
		SqlNameMatcher nameMatcher) {
	if (!opName.isSimple()) {
		return;
	}

	// We lookup only user functions via CatalogOperatorTable. Built in functions should
	// go through BasicOperatorTable
	if (isNotUserFunction(category)) {
		return;
	}

	String name = opName.getSimple();
	Optional<FunctionLookup.Result> candidateFunction = functionCatalog.lookupFunction(name);

	candidateFunction.flatMap(lookupResult ->
		convertToSqlFunction(category, name, lookupResult.getFunctionDefinition())
	).ifPresent(operatorList::add);
}
 
Example 9
Source Project: calcite   Source File: RexCall.java    License: Apache License 2.0 6 votes vote down vote up
protected @Nonnull String computeDigest(boolean withType) {
  final StringBuilder sb = new StringBuilder(op.getName());
  if ((operands.size() == 0)
      && (op.getSyntax() == SqlSyntax.FUNCTION_ID)) {
    // Don't print params for empty arg list. For example, we want
    // "SYSTEM_USER", not "SYSTEM_USER()".
  } else {
    sb.append("(");
    appendOperands(sb);
    sb.append(")");
  }
  if (withType) {
    sb.append(":");

    // NOTE jvs 16-Jan-2005:  for digests, it is very important
    // to use the full type string.
    sb.append(type.getFullTypeString());
  }
  return sb.toString();
}
 
Example 10
Source Project: dremio-oss   Source File: OperatorTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) {
  // don't try to evaluate operators that have non name.
  if(opName == null || opName.names == null) {
    return;
  }

  inner.lookupOperatorOverloads(opName, category, syntax, operatorList);

  if (operatorList.isEmpty() && syntax == SqlSyntax.FUNCTION && opName.isSimple()) {
    List<SqlOperator> ops = opMap.get(opName.getSimple().toUpperCase());
    if (ops != null) {
      operatorList.addAll(ops);
    }
  }
}
 
Example 11
Source Project: calcite   Source File: ListSqlOperatorTable.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupOperatorOverloads(SqlIdentifier opName,
    SqlFunctionCategory category,
    SqlSyntax syntax,
    List<SqlOperator> operatorList,
    SqlNameMatcher nameMatcher) {
  for (SqlOperator operator : this.operatorList) {
    if (operator.getSyntax() != syntax) {
      continue;
    }
    if (!opName.isSimple()
        || !nameMatcher.matches(operator.getName(), opName.getSimple())) {
      continue;
    }
    if (category != null
        && category != category(operator)
        && !category.isUserDefinedNotSpecificFunction()) {
      continue;
    }
    operatorList.add(operator);
  }
}
 
Example 12
Source Project: calcite   Source File: RelJson.java    License: Apache License 2.0 6 votes vote down vote up
SqlOperator toOp(Map<String, Object> map) {
  // in case different operator has the same kind, check with both name and kind.
  String name = map.get("name").toString();
  String kind = map.get("kind").toString();
  String syntax = map.get("syntax").toString();
  SqlKind sqlKind = SqlKind.valueOf(kind);
  SqlSyntax  sqlSyntax = SqlSyntax.valueOf(syntax);
  List<SqlOperator> operators = new ArrayList<>();
  SqlStdOperatorTable.instance().lookupOperatorOverloads(
      new SqlIdentifier(name, new SqlParserPos(0, 0)),
      null,
      sqlSyntax,
      operators,
      SqlNameMatchers.liberal());
  for (SqlOperator operator: operators) {
    if (operator.kind == sqlKind) {
      return operator;
    }
  }
  String class_ = (String) map.get("class");
  if (class_ != null) {
    return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
  }
  return null;
}
 
Example 13
Source Project: Bats   Source File: BigQuerySqlDialect.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void unparseCall(final SqlWriter writer, final SqlCall call, final int leftPrec,
    final int rightPrec) {
  switch (call.getKind()) {
  case POSITION:
    final SqlWriter.Frame frame = writer.startFunCall("STRPOS");
    writer.sep(",");
    call.operand(1).unparse(writer, leftPrec, rightPrec);
    writer.sep(",");
    call.operand(0).unparse(writer, leftPrec, rightPrec);
    if (3 == call.operandCount()) {
      throw new RuntimeException("3rd operand Not Supported for Function STRPOS in Big Query");
    }
    writer.endFunCall(frame);
    break;
  case UNION:
    if (!((SqlSetOperator) call.getOperator()).isAll()) {
      SqlSyntax.BINARY.unparse(writer, UNION_DISTINCT, call, leftPrec, rightPrec);
    }
    break;
  case EXCEPT:
    if (!((SqlSetOperator) call.getOperator()).isAll()) {
      SqlSyntax.BINARY.unparse(writer, EXCEPT_DISTINCT, call, leftPrec, rightPrec);
    }
    break;
  case INTERSECT:
    if (!((SqlSetOperator) call.getOperator()).isAll()) {
      SqlSyntax.BINARY.unparse(writer, INTERSECT_DISTINCT, call, leftPrec, rightPrec);
    }
    break;
  default:
    super.unparseCall(writer, call, leftPrec, rightPrec);
  }
}
 
Example 14
Source Project: Bats   Source File: ChainedSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
public void lookupOperatorOverloads(SqlIdentifier opName,
    SqlFunctionCategory category, SqlSyntax syntax,
    List<SqlOperator> operatorList) {
  for (SqlOperatorTable table : tableList) {
    table.lookupOperatorOverloads(opName, category, syntax, operatorList);
  }
}
 
Example 15
Source Project: calcite   Source File: ReflectiveSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
private static SqlSyntax normalize(SqlSyntax syntax) {
  switch (syntax) {
  case BINARY:
  case PREFIX:
  case POSTFIX:
    return syntax;
  default:
    return SqlSyntax.FUNCTION;
  }
}
 
Example 16
Source Project: Bats   Source File: ReflectiveSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
private static SqlSyntax normalize(SqlSyntax syntax) {
  switch (syntax) {
  case BINARY:
  case PREFIX:
  case POSTFIX:
    return syntax;
  default:
    return SqlSyntax.FUNCTION;
  }
}
 
Example 17
Source Project: Bats   Source File: FindPartitionConditions.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isHolisticExpression(RexCall call) {
  /* If we are already processing a holistic expression then all
   * nested expressions should be treated holistically as well
   */
  if (holisticExpression > 0) {
    return true;
  }

  if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL ||
      call.getOperator().getSyntax() == SqlSyntax.FUNCTION) {
    return true;
  }
  return false;
}
 
Example 18
Source Project: Bats   Source File: DrillOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category,
                                    SqlSyntax syntax, List<SqlOperator> operatorList) {
  if (isInferenceEnabled()) {
    populateFromTypeInference(opName, category, syntax, operatorList);
  } else {
    populateFromWithoutTypeInference(opName, category, syntax, operatorList);
  }
}
 
Example 19
Source Project: Bats   Source File: DrillOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
private void populateFromWithoutTypeInference(SqlIdentifier opName, SqlFunctionCategory category,
                                              SqlSyntax syntax, List<SqlOperator> operatorList) {
  inner.lookupOperatorOverloads(opName, category, syntax, operatorList);
  if (operatorList.isEmpty() && (syntax == SqlSyntax.FUNCTION || syntax == SqlSyntax.FUNCTION_ID) && opName.isSimple()) {
    List<SqlOperator> drillOps = drillOperatorsWithoutInferenceMap.get(opName.getSimple().toLowerCase());
    if (drillOps != null) {
      operatorList.addAll(drillOps);
    }
  }
}
 
Example 20
Source Project: Flink-CEPplus   Source File: SqlValidatorImpl.java    License: Apache License 2.0 5 votes vote down vote up
public CalciteException handleUnresolvedFunction(SqlCall call,
	SqlFunction unresolvedFunction, List<RelDataType> argTypes,
	List<String> argNames) {
	// For builtins, we can give a better error message
	final List<SqlOperator> overloads = new ArrayList<>();
	opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null,
		SqlSyntax.FUNCTION, overloads);
	if (overloads.size() == 1) {
		SqlFunction fun = (SqlFunction) overloads.get(0);
		if ((fun.getSqlIdentifier() == null)
			&& (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) {
			final int expectedArgCount =
				fun.getOperandCountRange().getMin();
			throw newValidationError(call,
				RESOURCE.invalidArgCount(call.getOperator().getName(),
					expectedArgCount));
		}
	}

	AssignableOperandTypeChecker typeChecking =
		new AssignableOperandTypeChecker(argTypes, argNames);
	String signature =
		typeChecking.getAllowedSignatures(
			unresolvedFunction,
			unresolvedFunction.getName());
	throw newValidationError(call,
		RESOURCE.validatorUnknownFunction(signature));
}
 
Example 21
Source Project: Flink-CEPplus   Source File: SqlValidatorImpl.java    License: Apache License 2.0 5 votes vote down vote up
public void validateCall(
	SqlCall call,
	SqlValidatorScope scope) {
	final SqlOperator operator = call.getOperator();
	if ((call.operandCount() == 0)
		&& (operator.getSyntax() == SqlSyntax.FUNCTION_ID)
		&& !call.isExpanded()
		&& !conformance.allowNiladicParentheses()) {
		// For example, "LOCALTIME()" is illegal. (It should be
		// "LOCALTIME", which would have been handled as a
		// 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);
}
 
Example 22
Source Project: flink   Source File: SqlValidatorImpl.java    License: Apache License 2.0 5 votes vote down vote up
public CalciteException handleUnresolvedFunction(SqlCall call,
	SqlFunction unresolvedFunction, List<RelDataType> argTypes,
	List<String> argNames) {
	// For builtins, we can give a better error message
	final List<SqlOperator> overloads = new ArrayList<>();
	opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null,
			SqlSyntax.FUNCTION, overloads, catalogReader.nameMatcher());
	if (overloads.size() == 1) {
		SqlFunction fun = (SqlFunction) overloads.get(0);
		if ((fun.getSqlIdentifier() == null)
			&& (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) {
			final int expectedArgCount =
				fun.getOperandCountRange().getMin();
			throw newValidationError(call,
				RESOURCE.invalidArgCount(call.getOperator().getName(),
					expectedArgCount));
		}
	}

	AssignableOperandTypeChecker typeChecking =
		new AssignableOperandTypeChecker(argTypes, argNames);
	String signature =
		typeChecking.getAllowedSignatures(
			unresolvedFunction,
			unresolvedFunction.getName());
	throw newValidationError(call,
		RESOURCE.validatorUnknownFunction(signature));
}
 
Example 23
Source Project: flink   Source File: FlinkSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void lookupOperatorOverloads(
		SqlIdentifier opName,
		SqlFunctionCategory category,
		SqlSyntax syntax,
		List<SqlOperator> operatorList,
		SqlNameMatcher nameMatcher) {
	// set caseSensitive=false to make sure the behavior is same with before.
	super.lookupOperatorOverloads(opName, category, syntax, operatorList, SqlNameMatchers.withCaseSensitive(false));
}
 
Example 24
Source Project: marble   Source File: HiveSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
private SqlSyntax[] getSqlSyntaxInCalcite(Class hiveUDFClass) {
  if (GenericUDFBaseBinary.class.isAssignableFrom(hiveUDFClass)) {
    return new SqlSyntax[]{SqlSyntax.BINARY, SqlSyntax.FUNCTION};
  } else if (GenericUDFBaseUnary.class.isAssignableFrom(hiveUDFClass)) {
    return new SqlSyntax[]{SqlSyntax.PREFIX, SqlSyntax.FUNCTION};
  } else if (hiveUDFClass.equals(UDFRegExp.class)) {
    //rlike
    return new SqlSyntax[]{SqlSyntax.SPECIAL, SqlSyntax.FUNCTION};
  } else {
    //we treat other udf classes as SqlSyntax.FUNCTION
    return new SqlSyntax[]{SqlSyntax.FUNCTION};
  }
}
 
Example 25
Source Project: marble   Source File: HiveSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
private SqlOperator getOperatorInSqlStdOperatorTable(String opName,
    SqlSyntax sqlSyntax, boolean isAgg) {
  List<SqlOperator> ops = operatorMapOfSqlStdOperatorTable.get(
      opName + "_" + sqlSyntax);
  for (SqlOperator op : ops) {
    if (isAgg && op instanceof SqlAggFunction) {
      return op;
    }
    if (!isAgg && !(op instanceof SqlAggFunction)) {
      return op;
    }
  }
  return null;
}
 
Example 26
Source Project: marble   Source File: HiveSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void lookupOperatorOverloads(final SqlIdentifier opName,
    final SqlFunctionCategory category, final SqlSyntax syntax,
    final List<SqlOperator> operatorList) {
  super.lookupOperatorOverloads(opName, category, syntax, operatorList);
  if (operatorList.size() == 0) {
    SqlStdOperatorTable.instance()
        .lookupOperatorOverloads(opName, category, syntax, operatorList);
  }

}
 
Example 27
Source Project: marble   Source File: HiveSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
public Class getHiveUDFClass(String name, SqlSyntax sqlSyntax) {
  String key = name + "_" + sqlSyntax;
  if (methodsUDF.containsKey(key)) {
    return methodsUDF.get(key).get(0);
  }
  return null;
}
 
Example 28
Source Project: marble   Source File: HiveUDFImplementor.java    License: Apache License 2.0 5 votes vote down vote up
private MemberDeclaration generateUdfInstanceDeclaration(String opName,
    SqlSyntax syntax, String fieldName) {
  try {
    if (opName.equals("NOT RLIKE")) {
      //we use a RexImpTable.NotImplementor to wrapper a HiveUDFImplementor ,
      // so `NOT RLIKE` and `RLIKE` would be treated as same here
      opName = "RLIKE";
    }
    if (opName.equals("NOT REGEXP")) {
      opName = "REGEXP";
    }
    Class hiveUDFClazz = HiveSqlOperatorTable.instance()
        .getHiveUDFClass(opName, syntax);
    Expression newUdfExpr;
    if (GenericUDF.class.isAssignableFrom(hiveUDFClazz)) {
      newUdfExpr = Expressions.new_(hiveUDFClazz.getConstructor());
    } else if (UDF.class.isAssignableFrom(hiveUDFClazz)) {
      newUdfExpr = Expressions.new_(GENERIC_UDF_BRIDGE_CONSTRUCTOR
          , new ConstantExpression(String.class, opName)
          , new ConstantExpression(boolean.class, false)
          , new ConstantExpression(String.class, hiveUDFClazz.getName()));
    } else {
      throw new IllegalArgumentException("unknown hive udf class for opName="
          + opName
          + ",and syntax="
          + syntax);
    }
    MemberDeclaration udfMemberDeclaration = Expressions.fieldDecl(
        Modifier.PUBLIC,
        Expressions.parameter(GenericUDF.class, fieldName),
        newUdfExpr);
    return udfMemberDeclaration;
  } catch (NoSuchMethodException e) {
    throw new RuntimeException("fail to new instance for op name " + opName, e);
  }
}
 
Example 29
Source Project: marble   Source File: HiveUDFImplementor.java    License: Apache License 2.0 5 votes vote down vote up
public static GenericUDF newGenericUDF(String opName,
    SqlSyntax syntax) {
  if (opName.equals("NOT RLIKE")) {
    //we use a RexImpTable.NotImplementor to wrapper a HiveUDFImplementor ,
    // so `NOT RLIKE` and `RLIKE` would be treated as same here
    opName = "RLIKE";
  }
  if (opName.equals("NOT REGEXP")) {
    opName = "REGEXP";
  }
  Class hiveUDFClazz = HiveSqlOperatorTable.instance()
      .getHiveUDFClass(opName, syntax);
  if (GenericUDF.class.isAssignableFrom(hiveUDFClazz)) {
    try {
      return (GenericUDF) hiveUDFClazz.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
      throw new RuntimeException(
          "fail to new instance for class " + hiveUDFClazz, e);
    }
  } else if (UDF.class.isAssignableFrom(hiveUDFClazz)) {
    return new GenericUDFBridge(opName, false, hiveUDFClazz.getName());
  } else {
    throw new IllegalArgumentException("unknown hive udf class for opName="
        + opName
        + ",and syntax="
        + syntax);
  }
}
 
Example 30
Source Project: dremio-oss   Source File: FindPartitionConditions.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isHolisticExpression(RexCall call) {
  /* If we are already processing a holistic expression then all
   * nested expressions should be treated holistically as well
   */
  if (holisticExpression > 0) {
    return true;
  }

  if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL ||
      call.getOperator().getSyntax() == SqlSyntax.FUNCTION) {
    return true;
  }
  return false;
}