本文整理汇总了Java中org.apache.calcite.sql.SqlLiteral.createExactNumeric方法的典型用法代码示例。如果您正苦于以下问题:Java SqlLiteral.createExactNumeric方法的具体用法?Java SqlLiteral.createExactNumeric怎么用?Java SqlLiteral.createExactNumeric使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.sql.SqlLiteral
的用法示例。
在下文中一共展示了SqlLiteral.createExactNumeric方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: getNode
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public SqlNode getNode(SqlNode node){
SqlLiteral literal;
if(isArray){
literal = SqlLiteral.createExactNumeric(value, parserPos);
}else{
literal = SqlLiteral.createCharString(value, parserPos);
}
return new SqlBasicCall(SqlStdOperatorTable.ITEM, new SqlNode[]{ node, literal }, parserPos);
}
示例3: literal
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private SqlNode literal(RelDataType type, Object value) {
if (value == null) {
int precision = type.getPrecision();
int scale = type.getScale();
if (!type.getSqlTypeName().allowsPrec()) {
precision = -1;
}
if (!type.getSqlTypeName().allowsScale()) {
scale = -1;
}
return SqlStdOperatorTable.CAST.createCall(
SqlParserPos.ZERO,
SqlLiteral.createNull(SqlParserPos.ZERO),
new SqlDataTypeSpec(
new SqlIdentifier(type.getSqlTypeName().getName(),
SqlParserPos.ZERO), precision, scale, null, null,
SqlParserPos.ZERO));
}
switch (type.getSqlTypeName()) {
case BOOLEAN:
return SqlLiteral.createBoolean((Boolean) value, SqlParserPos.ZERO);
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
return SqlLiteral.createExactNumeric(
value.toString(), SqlParserPos.ZERO);
case CHAR:
case VARCHAR:
return SqlLiteral.createCharString(value.toString(), SqlParserPos.ZERO);
case TIMESTAMP:
TimestampString ts = TimestampString.fromMillisSinceEpoch((Long) value);
return SqlLiteral.createTimestamp(ts, type.getPrecision(),
SqlParserPos.ZERO);
default:
throw new AssertionError(type);
}
}
示例4: expandVariance
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private SqlNode expandVariance(
final SqlNode arg,
boolean biased,
boolean sqrt) {
/* stddev_pop(x) ==>
* power(
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / count(x),
* .5)
* stddev_samp(x) ==>
* power(
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / (count(x) - 1),
* .5)
* var_pop(x) ==>
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / count(x)
* var_samp(x) ==>
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / (count(x) - 1)
*/
final SqlParserPos pos = SqlParserPos.ZERO;
final SqlNode argSquared =
SqlStdOperatorTable.MULTIPLY.createCall(pos, arg, arg);
final SqlNode sumArgSquared =
SqlStdOperatorTable.SUM.createCall(pos, argSquared);
final SqlNode sum =
SqlStdOperatorTable.SUM.createCall(pos, arg);
final SqlNode sumSquared =
SqlStdOperatorTable.MULTIPLY.createCall(pos, sum, sum);
final SqlNode count =
SqlStdOperatorTable.COUNT.createCall(pos, arg);
final SqlNode avgSumSquared =
SqlStdOperatorTable.DIVIDE.createCall(
pos, sumSquared, count);
final SqlNode diff =
SqlStdOperatorTable.MINUS.createCall(
pos, sumArgSquared, avgSumSquared);
final SqlNode denominator;
if (biased) {
denominator = count;
} else {
final SqlNumericLiteral one =
SqlLiteral.createExactNumeric("1", pos);
denominator =
SqlStdOperatorTable.MINUS.createCall(
pos, count, one);
}
final SqlNode diffAsDouble =
CastHighOp.createCall(pos, diff);
final SqlNode div =
SqlStdOperatorTable.DIVIDE.createCall(
pos, diffAsDouble, denominator);
SqlNode result = div;
if (sqrt) {
final SqlNumericLiteral half =
SqlLiteral.createExactNumeric("0.5", pos);
result =
SqlStdOperatorTable.POWER.createCall(pos, div, half);
}
return result;
}
示例5: expandVariance
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private SqlNode expandVariance(
final SqlNode arg,
boolean biased,
boolean sqrt) {
/* stddev_pop(x) ==>
* power(
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / count(x),
* .5)
* stddev_samp(x) ==>
* power(
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / (count(x) - 1),
* .5)
* var_pop(x) ==>
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / count(x)
* var_samp(x) ==>
* (sum(x * x) - sum(x) * sum(x) / count(x))
* / (count(x) - 1)
*/
final SqlParserPos pos = SqlParserPos.ZERO;
// cast the argument to double
final SqlNode castHighArg = CastHighOp.createCall(pos, arg);
final SqlNode argSquared =
SqlStdOperatorTable.MULTIPLY.createCall(pos, castHighArg, castHighArg);
final SqlNode sumArgSquared =
SqlStdOperatorTable.SUM.createCall(pos, argSquared);
final SqlNode sum =
SqlStdOperatorTable.SUM.createCall(pos, castHighArg);
final SqlNode sumSquared =
SqlStdOperatorTable.MULTIPLY.createCall(pos, sum, sum);
final SqlNode count =
SqlStdOperatorTable.COUNT.createCall(pos, castHighArg);
final SqlNode avgSumSquared =
SqlStdOperatorTable.DIVIDE.createCall(
pos, sumSquared, count);
final SqlNode diff =
SqlStdOperatorTable.MINUS.createCall(
pos, sumArgSquared, avgSumSquared);
final SqlNode denominator;
if (biased) {
denominator = count;
} else {
final SqlNumericLiteral one =
SqlLiteral.createExactNumeric("1", pos);
denominator =
SqlStdOperatorTable.MINUS.createCall(
pos, count, one);
}
final SqlNode diffAsDouble =
CastHighOp.createCall(pos, diff);
final SqlNode div =
SqlStdOperatorTable.DIVIDE.createCall(
pos, diffAsDouble, denominator);
SqlNode result = div;
if (sqrt) {
final SqlNumericLiteral half =
SqlLiteral.createExactNumeric("0.5", pos);
result =
SqlStdOperatorTable.POWER.createCall(pos, div, half);
}
return result;
}
示例6: expandVariance
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private SqlNode expandVariance(
final SqlNode argInput,
final RelDataType varType,
final SqlRexContext cx,
boolean biased,
boolean sqrt) {
// stddev_pop(x) ==>
// power(
// (sum(x * x) - sum(x) * sum(x) / count(x))
// / count(x),
// .5)
//
// stddev_samp(x) ==>
// power(
// (sum(x * x) - sum(x) * sum(x) / count(x))
// / (count(x) - 1),
// .5)
//
// var_pop(x) ==>
// (sum(x * x) - sum(x) * sum(x) / count(x))
// / count(x)
//
// var_samp(x) ==>
// (sum(x * x) - sum(x) * sum(x) / count(x))
// / (count(x) - 1)
final SqlParserPos pos = SqlParserPos.ZERO;
final RexNode argRex = cx.convertExpression(argInput);
final SqlNode arg;
if (!argRex.getType().equals(varType)) {
arg = SqlStdOperatorTable.CAST.createCall(pos,
new SqlDataTypeSpec(new SqlIdentifier(varType.getSqlTypeName().getName(), pos),
varType.getPrecision(), varType.getScale(), null, null, pos));
} else {
arg = argInput;
}
final SqlNode argSquared =
SqlStdOperatorTable.MULTIPLY.createCall(pos, arg, arg);
final SqlNode sumArgSquared =
SqlStdOperatorTable.SUM.createCall(pos, argSquared);
final SqlNode sum =
SqlStdOperatorTable.SUM.createCall(pos, arg);
final SqlNode sumSquared =
SqlStdOperatorTable.MULTIPLY.createCall(pos, sum, sum);
final SqlNode count =
SqlStdOperatorTable.COUNT.createCall(pos, arg);
final SqlNode avgSumSquared =
SqlStdOperatorTable.DIVIDE.createCall(
pos, sumSquared, count);
final SqlNode diff =
SqlStdOperatorTable.MINUS.createCall(
pos, sumArgSquared, avgSumSquared);
final SqlNode denominator;
if (biased) {
denominator = count;
} else {
final SqlNumericLiteral one =
SqlLiteral.createExactNumeric("1", pos);
denominator =
SqlStdOperatorTable.MINUS.createCall(
pos, count, one);
}
final SqlNode div =
SqlStdOperatorTable.DIVIDE.createCall(
pos, diff, denominator);
SqlNode result = div;
if (sqrt) {
final SqlNumericLiteral half =
SqlLiteral.createExactNumeric("0.5", pos);
result =
SqlStdOperatorTable.POWER.createCall(pos, div, half);
}
return result;
}
示例7: convertLiteral
import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public SqlNode convertLiteral(RexLiteral literal) {
// Numeric
if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createExactNumeric(
literal.getValue().toString(),
SqlParserPos.ZERO);
}
if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createApproxNumeric(
literal.getValue().toString(),
SqlParserPos.ZERO);
}
// Timestamp
if (SqlTypeFamily.TIMESTAMP.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createTimestamp(
literal.getValueAs(TimestampString.class),
0,
SqlParserPos.ZERO);
}
// Date
if (SqlTypeFamily.DATE.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createDate(
literal.getValueAs(DateString.class),
SqlParserPos.ZERO);
}
// Time
if (SqlTypeFamily.TIME.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createTime(
literal.getValueAs(TimeString.class),
0,
SqlParserPos.ZERO);
}
// String
if (SqlTypeFamily.CHARACTER.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createCharString(
((NlsString) (literal.getValue())).getValue(),
SqlParserPos.ZERO);
}
// Boolean
if (SqlTypeFamily.BOOLEAN.getTypeNames().contains(
literal.getTypeName())) {
return SqlLiteral.createBoolean(
(Boolean) literal.getValue(),
SqlParserPos.ZERO);
}
return null;
}