Java Code Examples for org.apache.calcite.rex.RexLiteral#getTypeName()
The following examples show how to use
org.apache.calcite.rex.RexLiteral#getTypeName() .
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: DateRangeRules.java From Bats with Apache License 2.0 | 6 votes |
private Calendar timestampValue(RexLiteral timeLiteral) { switch (timeLiteral.getTypeName()) { case TIMESTAMP_WITH_LOCAL_TIME_ZONE: final TimeZone tz = TimeZone.getTimeZone(this.timeZone); return Util.calendar( SqlFunctions.timestampWithLocalTimeZoneToTimestamp(timeLiteral.getValueAs(Long.class), tz)); case TIMESTAMP: return Util.calendar(timeLiteral.getValueAs(Long.class)); case DATE: // Cast date to timestamp with local time zone final DateString d = timeLiteral.getValueAs(DateString.class); return Util.calendar(d.getMillisSinceEpoch()); default: throw Util.unexpected(timeLiteral.getTypeName()); } }
Example 2
Source File: NumericEquiDepthHistogram.java From Bats with Apache License 2.0 | 6 votes |
private Double getLiteralValue(final RexNode filter) { Double value = null; List<RexNode> operands = ((RexCall) filter).getOperands(); if (operands.size() == 2 && operands.get(1) instanceof RexLiteral) { RexLiteral l = ((RexLiteral) operands.get(1)); switch (l.getTypeName()) { case DATE: case TIMESTAMP: case TIME: value = (double) ((java.util.Calendar) l.getValue()).getTimeInMillis(); break; case INTEGER: case BIGINT: case FLOAT: case DOUBLE: case DECIMAL: case BOOLEAN: value = l.getValueAs(Double.class); break; default: break; } } return value; }
Example 3
Source File: DruidJsonFilter.java From calcite with Apache License 2.0 | 6 votes |
/** * @param rexNode rexNode to translate to Druid literal equivalante * @param rowType rowType associated to rexNode * @param druidQuery druid Query * * @return non null string or null if it can not translate to valid Druid equivalent */ @Nullable private static String toDruidLiteral(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { final String val; final RexLiteral rhsLiteral = (RexLiteral) rexNode; if (SqlTypeName.NUMERIC_TYPES.contains(rhsLiteral.getTypeName())) { val = String.valueOf(RexLiteral.value(rhsLiteral)); } else if (SqlTypeName.CHAR_TYPES.contains(rhsLiteral.getTypeName())) { val = String.valueOf(RexLiteral.stringValue(rhsLiteral)); } else if (SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE == rhsLiteral.getTypeName() || SqlTypeName.TIMESTAMP == rhsLiteral.getTypeName() || SqlTypeName.DATE == rhsLiteral.getTypeName()) { Long millisSinceEpoch = DruidDateTimeUtils.literalValue(rexNode); if (millisSinceEpoch == null) { throw new AssertionError( "Cannot translate Literal" + rexNode + " of type " + rhsLiteral.getTypeName() + " to TimestampString"); } val = DATE_FORMATTER.format(millisSinceEpoch); } else { // Don't know how to filter on this kind of literal. val = null; } return val; }
Example 4
Source File: DateRangeRules.java From calcite with Apache License 2.0 | 6 votes |
private Calendar timestampValue(RexLiteral timeLiteral) { switch (timeLiteral.getTypeName()) { case TIMESTAMP_WITH_LOCAL_TIME_ZONE: final TimeZone tz = TimeZone.getTimeZone(this.timeZone); return Util.calendar( SqlFunctions.timestampWithLocalTimeZoneToTimestamp( timeLiteral.getValueAs(Long.class), tz)); case TIMESTAMP: return Util.calendar(timeLiteral.getValueAs(Long.class)); case DATE: // Cast date to timestamp with local time zone final DateString d = timeLiteral.getValueAs(DateString.class); return Util.calendar(d.getMillisSinceEpoch()); default: throw Util.unexpected(timeLiteral.getTypeName()); } }
Example 5
Source File: DrillRelOptUtil.java From Bats with Apache License 2.0 | 5 votes |
public static boolean isLimit0(RexNode fetch) { if (fetch != null && fetch.isA(SqlKind.LITERAL)) { RexLiteral l = (RexLiteral) fetch; switch (l.getTypeName()) { case BIGINT: case INTEGER: case DECIMAL: if (((long) l.getValue2()) == 0) { return true; } } } return false; }
Example 6
Source File: OLAPProjectRel.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private void rewriteProjectForIntersect(RexNode rex, SqlTypeName sqlTypeName, BasicSqlType eleSqlType, ArraySqlType arraySqlType, int idx) { if (rex.isA(SqlKind.ARRAY_VALUE_CONSTRUCTOR)) { // somethings like ['2012-01-01', '2012-01-02', '2012-01-03'] List<RexNode> nodeList = ((RexCall) rex).getOperands(); RexLiteral newNode = null; boolean needChange = true; List<RexNode> newerList = new ArrayList<>(); if (!nodeList.isEmpty()) { for (RexNode node : nodeList) { if (node instanceof RexLiteral) { RexLiteral literal = (RexLiteral) node; if (literal.getTypeName() == sqlTypeName) { needChange = false; break; } else { newNode = RexLiteral.fromJdbcString(eleSqlType, sqlTypeName, literal.getValue2().toString()); } } if (newNode != null) { newerList.add(newNode); } newNode = null; } if (needChange) { rewriteProjects.set(idx, ((RexCall) rex).clone(arraySqlType, newerList)); logger.debug("Rewrite project REL {} for intersect count.", rewriteProjects.get(idx)); } } } }
Example 7
Source File: Limit0Converter.java From dremio-oss with Apache License 2.0 | 5 votes |
private static boolean isLimit0(RexNode fetch) { if (fetch != null && fetch.isA(SqlKind.LITERAL)) { RexLiteral l = (RexLiteral) fetch; switch (l.getTypeName()) { case BIGINT: case INTEGER: case DECIMAL: if (((long) l.getValue2()) == 0) { return true; } } } return false; }
Example 8
Source File: SchemaField.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public SchemaPath visitCall(RexCall call) { if(call.getOperator().getSyntax() != SqlSyntax.SPECIAL || call.getOperator() != SqlStdOperatorTable.ITEM){ return null; } LogicalExpression logExpr = call.getOperands().get(0).accept(this); if (!(logExpr instanceof SchemaPath)) { return (SchemaPath) logExpr; } SchemaPath left = (SchemaPath) logExpr; final RexLiteral literal = (RexLiteral) call.getOperands().get(1); switch(literal.getTypeName()){ case DECIMAL: case INTEGER: switch(indexMode){ case ALLOW: return left.getChild(((BigDecimal)literal.getValue()).intValue()); case SKIP: return left; case DISALLOW: default: return null; } case CHAR: case VARCHAR: return left.getChild(literal.getValue2().toString()); default: // fall through } return null; }
Example 9
Source File: OLAPProjectRel.java From kylin with Apache License 2.0 | 5 votes |
private void rewriteProjectForIntersect(RexNode rex, SqlTypeName sqlTypeName, BasicSqlType eleSqlType, ArraySqlType arraySqlType, int idx) { if (rex.isA(SqlKind.ARRAY_VALUE_CONSTRUCTOR)) { // somethings like ['2012-01-01', '2012-01-02', '2012-01-03'] List<RexNode> nodeList = ((RexCall) rex).getOperands(); RexLiteral newNode = null; boolean needChange = true; List<RexNode> newerList = new ArrayList<>(); if (!nodeList.isEmpty()) { for (RexNode node : nodeList) { if (node instanceof RexLiteral) { RexLiteral literal = (RexLiteral) node; if (literal.getTypeName() == sqlTypeName) { needChange = false; break; } else { newNode = RexLiteral.fromJdbcString(eleSqlType, sqlTypeName, literal.getValue2().toString()); } } if (newNode != null) { newerList.add(newNode); } newNode = null; } if (needChange) { rewriteProjects.set(idx, ((RexCall) rex).clone(arraySqlType, newerList)); logger.debug("Rewrite project REL {} for intersect count.", rewriteProjects.get(idx)); } } } }
Example 10
Source File: SplunkPushDownRule.java From calcite with Apache License 2.0 | 5 votes |
private String toString(boolean like, RexLiteral literal) { String value = null; SqlTypeName litSqlType = literal.getTypeName(); if (SqlTypeName.NUMERIC_TYPES.contains(litSqlType)) { value = literal.getValue().toString(); } else if (litSqlType == SqlTypeName.CHAR) { value = ((NlsString) literal.getValue()).getValue(); if (like) { value = value.replace("%", "*"); } value = searchEscape(value); } return value; }
Example 11
Source File: GeodeFilter.java From calcite with Apache License 2.0 | 5 votes |
private String quoteCharLiteral(RexLiteral literal) { String value = literalValue(literal); if (literal.getTypeName() == CHAR) { value = "'" + value + "'"; } return value; }