Java Code Examples for org.apache.calcite.sql.SqlKind#name()

The following examples show how to use org.apache.calcite.sql.SqlKind#name() . 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: SqlMinMaxAggFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Creates a SqlMinMaxAggFunction. */
public SqlMinMaxAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.COMPARABLE_ORDERED,
      SqlFunctionCategory.SYSTEM,
      false,
      false,
      Optionality.FORBIDDEN);
  this.argTypes = ImmutableList.of();
  this.minMaxKind = MINMAX_COMPARABLE;
  Preconditions.checkArgument(kind == SqlKind.MIN
      || kind == SqlKind.MAX);
}
 
Example 2
Source File: SqlBitOpAggFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates a SqlBitOpAggFunction. */
public SqlBitOpAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.INTEGER,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.BIT_AND
      || kind == SqlKind.BIT_OR
      || kind == SqlKind.BIT_XOR);
}
 
Example 3
Source File: SqlFloorFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlFloorFunction(SqlKind kind) {
  super(kind.name(), kind, ReturnTypes.ARG0_OR_EXACT_NO_SCALE, null,
      OperandTypes.or(OperandTypes.NUMERIC_OR_INTERVAL,
          OperandTypes.sequence(
              "'" + kind + "(<DATE> TO <TIME_UNIT>)'\n"
              + "'" + kind + "(<TIME> TO <TIME_UNIT>)'\n"
              + "'" + kind + "(<TIMESTAMP> TO <TIME_UNIT>)'",
              OperandTypes.DATETIME,
              OperandTypes.ANY)),
      SqlFunctionCategory.NUMERIC);
  Preconditions.checkArgument(kind == SqlKind.FLOOR || kind == SqlKind.CEIL);
}
 
Example 4
Source File: SqlFirstLastValueAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlFirstLastValueAggFunction(SqlKind kind) {
  super(
      kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.NUMERIC,
      false,
      true,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE
      || kind == SqlKind.LAST_VALUE);
}
 
Example 5
Source File: SqlCovarAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SqlCovarAggFunction.
 */
public SqlCovarAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      kind == SqlKind.REGR_COUNT ? ReturnTypes.BIGINT : ReturnTypes.COVAR_REGR_FUNCTION,
      null,
      OperandTypes.NUMERIC_NUMERIC,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(kind),
      "unsupported sql kind: " + kind);
}
 
Example 6
Source File: SqlLeadLagAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlLeadLagAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      RETURN_TYPE,
      null,
      OPERAND_TYPES,
      SqlFunctionCategory.NUMERIC,
      false,
      true,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.LEAD
      || kind == SqlKind.LAG);
}
 
Example 7
Source File: SqlFloorFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlFloorFunction(SqlKind kind) {
  super(kind.name(), kind, ReturnTypes.ARG0_OR_EXACT_NO_SCALE, null,
      OperandTypes.or(OperandTypes.NUMERIC_OR_INTERVAL,
          OperandTypes.sequence(
              "'" + kind + "(<DATE> TO <TIME_UNIT>)'\n"
              + "'" + kind + "(<TIME> TO <TIME_UNIT>)'\n"
              + "'" + kind + "(<TIMESTAMP> TO <TIME_UNIT>)'",
              OperandTypes.DATETIME,
              OperandTypes.ANY)),
      SqlFunctionCategory.NUMERIC);
  Preconditions.checkArgument(kind == SqlKind.FLOOR || kind == SqlKind.CEIL);
}
 
Example 8
Source File: SqlFirstLastValueAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public SqlFirstLastValueAggFunction(SqlKind kind) {
	super(
			kind.name(),
			null,
			kind,
			ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
			null,
			OperandTypes.ANY,
			SqlFunctionCategory.NUMERIC,
			false,
			false,
			Optionality.FORBIDDEN);
	Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE
			|| kind == SqlKind.LAST_VALUE);
}
 
Example 9
Source File: SqlFirstLastValueAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public SqlFirstLastValueAggFunction(SqlKind kind) {
	super(
			kind.name(),
			null,
			kind,
			ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
			null,
			OperandTypes.ANY,
			SqlFunctionCategory.NUMERIC,
			false,
			false,
			Optionality.FORBIDDEN);
	Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE
			|| kind == SqlKind.LAST_VALUE);
}
 
Example 10
Source File: SqlAnyValueAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlAnyValueAggFunction. */
public SqlAnyValueAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.ANY_VALUE);
}
 
Example 11
Source File: SqlBitOpAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlBitOpAggFunction. */
public SqlBitOpAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.INTEGER,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.BIT_AND
      || kind == SqlKind.BIT_OR);
}
 
