Java Code Examples for org.apache.calcite.sql.SqlKind#DEFAULT

The following examples show how to use org.apache.calcite.sql.SqlKind#DEFAULT . 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: SqlUserDefinedTableMacro.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static Object getValue(SqlNode right) throws NonLiteralException {
  switch (right.getKind()) {
  case ARRAY_VALUE_CONSTRUCTOR:
    final List<Object> list = new ArrayList<>();
    for (SqlNode o : ((SqlCall) right).getOperandList()) {
      list.add(getValue(o));
    }
    return ImmutableNullableList.copyOf(list);
  case MAP_VALUE_CONSTRUCTOR:
    final ImmutableMap.Builder<Object, Object> builder2 =
        ImmutableMap.builder();
    final List<SqlNode> operands = ((SqlCall) right).getOperandList();
    for (int i = 0; i < operands.size(); i += 2) {
      final SqlNode key = operands.get(i);
      final SqlNode value = operands.get(i + 1);
      builder2.put(getValue(key), getValue(value));
    }
    return builder2.build();
  default:
    if (SqlUtil.isNullLiteral(right, true)) {
      return null;
    }
    if (SqlUtil.isLiteral(right)) {
      return ((SqlLiteral) right).getValue();
    }
    if (right.getKind() == SqlKind.DEFAULT) {
      return null; // currently NULL is the only default value
    }
    throw new NonLiteralException();
  }
}
 
Example 2
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private boolean isRowWithDefault(SqlNode operand, int column) {
	switch (operand.getKind()) {
		case ROW:
			final SqlCall row = (SqlCall) operand;
			return row.getOperandList().size() >= column
				&& row.getOperandList().get(column).getKind() == SqlKind.DEFAULT;
	}
	return false;
}
 
Example 3
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean isRowWithDefault(SqlNode operand, int column) {
	switch (operand.getKind()) {
		case ROW:
			final SqlCall row = (SqlCall) operand;
			return row.getOperandList().size() >= column
				&& row.getOperandList().get(column).getKind() == SqlKind.DEFAULT;
	}
	return false;
}
 
Example 4
Source File: HiveTableSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object getValue(SqlNode right) throws NonLiteralException {
	switch (right.getKind()) {
		case ARRAY_VALUE_CONSTRUCTOR:
			final List<Object> list = new ArrayList<>();
			for (SqlNode o : ((SqlCall) right).getOperandList()) {
				list.add(getValue(o));
			}
			return ImmutableNullableList.copyOf(list).toArray();
		case MAP_VALUE_CONSTRUCTOR:
			final Map<Object, Object> map = new HashMap<>();
			final List<SqlNode> operands = ((SqlCall) right).getOperandList();
			for (int i = 0; i < operands.size(); i += 2) {
				final SqlNode key = operands.get(i);
				final SqlNode value = operands.get(i + 1);
				map.put(getValue(key), getValue(value));
			}
			return map;
		default:
			if (SqlUtil.isNullLiteral(right, true)) {
				return null;
			}
			if (SqlUtil.isLiteral(right)) {
				return ((SqlLiteral) right).getValue();
			}
			if (right.getKind() == SqlKind.DEFAULT) {
				return null; // currently NULL is the only default value
			}
			throw new NonLiteralException();
	}
}
 
Example 5
Source File: HiveTableSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object getValue(SqlNode right) throws NonLiteralException {
	switch (right.getKind()) {
		case ARRAY_VALUE_CONSTRUCTOR:
			final List<Object> list = new ArrayList<>();
			for (SqlNode o : ((SqlCall) right).getOperandList()) {
				list.add(getValue(o));
			}
			return ImmutableNullableList.copyOf(list).toArray();
		case MAP_VALUE_CONSTRUCTOR:
			final Map<Object, Object> map = new HashMap<>();
			final List<SqlNode> operands = ((SqlCall) right).getOperandList();
			for (int i = 0; i < operands.size(); i += 2) {
				final SqlNode key = operands.get(i);
				final SqlNode value = operands.get(i + 1);
				map.put(getValue(key), getValue(value));
			}
			return map;
		default:
			if (SqlUtil.isNullLiteral(right, true)) {
				return null;
			}
			if (SqlUtil.isLiteral(right)) {
				return ((SqlLiteral) right).getValue();
			}
			if (right.getKind() == SqlKind.DEFAULT) {
				return null; // currently NULL is the only default value
			}
			throw new NonLiteralException();
	}
}
 
Example 6
Source File: SqlUserDefinedTableMacro.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static Object getValue(SqlNode right) throws NonLiteralException {
  switch (right.getKind()) {
  case ARRAY_VALUE_CONSTRUCTOR:
    final List<Object> list = new ArrayList<>();
    for (SqlNode o : ((SqlCall) right).getOperandList()) {
      list.add(getValue(o));
    }
    return ImmutableNullableList.copyOf(list);
  case MAP_VALUE_CONSTRUCTOR:
    final ImmutableMap.Builder<Object, Object> builder2 =
        ImmutableMap.builder();
    final List<SqlNode> operands = ((SqlCall) right).getOperandList();
    for (int i = 0; i < operands.size(); i += 2) {
      final SqlNode key = operands.get(i);
      final SqlNode value = operands.get(i + 1);
      builder2.put(getValue(key), getValue(value));
    }
    return builder2.build();
  case CAST:
    return getValue(((SqlCall) right).operand(0));
  default:
    if (SqlUtil.isNullLiteral(right, true)) {
      return null;
    }
    if (SqlUtil.isLiteral(right)) {
      return ((SqlLiteral) right).getValue();
    }
    if (right.getKind() == SqlKind.DEFAULT) {
      return null; // currently NULL is the only default value
    }
    throw new NonLiteralException();
  }
}
 
Example 7
Source File: SqlDefaultOperator.java    From Bats with Apache License 2.0 4 votes vote down vote up
SqlDefaultOperator() {
  super("DEFAULT", SqlKind.DEFAULT, 100, true,
      ReturnTypes.explicit(SqlTypeName.ANY), InferTypes.RETURN_TYPE,
      OperandTypes.NILADIC);
}
 
Example 8
Source File: SqlDefaultOperator.java    From calcite with Apache License 2.0 4 votes vote down vote up
SqlDefaultOperator() {
  super("DEFAULT", SqlKind.DEFAULT, 100, true,
      ReturnTypes.explicit(SqlTypeName.ANY), InferTypes.RETURN_TYPE,
      OperandTypes.NILADIC);
}