Java Code Examples for org.apache.calcite.sql.type.OperandTypes#family()

The following examples show how to use org.apache.calcite.sql.type.OperandTypes#family() . 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: SqlItemOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
private SqlSingleOperandTypeChecker getChecker(RelDataType operandType) {
  switch (operandType.getSqlTypeName()) {
  case ARRAY:
    return OperandTypes.family(SqlTypeFamily.INTEGER);
  case MAP:
    return OperandTypes.family(
        operandType.getKeyType().getSqlTypeName().getFamily());
  case ANY:
  case DYNAMIC_STAR:
    return OperandTypes.or(
        OperandTypes.family(SqlTypeFamily.INTEGER),
        OperandTypes.family(SqlTypeFamily.CHARACTER));
  default:
    throw new AssertionError(operandType.getSqlTypeName());
  }
}
 
Example 2
Source File: SqlItemOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
private SqlSingleOperandTypeChecker getChecker(SqlCallBinding callBinding) {
  final RelDataType operandType = callBinding.getOperandType(0);
  switch (operandType.getSqlTypeName()) {
  case ARRAY:
    return OperandTypes.family(SqlTypeFamily.INTEGER);
  case MAP:
    return OperandTypes.family(
        operandType.getKeyType().getSqlTypeName().getFamily());
  case ROW:
    return OperandTypes.CHARACTER;
  case ANY:
  case DYNAMIC_STAR:
    return OperandTypes.or(
        OperandTypes.family(SqlTypeFamily.INTEGER),
        OperandTypes.family(SqlTypeFamily.CHARACTER));
  default:
    throw callBinding.newValidationSignatureError();
  }
}
 
Example 3
Source File: StreamRecordTimestampSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public StreamRecordTimestampSqlFunction() {
	super(
		"STREAMRECORD_TIMESTAMP",
		SqlKind.OTHER_FUNCTION,
		ReturnTypes.explicit(SqlTypeName.BIGINT),
		InferTypes.RETURN_TYPE,
		OperandTypes.family(SqlTypeFamily.NUMERIC),
		SqlFunctionCategory.SYSTEM);
}
 
Example 4
Source File: SqlTimestampAddFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlTimestampAddFunction. */
SqlTimestampAddFunction() {
  super("TIMESTAMPADD", SqlKind.TIMESTAMP_ADD, RETURN_TYPE_INFERENCE, null,
      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER,
          SqlTypeFamily.DATETIME),
      SqlFunctionCategory.TIMEDATE);
}
 
Example 5
Source File: SqlTimestampDiffFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
SqlTimestampDiffFunction() {
  super("TIMESTAMPDIFF", SqlKind.TIMESTAMP_DIFF,
      RETURN_TYPE_INFERENCE, null,
      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATETIME,
          SqlTypeFamily.DATETIME),
      SqlFunctionCategory.TIMEDATE);
}
 
Example 6
Source File: PigRelSqlUdfs.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Pig DataBag from a list of relational operands.
 *
 * @param operands Relational operands
 * @return Pig DataBag SqlUDF
 */
static SqlUserDefinedFunction createPigBagUDF(ImmutableList<RexNode> operands) {
  return new PigUserDefinedFunction(
      "PIG_BAG",
      infer(PigRelSqlUdfs.PIG_BAG_FUNC),
      OperandTypes.family(getTypeFamilies(operands)),
      getRelDataTypes(operands),
      PigRelSqlUdfs.PIG_BAG_FUNC);
}
 
Example 7
Source File: SqlJsonValueFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlJsonValueFunction(String name) {
  super(name, SqlKind.OTHER_FUNCTION,
      ReturnTypes.cascade(
          opBinding -> explicitTypeSpec(opBinding).orElse(getDefaultType(opBinding)),
          SqlTypeTransforms.FORCE_NULLABLE),
      null,
      OperandTypes.family(
          ImmutableList.of(SqlTypeFamily.ANY, SqlTypeFamily.CHARACTER),
          ordinal -> ordinal > 1),
      SqlFunctionCategory.SYSTEM);
}
 