Example 12
Source File: SqlFirstLastValueAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlFirstLastValueAggFunction(SqlKind kind) {
  super(
      kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.NUMERIC,
      false,
      true,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE
      || kind == SqlKind.LAST_VALUE);
}
 
Example 13
Source File: SqlCovarAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SqlCovarAggFunction.
 */
public SqlCovarAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      kind == SqlKind.REGR_COUNT ? ReturnTypes.BIGINT : ReturnTypes.COVAR_REGR_FUNCTION,
      null,
      OperandTypes.NUMERIC_NUMERIC,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(kind),
      "unsupported sql kind: " + kind);
}
 
Example 14
Source File: SqlLeadLagAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlLeadLagAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      RETURN_TYPE,
      null,
      OPERAND_TYPES,
      SqlFunctionCategory.NUMERIC,
      false,
      true,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.LEAD
      || kind == SqlKind.LAG);
}
 
Example 15
Source File: OverConvertRule.java    From flink with Apache License 2.0 4 votes vote down vote up
private RexWindowBound createBound(ConvertContext context, Expression bound, SqlKind sqlKind) {
	if (bound instanceof CallExpression) {
		CallExpression callExpr = (CallExpression) bound;
		FunctionDefinition func = callExpr.getFunctionDefinition();
		if (BuiltInFunctionDefinitions.UNBOUNDED_ROW.equals(func) || BuiltInFunctionDefinitions.UNBOUNDED_RANGE
			.equals(func)) {
			SqlNode unbounded = sqlKind.equals(SqlKind.PRECEDING) ? SqlWindow
				.createUnboundedPreceding(SqlParserPos.ZERO) :
				SqlWindow.createUnboundedFollowing(SqlParserPos.ZERO);
			return RexWindowBound.create(unbounded, null);
		} else if (BuiltInFunctionDefinitions.CURRENT_ROW.equals(func) || BuiltInFunctionDefinitions.CURRENT_RANGE
			.equals(func)) {
			SqlNode currentRow = SqlWindow.createCurrentRow(SqlParserPos.ZERO);
			return RexWindowBound.create(currentRow, null);
		} else {
			throw new IllegalArgumentException("Unexpected expression: " + bound);
		}
	} else if (bound instanceof ValueLiteralExpression) {
		RelDataType returnType = context.getTypeFactory()
			.createFieldTypeFromLogicalType(new DecimalType(true, 19, 0));
		SqlOperator sqlOperator = new SqlPostfixOperator(
			sqlKind.name(),
			sqlKind,
			2,
			new OrdinalReturnTypeInference(0),
			null,
			null);
		SqlNode[] operands = new SqlNode[] { SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO) };
		SqlNode node = new SqlBasicCall(sqlOperator, operands, SqlParserPos.ZERO);

		ValueLiteralExpression literalExpr = (ValueLiteralExpression) bound;
		RexNode literalRexNode = literalExpr.getValueAs(BigDecimal.class)
			.map(v -> context.getRelBuilder().literal(v))
			.orElse(context.getRelBuilder().literal(extractValue(literalExpr, Object.class)));

		List<RexNode> expressions = new ArrayList<>();
		expressions.add(literalRexNode);
		RexNode rexNode = context.getRelBuilder().getRexBuilder().makeCall(
			returnType, sqlOperator, expressions);
		return RexWindowBound.create(node, rexNode);
	} else {
		throw new TableException("Unexpected expression: " + bound);
	}
}
 
Example 16
Source File: SqlNthValueAggFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlNthValueAggFunction(SqlKind kind) {
  super(kind.name(), null, kind, ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null, OperandTypes.ANY_NUMERIC, SqlFunctionCategory.NUMERIC, false,
      true, Optionality.FORBIDDEN);
}
 
Example 17
Source File: SqlMinMaxAggFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Creates a SqlMinMaxAggFunction. */
public SqlMinMaxAggFunction(SqlKind kind) {
  this(kind.name(), kind, OperandTypes.COMPARABLE_ORDERED);
}
 
Example 18
Source File: SqlAvgAggFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a SqlAvgAggFunction.
 */
public SqlAvgAggFunction(SqlKind kind) {
  this(kind.name(), kind);
}
 
Example 19
Source File: SqlAvgAggFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a SqlAvgAggFunction.
 */
public SqlAvgAggFunction(SqlKind kind) {
  this(kind.name(), kind);
}
 
Example 20
Source File: SqlNthValueAggFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlNthValueAggFunction(SqlKind kind) {
  super(kind.name(), null, kind, ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null, OperandTypes.ANY_NUMERIC, SqlFunctionCategory.NUMERIC, false,
      true, Optionality.FORBIDDEN);
}