org.apache.calcite.sql.SqlSyntax Java Examples

The following examples show how to use org.apache.calcite.sql.SqlSyntax. 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: OperatorTable.java    From dremio-oss with 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 #2
Source File: DrillOperatorTable.java    From Bats with 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 #3
Source File: SqlValidatorImpl.java    From flink with 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 #4
Source File: ListSqlOperatorTable.java    From calcite with 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 #5
Source File: RexCallImpl.java    From Bats with 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 #6
Source File: CalciteCatalogReader.java    From Bats with 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 #7
Source File: FunctionCatalogOperatorTable.java    From flink with 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 File: FunctionCatalogOperatorTable.java    From flink with 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 File: ListSqlOperatorTable.java    From Bats with 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 #10
Source File: RelJson.java    From calcite with 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 #11
Source File: HiveSqlDialect.java    From Bats with 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 #12
Source File: RexCall.java    From calcite with 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 #13
Source File: FindPartitionConditions.java    From dremio-oss with 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 #14
Source File: SqlValidatorUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Lookup sql function by sql identifier and function category.
 *
 * @param opTab    operator table to look up
 * @param funName  function name
 * @param funcType function category
 * @return A sql function if and only if there is one operator matches, else null
 */
public static SqlOperator lookupSqlFunctionByID(SqlOperatorTable opTab,
    SqlIdentifier funName,
    SqlFunctionCategory funcType) {
  if (funName.isSimple()) {
    final List<SqlOperator> list = new ArrayList<>();
    opTab.lookupOperatorOverloads(funName, funcType, SqlSyntax.FUNCTION, list,
        SqlNameMatchers.withCaseSensitive(funName.isComponentQuoted(0)));
    if (list.size() == 1) {
      return list.get(0);
    }
  }
  return null;
}
 
Example #15
Source File: ChainedSqlOperatorTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void lookupOperatorOverloads(SqlIdentifier opName,
    SqlFunctionCategory category, SqlSyntax syntax,
    List<SqlOperator> operatorList, SqlNameMatcher nameMatcher) {
  for (SqlOperatorTable table : tableList) {
    table.lookupOperatorOverloads(opName, category, syntax, operatorList,
        nameMatcher);
  }
}
 
Example #16
Source File: SqlValidatorImpl.java    From Flink-CEPplus with 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 #17
Source File: SqlValidatorImpl.java    From Flink-CEPplus with 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 #18
Source File: SqlOperatorImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public SqlOperatorImpl(String name, int argCountMin, int argCountMax, boolean isDeterministic,
    boolean isDynamic, SqlReturnTypeInference sqlReturnTypeInference, SqlSyntax syntax) {
  super(name,
    null,
    SqlKind.OTHER_FUNCTION,
    sqlReturnTypeInference,
    null,
    Checker.getChecker(argCountMin, argCountMax),
    null,
    SqlFunctionCategory.USER_DEFINED_FUNCTION);
  this.isDeterministic = isDeterministic;
  this.isDynamic = isDynamic;
  this.syntax = syntax;
}
 
Example #19
Source File: SqlValidatorImpl.java    From flink with 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 #20
Source File: SchemaField.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public SchemaPath visitCall(RexCall call) {
  if(call.getOperator().getSyntax() != SqlSyntax.SPECIAL || call.getOperator() != SqlStdOperatorTable.ITEM){
    return null;
  }
  LogicalExpression logExpr = call.getOperands().get(0).accept(this);

  if (!(logExpr instanceof SchemaPath)) {
    return (SchemaPath) logExpr;
  }

  SchemaPath left = (SchemaPath) logExpr;
  final RexLiteral literal = (RexLiteral) call.getOperands().get(1);
  switch(literal.getTypeName()){
  case DECIMAL:
  case INTEGER:
    switch(indexMode){
    case ALLOW:
      return left.getChild(((BigDecimal)literal.getValue()).intValue());
    case SKIP:
      return left;
    case DISALLOW:
    default:
      return null;
    }

  case CHAR:
  case VARCHAR:
    return left.getChild(literal.getValue2().toString());
  default:
    // fall through
  }

  return null;
}
 
Example #21
Source File: SqlOperatorImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public SqlOperatorImpl(String name, int argCountMin, int argCountMax, boolean isDeterministic,
    SqlReturnTypeInference sqlReturnTypeInference) {
  this(name,
      argCountMin,
      argCountMax,
      isDeterministic,
      false,
      sqlReturnTypeInference,
      SqlSyntax.FUNCTION);
}
 
Example #22
Source File: HiveSqlOperatorTable.java    From marble with 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 #23
Source File: HiveUDFImplementor.java    From marble with 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 #24
Source File: SchemaField.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public RexNode visitCall(RexCall call) {
  final boolean isItem = call.getOperator().getSyntax() == SqlSyntax.SPECIAL && call.getOperator() == SqlStdOperatorTable.ITEM;
  if(isItem){
    return visitCandidate(call);
  }
  return super.visitCall(call);
}
 
Example #25
Source File: PredicateAnalyzer.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Expression visitCall(RexCall call) {

  SqlSyntax syntax = call.getOperator().getSyntax();
  if (!supportedRexCall(call)) {
    throw new PredicateAnalyzerException(format("Unsupported call: [%s]", call));
  }

  switch (syntax) {
    case BINARY:
      return binary(call);
    case POSTFIX:
      return postfix(call);
    case SPECIAL:
      switch (call.getKind()) {
        case CAST:
          return cast(call);
        case LIKE:
          return binary(call);
        default:
          throw new PredicateAnalyzerException(format("Unsupported call: [%s]", call));
      }
    case FUNCTION:
      if (call.getOperator().getName().equalsIgnoreCase("CONTAINS")) {
        List<Expression> operands = Lists.newArrayList();
        for (RexNode node : call.getOperands()) {
          final Expression nodeExpr = node.accept(this);
          operands.add(nodeExpr);
        }
        String query = convertQueryString(operands.subList(0, operands.size() - 1), operands.get(operands.size() - 1));
        return QueryExpression.create(new NamedFieldExpression(null)).queryString(query);
      }
    default:
      throw new PredicateAnalyzerException(format("Unsupported syntax [%s] for call: [%s]", syntax, call));
  }
}
 
Example #26
Source File: HiveUDFImplementor.java    From marble with 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 #27
Source File: HiveSqlOperatorTable.java    From marble with 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 File: FlinkSqlOperatorTable.java    From flink with 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 #29
Source File: HiveSqlOperatorTable.java    From marble with 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 #30
Source File: HiveSqlOperatorTable.java    From marble with 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;
}