Example 8
Source File: StreamRecordTimestampSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public StreamRecordTimestampSqlFunction() {
	super(
		"STREAMRECORD_TIMESTAMP",
		SqlKind.OTHER_FUNCTION,
		ReturnTypes.explicit(SqlTypeName.BIGINT),
		InferTypes.RETURN_TYPE,
		OperandTypes.family(SqlTypeFamily.NUMERIC),
		SqlFunctionCategory.SYSTEM);
}
 
Example 9
Source File: ProctimeMaterializeSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public ProctimeMaterializeSqlFunction() {
	super(
		"PROCTIME_MATERIALIZE",
		SqlKind.OTHER_FUNCTION,
		ReturnTypes.cascade(
				ReturnTypes.explicit(SqlTypeName.TIMESTAMP, 3),
				SqlTypeTransforms.TO_NULLABLE),
		InferTypes.RETURN_TYPE,
		OperandTypes.family(SqlTypeFamily.TIMESTAMP),
		SqlFunctionCategory.SYSTEM);
}
 
Example 10
Source File: SqlJsonArrayAggAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlJsonArrayAggAggFunction(SqlKind kind,
    SqlJsonConstructorNullClause nullClause) {
  super(kind + "_" + nullClause.name(), null, kind, ReturnTypes.VARCHAR_2000,
      InferTypes.ANY_NULLABLE, OperandTypes.family(SqlTypeFamily.ANY),
      SqlFunctionCategory.SYSTEM, false, false, Optionality.OPTIONAL);
  this.nullClause = Objects.requireNonNull(nullClause);
}
 
Example 11
Source File: DremioCatalogReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Rest of class is utility functions taken directly from CalciteCatalogReader. This is because that class consider these utilities to be private concerns.
 */
private SqlOperator toOp(SqlIdentifier name, final Function function) {
  List<RelDataType> argTypes = new ArrayList<>();
  List<SqlTypeFamily> typeFamilies = new ArrayList<>();
  for (FunctionParameter o : function.getParameters()) {
    final RelDataType type = o.getType(typeFactory);
    argTypes.add(type);
    typeFamilies.add(
        Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
  }
  final Predicate<Integer> optional =
      new Predicate<Integer>() {
        @Override
        public boolean apply(Integer input) {
          return function.getParameters().get(input).isOptional();
        }
      };
  final FamilyOperandTypeChecker typeChecker =
      OperandTypes.family(typeFamilies, optional);
  final List<RelDataType> paramTypes = toSql(argTypes);
  if (function instanceof ScalarFunction) {
    return new SqlUserDefinedFunction(name, infer((ScalarFunction) function),
        InferTypes.explicit(argTypes), typeChecker, paramTypes, function);
  } else if (function instanceof AggregateFunction) {
    return new SqlUserDefinedAggFunction(name,
        infer((AggregateFunction) function), InferTypes.explicit(argTypes),
        typeChecker, (AggregateFunction) function, false, false, typeFactory);
  } else if (function instanceof TableMacro) {
    return new SqlUserDefinedTableMacro(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableMacro) function);
  } else if (function instanceof TableFunction) {
    return new SqlUserDefinedTableFunction(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableFunction) function);
  } else {
    throw new AssertionError("unknown function type " + function);
  }
}
 
Example 12
Source File: OLAPAggregateRel.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
SqlAggFunction createCustomAggFunction(String funcName, RelDataType returnType, Class<?> customAggFuncClz) {
    RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
    SqlIdentifier sqlIdentifier = new SqlIdentifier(funcName, new SqlParserPos(1, 1));
    AggregateFunction aggFunction = AggregateFunctionImpl.create(customAggFuncClz);
    List<RelDataType> argTypes = new ArrayList<RelDataType>();
    List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>();
    for (FunctionParameter o : aggFunction.getParameters()) {
        final RelDataType type = o.getType(typeFactory);
        argTypes.add(type);
        typeFamilies.add(Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
    }
    return new SqlUserDefinedAggFunction(sqlIdentifier, ReturnTypes.explicit(returnType),
            InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), aggFunction, false, false,
            typeFactory);
}
 
Example 13
Source File: ProctimeMaterializeSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public ProctimeMaterializeSqlFunction() {
	super(
		"PROCTIME_MATERIALIZE",
		SqlKind.OTHER_FUNCTION,
		ReturnTypes.cascade(
				ReturnTypes.explicit(SqlTypeName.TIMESTAMP),
				SqlTypeTransforms.TO_NULLABLE),
		InferTypes.RETURN_TYPE,
		OperandTypes.family(SqlTypeFamily.TIMESTAMP),
		SqlFunctionCategory.SYSTEM);
}
 
