本文整理汇总了Java中org.apache.calcite.sql.SqlLiteral类的典型用法代码示例。如果您正苦于以下问题:Java SqlLiteral类的具体用法?Java SqlLiteral怎么用?Java SqlLiteral使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlLiteral类属于org.apache.calcite.sql包,在下文中一共展示了SqlLiteral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewrite
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
SqlExplain node = unwrap(sqlNode, SqlExplain.class);
SqlLiteral op = node.operand(2);
SqlExplain.Depth depth = (SqlExplain.Depth) op.getValue();
if (node.getDetailLevel() != null) {
level = node.getDetailLevel();
}
switch (depth) {
case LOGICAL:
mode = ResultMode.LOGICAL;
break;
case PHYSICAL:
mode = ResultMode.PHYSICAL;
break;
default:
throw new UnsupportedOperationException("Unknown depth " + depth);
}
return node.operand(0);
}
示例2: SqlCreateTable
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
public SqlCreateTable(
SqlParserPos pos,
SqlIdentifier tblName,
SqlNodeList fieldList,
PartitionDistributionStrategy partitionDistributionStrategy,
SqlNodeList partitionColumns,
SqlNodeList formatOptions,
SqlLiteral singleWriter,
SqlNode query,
SqlNodeList sortFieldList,
SqlNodeList distributionColumns) {
super(pos);
this.tblName = tblName;
this.fieldList = fieldList;
this.partitionDistributionStrategy = partitionDistributionStrategy;
this.partitionColumns = partitionColumns;
this.formatOptions = formatOptions;
this.singleWriter = singleWriter;
this.query = query;
this.sortColumns = sortFieldList;
this.distributionColumns = distributionColumns;
}
示例3: convertCall
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
final SqlLiteral literal = (SqlLiteral) call.getOperandList().get(0);
final String value = ((NlsString)literal.getValue()).getValue();
TimeUnitRange range = VALID_PERIODS.get(value.toLowerCase());
Preconditions.checkNotNull(range, "Unhandle range type: %s.", value);
List<RexNode> exprs = new ArrayList<>();
exprs.add(rexBuilder.makeFlag(range));
exprs.add(cx.convertExpression(call.getOperandList().get(1)));
RelDataTypeFactory typeFactory = cx.getTypeFactory();
final RelDataType returnType
= typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), exprs.get(1).getType().isNullable());
return rexBuilder.makeCall(returnType, SqlStdOperatorTable.EXTRACT, exprs);
}
示例4: implement
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
public JdbcImplementor.Result implement(JdbcImplementor implementor) {
final JdbcImplementor.Result leftResult =
implementor.visitChild(0, left);
final JdbcImplementor.Result rightResult =
implementor.visitChild(1, right);
final JdbcImplementor.Context leftContext = leftResult.qualifiedContext();
final JdbcImplementor.Context rightContext =
rightResult.qualifiedContext();
SqlNode sqlCondition = convertConditionToSqlNode(condition,
leftContext,
rightContext,
left.getRowType().getFieldCount());
SqlNode join =
new SqlJoin(POS,
leftResult.asFrom(),
SqlLiteral.createBoolean(false, POS),
joinType(joinType).symbol(POS),
rightResult.asFrom(),
JoinConditionType.ON.symbol(POS),
sqlCondition);
return implementor.result(join, leftResult, rightResult);
}
示例5: visitJoin
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
public Result visitJoin(Join e) {
final Result leftResult = visitChild(0, e.getLeft());
final Result rightResult = visitChild(1, e.getRight());
final Context leftContext = leftResult.qualifiedContext();
final Context rightContext =
rightResult.qualifiedContext();
SqlNode sqlCondition = convertConditionToSqlNode(e.getCondition(),
leftContext,
rightContext,
e.getLeft().getRowType().getFieldCount());
SqlNode join =
new SqlJoin(POS,
leftResult.asFrom(),
SqlLiteral.createBoolean(false, POS),
joinType(e.getJoinType()).symbol(POS),
rightResult.asFrom(),
JoinConditionType.ON.symbol(POS),
sqlCondition);
return result(join, leftResult, rightResult);
}
示例6: parseTimestampLiteral
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
public static SqlTimestampLiteral parseTimestampLiteral(String s,
SqlParserPos pos) {
final String dateStr = parseString(s);
final DateTimeUtils.PrecisionTime pt =
DateTimeUtils.parsePrecisionDateTimeLiteral(dateStr,
Format.PER_THREAD.get().timestamp, DateTimeUtils.UTC_ZONE, -1);
if (pt == null) {
throw SqlUtil.newContextException(pos,
RESOURCE.illegalLiteral("TIMESTAMP", s,
RESOURCE.badFormat(DateTimeUtils.TIMESTAMP_FORMAT_STRING).str()));
}
final TimestampString ts =
TimestampString.fromCalendarFields(pt.getCalendar())
.withFraction(pt.getFraction());
return SqlLiteral.createTimestamp(ts, pt.getPrecision(), pos);
}
示例7: validateQuery
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
public void validateQuery(SqlNode node, SqlValidatorScope scope,
RelDataType targetRowType) {
final SqlValidatorNamespace ns = getNamespace(node, scope);
if (node.getKind() == SqlKind.TABLESAMPLE) {
List<SqlNode> operands = ((SqlCall) node).getOperandList();
SqlSampleSpec sampleSpec = SqlLiteral.sampleValue(operands.get(1));
if (sampleSpec instanceof SqlSampleSpec.SqlTableSampleSpec) {
validateFeature(RESOURCE.sQLFeature_T613(), node.getParserPosition());
} else if (sampleSpec
instanceof SqlSampleSpec.SqlSubstitutionSampleSpec) {
validateFeature(RESOURCE.sQLFeatureExt_T613_Substitution(),
node.getParserPosition());
}
}
validateNamespace(ns, targetRowType);
if (node == top) {
validateModality(node);
}
validateAccess(
node,
ns.getTable(),
SqlAccessEnum.SELECT);
}
示例8: visit
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
public SqlNode visit(SqlLiteral literal) {
// Ordinal markers, e.g. 'select a, b from t order by 2'.
// Only recognize them if they are the whole expression,
// and if the dialect permits.
if (literal == root && getConformance().isSortByOrdinal()) {
switch (literal.getTypeName()) {
case DECIMAL:
case DOUBLE:
final int intValue = literal.intValue(false);
if (intValue >= 0) {
if (intValue < 1 || intValue > aliasList.size()) {
throw newValidationError(
literal, RESOURCE.orderByOrdinalOutOfRange());
}
// SQL ordinals are 1-based, but Sort's are 0-based
int ordinal = intValue - 1;
return nthSelectItem(ordinal, literal.getParserPosition());
}
break;
}
}
return super.visit(literal);
}
示例9: unparseCall
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
if (call.getOperator() == SqlStdOperatorTable.SUBSTRING) {
SqlUtil.unparseFunctionSyntax(OracleSqlOperatorTable.SUBSTR, writer, call);
} else {
switch (call.getKind()) {
case FLOOR:
if (call.operandCount() != 2) {
super.unparseCall(writer, call, leftPrec, rightPrec);
return;
}
final SqlLiteral timeUnitNode = call.operand(1);
final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);
SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, timeUnit.name(),
timeUnitNode.getParserPosition());
SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
break;
default:
super.unparseCall(writer, call, leftPrec, rightPrec);
}
}
}
示例10: unparseCall
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
switch (call.getKind()) {
case FLOOR:
if (call.operandCount() != 2) {
super.unparseCall(writer, call, leftPrec, rightPrec);
return;
}
final SqlLiteral timeUnitNode = call.operand(1);
final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);
final String translatedLit = convertTimeUnit(timeUnit);
SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, translatedLit,
timeUnitNode.getParserPosition());
SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
break;
default:
super.unparseCall(writer, call, leftPrec, rightPrec);
}
}
示例11: unparseCall
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
switch (call.getKind()) {
case FLOOR:
if (call.operandCount() != 2) {
super.unparseCall(writer, call, leftPrec, rightPrec);
return;
}
final SqlLiteral timeUnitNode = call.operand(1);
final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);
SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, timeUnit.name(),
timeUnitNode.getParserPosition());
SqlFloorFunction.unparseDatetimeFunction(writer, call2, "DATE_TRUNC", false);
break;
default:
super.unparseCall(writer, call, leftPrec, rightPrec);
}
}
示例12: createSwitched
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
/**
* Creates a call to the switched form of the case operator, viz:
*
* <blockquote><code>CASE value<br>
* WHEN whenList[0] THEN thenList[0]<br>
* WHEN whenList[1] THEN thenList[1]<br>
* ...<br>
* ELSE elseClause<br>
* END</code></blockquote>
*/
public static SqlCase createSwitched(SqlParserPos pos, SqlNode value,
SqlNodeList whenList, SqlNodeList thenList, SqlNode elseClause) {
if (null != value) {
List<SqlNode> list = whenList.getList();
for (int i = 0; i < list.size(); i++) {
SqlNode e = list.get(i);
final SqlCall call;
if (e instanceof SqlNodeList) {
call = SqlStdOperatorTable.IN.createCall(pos, value, e);
} else {
call = SqlStdOperatorTable.EQUALS.createCall(pos, value, e);
}
list.set(i, call);
}
}
if (null == elseClause) {
elseClause = SqlLiteral.createNull(pos);
}
return new SqlCase(pos, null, whenList, thenList, elseClause);
}
示例13: validateValueAgainstConstraint
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
/**
* Ensures that a source value does not violate the constraint of the target
* column.
*
* @param sourceValue The insert value being validated
* @param targetConstraint The constraint applied to sourceValue for validation
* @param errorSupplier The function to apply when validation fails
*/
public static void validateValueAgainstConstraint(SqlNode sourceValue,
RexNode targetConstraint,
Supplier<CalciteContextException> errorSupplier) {
if (!(sourceValue instanceof SqlLiteral)) {
// We cannot guarantee that the value satisfies the constraint.
throw errorSupplier.get();
}
final SqlLiteral insertValue = (SqlLiteral) sourceValue;
final RexLiteral columnConstraint = (RexLiteral) targetConstraint;
final RexSqlStandardConvertletTable convertletTable =
new RexSqlStandardConvertletTable();
final RexToSqlNodeConverter sqlNodeToRexConverter =
new RexToSqlNodeConverterImpl(convertletTable);
final SqlLiteral constraintValue =
(SqlLiteral) sqlNodeToRexConverter.convertLiteral(columnConstraint);
if (!insertValue.equals(constraintValue)) {
// The value does not satisfy the constraint.
throw errorSupplier.get();
}
}
示例14: testSqlNodeLiteral
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
/** Tests {@link org.apache.calcite.sql.SqlUtil#isLiteral(SqlNode, boolean)},
* which was added to enhance Calcite's public API
* <a href="https://issues.apache.org/jira/browse/CALCITE-1219">[CALCITE-1219]
* Add a method to SqlOperatorBinding to determine whether operand is a
* literal</a>.
*/
@Test public void testSqlNodeLiteral() {
final SqlNode literal = SqlLiteral.createExactNumeric(
"0",
SqlParserPos.ZERO);
final SqlNode castLiteral = SqlStdOperatorTable.CAST.createCall(
SqlParserPos.ZERO,
literal,
integerType);
final SqlNode castCastLiteral = SqlStdOperatorTable.CAST.createCall(
SqlParserPos.ZERO,
castLiteral,
integerType);
// SqlLiteral is considered as a Literal
assertSame(true, SqlUtil.isLiteral(literal, true));
// CAST(SqlLiteral as type) is considered as a Literal
assertSame(true, SqlUtil.isLiteral(castLiteral, true));
// CAST(CAST(SqlLiteral as type) as type) is NOT considered as a Literal
assertSame(false, SqlUtil.isLiteral(castCastLiteral, true));
}
示例15: unwrapConstant
import org.apache.calcite.sql.SqlLiteral; //导入依赖的package包/类
/**
* Unwrap a constant in the AST as a Java Object.
*
* <p>The Calcite validator has folded all the constants by this point.
* Thus the function expects either a SqlLiteral or a SqlIdentifier but not a SqlCall.</p>
*/
private static String unwrapConstant(SqlNode value) {
if (value == null) {
return null;
} else if (value instanceof SqlLiteral) {
return ((SqlLiteral) value).toValue();
} else if (value instanceof SqlIdentifier) {
return value.toString();
} else {
throw new IllegalArgumentException("Invalid constant " + value);
}
}