本文整理汇总了Java中org.apache.calcite.sql.SqlLiteral.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java SqlLiteral.getValue方法的具体用法?Java SqlLiteral.getValue怎么用?Java SqlLiteral.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.sql.SqlLiteral
的用法示例。
在下文中一共展示了SqlLiteral.getValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createOptionValue
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static OptionValue createOptionValue(final String name, final OptionValue.OptionType type,
final SqlLiteral literal) {
final Object object = literal.getValue();
final SqlTypeName typeName = literal.getTypeName();
switch (typeName) {
case DECIMAL: {
final BigDecimal bigDecimal = (BigDecimal) object;
if (bigDecimal.scale() == 0) {
return OptionValue.createLong(type, name, bigDecimal.longValue());
} else {
return OptionValue.createDouble(type, name, bigDecimal.doubleValue());
}
}
case DOUBLE:
case FLOAT:
return OptionValue.createDouble(type, name, ((BigDecimal) object).doubleValue());
case SMALLINT:
case TINYINT:
case BIGINT:
case INTEGER:
return OptionValue.createLong(type, name, ((BigDecimal) object).longValue());
case VARBINARY:
case VARCHAR:
case CHAR:
return OptionValue.createString(type, name, ((NlsString) object).getValue());
case BOOLEAN:
return OptionValue.createBoolean(type, name, (Boolean) object);
default:
throw UserException.validationError()
.message("Drill doesn't support assigning literals of type %s in SET statements.", typeName)
.build(logger);
}
}
示例3: createOptionValue
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static OptionValue createOptionValue(final String name, final OptionValue.OptionType type,
final SqlLiteral literal) {
final Object object = literal.getValue();
final SqlTypeName typeName = literal.getTypeName();
switch (typeName) {
case DECIMAL: {
final BigDecimal bigDecimal = (BigDecimal) object;
if (bigDecimal.scale() == 0) {
return OptionValue.createLong(type, name, bigDecimal.longValue());
} else {
return OptionValue.createDouble(type, name, bigDecimal.doubleValue());
}
}
case DOUBLE:
case FLOAT:
return OptionValue.createDouble(type, name, ((BigDecimal) object).doubleValue());
case SMALLINT:
case TINYINT:
case BIGINT:
case INTEGER:
return OptionValue.createLong(type, name, ((BigDecimal) object).longValue());
case VARBINARY:
case VARCHAR:
case CHAR:
return OptionValue.createString(type, name, ((NlsString) object).getValue());
case BOOLEAN:
return OptionValue.createBoolean(type, name, (Boolean) object);
default:
throw UserException.validationError()
.message("Dremio doesn't support assigning literals of type %s in SET statements.", typeName)
.build(logger);
}
}
示例4: containsNullLiteral
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static boolean containsNullLiteral(SqlNodeList valueList) {
for (SqlNode node : valueList.getList()) {
if (node instanceof SqlLiteral) {
SqlLiteral lit = (SqlLiteral) node;
if (lit.getValue() == null) {
return true;
}
}
}
return false;
}
示例5: sqlLiteralToObject
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static Object sqlLiteralToObject(final SqlLiteral literal) {
final Object object = literal.getValue();
final SqlTypeName typeName = literal.getTypeName();
switch (typeName) {
case DECIMAL: {
final BigDecimal bigDecimal = (BigDecimal) object;
if (bigDecimal.scale() == 0) {
return bigDecimal.longValue();
} else {
return bigDecimal.doubleValue();
}
}
case DOUBLE:
case FLOAT:
return ((BigDecimal) object).doubleValue();
case SMALLINT:
case TINYINT:
case BIGINT:
case INTEGER:
return ((BigDecimal) object).longValue();
case VARBINARY:
case VARCHAR:
case CHAR:
return ((NlsString) object).getValue().toString();
case BOOLEAN:
return object;
default:
throw UserException.validationError()
.message("Drill doesn't support assigning literals of type %s in SET statements.", typeName)
.build(logger);
}
}
示例6: containsNullLiteral
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static boolean containsNullLiteral(SqlNodeList valueList) {
for (SqlNode node : valueList.getList()) {
if (node instanceof SqlLiteral) {
SqlLiteral lit = (SqlLiteral) node;
if (lit.getValue() == null) {
return true;
}
}
}
return false;
}
示例7: validateLiteralAsDouble
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private void validateLiteralAsDouble(SqlLiteral literal) {
BigDecimal bd = (BigDecimal) literal.getValue();
double d = bd.doubleValue();
if (Double.isInfinite(d) || Double.isNaN(d)) {
// overflow
throw newValidationError(literal,
RESOURCE.numberLiteralOutOfRange(Util.toScientificNotation(bd)));
}
// REVIEW jvs 4-Aug-2004: what about underflow?
}
示例8: unparseFloor
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
/**
* Unparses datetime floor for Microsoft SQL Server.
* There is no TRUNC function, so simulate this using calls to CONVERT.
*
* @param writer Writer
* @param call Call
*/
private void unparseFloor(SqlWriter writer, SqlCall call) {
SqlLiteral node = call.operand(1);
TimeUnitRange unit = (TimeUnitRange) node.getValue();
switch (unit) {
case YEAR:
unparseFloorWithUnit(writer, call, 4, "-01-01");
break;
case MONTH:
unparseFloorWithUnit(writer, call, 7, "-01");
break;
case WEEK:
writer.print("CONVERT(DATETIME, CONVERT(VARCHAR(10), "
+ "DATEADD(day, - (6 + DATEPART(weekday, ");
call.operand(0).unparse(writer, 0, 0);
writer.print(")) % 7, ");
call.operand(0).unparse(writer, 0, 0);
writer.print("), 126))");
break;
case DAY:
unparseFloorWithUnit(writer, call, 10, "");
break;
case HOUR:
unparseFloorWithUnit(writer, call, 13, ":00:00");
break;
case MINUTE:
unparseFloorWithUnit(writer, call, 16, ":00");
break;
case SECOND:
unparseFloorWithUnit(writer, call, 19, ":00");
break;
default:
throw new IllegalArgumentException("MSSQL does not support FLOOR for time unit: "
+ unit);
}
}
示例9: toResult
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
@Override
public List<Explain> toResult(String sql, SqlNode sqlNode) throws Exception {
try {
final SqlExplain node = SqlNodeUtil.unwrap(sqlNode, SqlExplain.class);
final SqlLiteral op = node.operand(2);
final SqlExplain.Depth depth = (SqlExplain.Depth) op.getValue();
final ResultMode mode;
SqlExplainLevel level = SqlExplainLevel.ALL_ATTRIBUTES;
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);
}
final SqlNode innerNode = node.operand(0);
// try(DisabledBlock block = toggle.openDisabledBlock()){
Rel drel;
final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, innerNode);
final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
final RelNode queryRelNode = convertedRelNode.getConvertedNode();
PrelTransformer.log("Calcite", queryRelNode, logger, null);
drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType);
if (mode == ResultMode.LOGICAL) {
return Collections.singletonList(new Explain(RelOptUtil.toString(drel, level)));
}
final Pair<Prel, String> convertToPrel = PrelTransformer.convertToPrel(config, drel);
final String text = convertToPrel.getValue();
return Collections.singletonList(new Explain(text));
// }
} catch (Exception ex){
throw SqlExceptionHelper.coerceException(logger, sql, ex, true);
}
}
示例10: convertOver
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private RexNode convertOver(Blackboard bb, SqlNode node) {
SqlCall call = (SqlCall) node;
SqlCall aggCall = call.operand(0);
SqlNode windowOrRef = call.operand(1);
final SqlWindow window =
validator.resolveWindow(windowOrRef, bb.scope, true);
// ROW_NUMBER() expects specific kind of framing.
if (aggCall.getKind() == SqlKind.ROW_NUMBER) {
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO));
window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO));
window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO));
}
final SqlNodeList partitionList = window.getPartitionList();
final ImmutableList.Builder<RexNode> partitionKeys =
ImmutableList.builder();
for (SqlNode partition : partitionList) {
partitionKeys.add(bb.convertExpression(partition));
}
RexNode lowerBound = bb.convertExpression(window.getLowerBound());
RexNode upperBound = bb.convertExpression(window.getUpperBound());
SqlNodeList orderList = window.getOrderList();
if ((orderList.size() == 0) && !window.isRows()) {
// A logical range requires an ORDER BY clause. Use the implicit
// ordering of this relation. There must be one, otherwise it would
// have failed validation.
orderList = bb.scope.getOrderList();
if (orderList == null) {
throw new AssertionError(
"Relation should have sort key for implicit ORDER BY");
}
}
final ImmutableList.Builder<RexFieldCollation> orderKeys =
ImmutableList.builder();
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
for (SqlNode order : orderList) {
flags.clear();
RexNode e = bb.convertSortExpression(order, flags);
orderKeys.add(new RexFieldCollation(e, flags));
}
try {
Preconditions.checkArgument(bb.window == null,
"already in window agg mode");
bb.window = window;
RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
rexAgg =
rexBuilder.ensureType(
validator.getValidatedNodeType(call), rexAgg, false);
// Walk over the tree and apply 'over' to all agg functions. This is
// necessary because the returned expression is not necessarily a call
// to an agg function. For example, AVG(x) becomes SUM(x) / COUNT(x).
final SqlLiteral q = aggCall.getFunctionQuantifier();
final boolean isDistinct = q != null
&& q.getValue() == SqlSelectKeyword.DISTINCT;
final RexShuttle visitor =
new HistogramShuttle(
partitionKeys.build(), orderKeys.build(),
RexWindowBound.create(window.getLowerBound(), lowerBound),
RexWindowBound.create(window.getUpperBound(), upperBound),
window,
isDistinct);
RexNode overNode = rexAgg.accept(visitor);
return overNode;
} finally {
bb.window = null;
}
}
示例11: validateLiteral
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public void validateLiteral(SqlLiteral literal) {
switch (literal.getTypeName()) {
case DECIMAL:
// Decimal and long have the same precision (as 64-bit integers), so
// the unscaled value of a decimal must fit into a long.
// REVIEW jvs 4-Aug-2004: This should probably be calling over to
// the available calculator implementations to see what they
// support. For now use ESP instead.
//
// jhyde 2006/12/21: I think the limits should be baked into the
// type system, not dependent on the calculator implementation.
BigDecimal bd = (BigDecimal) literal.getValue();
BigInteger unscaled = bd.unscaledValue();
long longValue = unscaled.longValue();
if (!BigInteger.valueOf(longValue).equals(unscaled)) {
// overflow
throw newValidationError(literal,
RESOURCE.numberLiteralOutOfRange(bd.toString()));
}
break;
case DOUBLE:
validateLiteralAsDouble(literal);
break;
case BINARY:
final BitString bitString = (BitString) literal.getValue();
if ((bitString.getBitCount() % 8) != 0) {
throw newValidationError(literal, RESOURCE.binaryLiteralOdd());
}
break;
case DATE:
case TIME:
case TIMESTAMP:
Calendar calendar = literal.getValueAs(Calendar.class);
final int year = calendar.get(Calendar.YEAR);
final int era = calendar.get(Calendar.ERA);
if (year < 1 || era == GregorianCalendar.BC || year > 9999) {
throw newValidationError(literal,
RESOURCE.dateLiteralOutOfRange(literal.toString()));
}
break;
case INTERVAL_YEAR:
case INTERVAL_YEAR_MONTH:
case INTERVAL_MONTH:
case INTERVAL_DAY:
case INTERVAL_DAY_HOUR:
case INTERVAL_DAY_MINUTE:
case INTERVAL_DAY_SECOND:
case INTERVAL_HOUR:
case INTERVAL_HOUR_MINUTE:
case INTERVAL_HOUR_SECOND:
case INTERVAL_MINUTE:
case INTERVAL_MINUTE_SECOND:
case INTERVAL_SECOND:
if (literal instanceof SqlIntervalLiteral) {
SqlIntervalLiteral.IntervalValue interval =
(SqlIntervalLiteral.IntervalValue)
literal.getValue();
SqlIntervalQualifier intervalQualifier =
interval.getIntervalQualifier();
// ensure qualifier is good before attempting to validate literal
validateIntervalQualifier(intervalQualifier);
String intervalStr = interval.getIntervalLiteral();
// throws CalciteContextException if string is invalid
int[] values = intervalQualifier.evaluateIntervalLiteral(intervalStr,
literal.getParserPosition(), typeFactory.getTypeSystem());
Util.discard(values);
}
break;
default:
// default is to do nothing
}
}
示例12: unparse
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public void unparse(
SqlWriter writer,
SqlCall call,
int leftPrec,
int rightPrec) {
final SqlWriter.Frame frame = writer.startList("", "");
SqlCollation collation = null;
for (Ord<SqlNode> operand : Ord.zip(call.getOperandList())) {
SqlLiteral rand = (SqlLiteral) operand.e;
if (operand.i > 0) {
// SQL:2003 says there must be a newline between string
// fragments.
writer.newlineAndIndent();
}
if (rand instanceof SqlCharStringLiteral) {
NlsString nls = ((SqlCharStringLiteral) rand).getNlsString();
if (operand.i == 0) {
collation = nls.getCollation();
// print with prefix
writer.literal(nls.asSql(true, false));
} else {
// print without prefix
writer.literal(nls.asSql(false, false));
}
} else if (operand.i == 0) {
// print with prefix
rand.unparse(writer, leftPrec, rightPrec);
} else {
// print without prefix
if (rand.getTypeName() == SqlTypeName.BINARY) {
BitString bs = (BitString) rand.getValue();
writer.literal("'" + bs.toHexString() + "'");
} else {
writer.literal("'" + rand.toValue() + "'");
}
}
}
if (collation != null) {
collation.unparse(writer, 0, 0);
}
writer.endList(frame);
}