Example 14
Source File: CalciteCatalogReader.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Converts a function to a {@link org.apache.calcite.sql.SqlOperator}.
 *
 * <p>The {@code typeFactory} argument is technical debt; see [CALCITE-2082]
 * Remove RelDataTypeFactory argument from SqlUserDefinedAggFunction
 * constructor. */
private static SqlOperator toOp(RelDataTypeFactory typeFactory,
    SqlIdentifier name, final Function function) {
  List<RelDataType> argTypes = new ArrayList<>();
  List<SqlTypeFamily> typeFamilies = new ArrayList<>();
  for (FunctionParameter o : function.getParameters()) {
    final RelDataType type = o.getType(typeFactory);
    argTypes.add(type);
    typeFamilies.add(
        Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
  }
  final FamilyOperandTypeChecker typeChecker =
      OperandTypes.family(typeFamilies, i ->
          function.getParameters().get(i).isOptional());
  final List<RelDataType> paramTypes = toSql(typeFactory, argTypes);
  if (function instanceof ScalarFunction) {
    return new SqlUserDefinedFunction(name, infer((ScalarFunction) function),
        InferTypes.explicit(argTypes), typeChecker, paramTypes, function);
  } else if (function instanceof AggregateFunction) {
    return new SqlUserDefinedAggFunction(name,
        infer((AggregateFunction) function), InferTypes.explicit(argTypes),
        typeChecker, (AggregateFunction) function, false, false,
        Optionality.FORBIDDEN, typeFactory);
  } else if (function instanceof TableMacro) {
    return new SqlUserDefinedTableMacro(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableMacro) function);
  } else if (function instanceof TableFunction) {
    return new SqlUserDefinedTableFunction(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableFunction) function);
  } else {
    throw new AssertionError("unknown function type " + function);
  }
}
 
Example 15
Source File: SqlDotOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
private SqlSingleOperandTypeChecker getChecker(RelDataType operandType) {
  switch (operandType.getSqlTypeName()) {
  case ROW:
    return OperandTypes.family(SqlTypeFamily.STRING);
  default:
    throw new AssertionError(operandType.getSqlTypeName());
  }
}
 
Example 16
Source File: SqlJsonObjectAggAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlJsonObjectAggAggFunction. */
public SqlJsonObjectAggAggFunction(SqlKind kind,
    SqlJsonConstructorNullClause nullClause) {
  super(kind + "_" + nullClause.name(), null, kind, ReturnTypes.VARCHAR_2000, null,
      OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.ANY),
      SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN);
  this.nullClause = Objects.requireNonNull(nullClause);
}
 
Example 17
Source File: SqlTimestampDiffFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
SqlTimestampDiffFunction() {
  super("TIMESTAMPDIFF", SqlKind.TIMESTAMP_DIFF,
      RETURN_TYPE_INFERENCE, null,
      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATETIME,
          SqlTypeFamily.DATETIME),
      SqlFunctionCategory.TIMEDATE);
}
 
Example 18
Source File: SqlTimestampAddFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlTimestampAddFunction. */
SqlTimestampAddFunction() {
  super("TIMESTAMPADD", SqlKind.TIMESTAMP_ADD, RETURN_TYPE_INFERENCE, null,
      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER,
          SqlTypeFamily.DATETIME),
      SqlFunctionCategory.TIMEDATE);
}
 
Example 19
Source File: MockSqlOperatorTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
public MyAvgAggFunction() {
  super("MYAGG", null, SqlKind.AVG, ReturnTypes.AVG_AGG_FUNCTION,
      null, OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
      SqlFunctionCategory.NUMERIC, false, false, Optionality.FORBIDDEN);
}
 
Example 20
Source File: MockSqlOperatorTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SplitFunction() {
  super("SPLIT", new SqlIdentifier("SPLIT", SqlParserPos.ZERO), SqlKind.OTHER_FUNCTION, null,
      null, OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING), null,
      SqlFunctionCategory.USER_DEFINED_FUNCTION);
}