Search in sources :

Example 21 with SqlParserPos

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project hive by apache.

the class RexNodeExprFactory method createIntervalDayConstantExpr.

/**
 * {@inheritDoc}
 */
@Override
protected RexLiteral createIntervalDayConstantExpr(String value) {
    HiveIntervalDayTime v = new HiveIntervalDayTime(Integer.parseInt(value), 0, 0, 0, 0);
    BigDecimal secsValueBd = BigDecimal.valueOf(v.getTotalSeconds() * 1000);
    BigDecimal nanosValueBd = BigDecimal.valueOf((v).getNanos(), 6);
    return rexBuilder.makeIntervalLiteral(secsValueBd.add(nanosValueBd), new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, new SqlParserPos(1, 1)));
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) HiveIntervalDayTime(org.apache.hadoop.hive.common.type.HiveIntervalDayTime) BigDecimal(java.math.BigDecimal)

Example 22 with SqlParserPos

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project hive by apache.

the class RexNodeExprFactory method createIntervalYearConstantExpr.

/**
 * {@inheritDoc}
 */
@Override
protected RexLiteral createIntervalYearConstantExpr(String value) {
    HiveIntervalYearMonth v = new HiveIntervalYearMonth(Integer.parseInt(value), 0);
    BigDecimal totalMonths = BigDecimal.valueOf(v.getTotalMonths());
    return rexBuilder.makeIntervalLiteral(totalMonths, new SqlIntervalQualifier(TimeUnit.YEAR, TimeUnit.MONTH, new SqlParserPos(1, 1)));
}
Also used : HiveIntervalYearMonth(org.apache.hadoop.hive.common.type.HiveIntervalYearMonth) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) BigDecimal(java.math.BigDecimal)

Example 23 with SqlParserPos

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project hive by apache.

the class RexNodeExprFactory method createIntervalMinuteConstantExpr.

/**
 * {@inheritDoc}
 */
@Override
protected RexLiteral createIntervalMinuteConstantExpr(String value) {
    HiveIntervalDayTime v = new HiveIntervalDayTime(0, 0, Integer.parseInt(value), 0, 0);
    BigDecimal secsValueBd = BigDecimal.valueOf(v.getTotalSeconds() * 1000);
    BigDecimal nanosValueBd = BigDecimal.valueOf((v).getNanos(), 6);
    return rexBuilder.makeIntervalLiteral(secsValueBd.add(nanosValueBd), new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, new SqlParserPos(1, 1)));
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) HiveIntervalDayTime(org.apache.hadoop.hive.common.type.HiveIntervalDayTime) BigDecimal(java.math.BigDecimal)

Example 24 with SqlParserPos

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project drill by apache.

the class DrillAvgVarianceConvertlet method expandAvg.

private SqlNode expandAvg(final SqlNode arg) {
    final SqlParserPos pos = SqlParserPos.ZERO;
    final SqlNode sum = SqlStdOperatorTable.SUM.createCall(pos, arg);
    final SqlNode count = SqlStdOperatorTable.COUNT.createCall(pos, arg);
    final SqlNode sumAsDouble = CastHighOp.createCall(pos, sum);
    return SqlStdOperatorTable.DIVIDE.createCall(pos, sumAsDouble, count);
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlNode(org.apache.calcite.sql.SqlNode)

Example 25 with SqlParserPos

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project drill by apache.

the class TestDrillSQLWorker method testErrorFormating.

@Test
public void testErrorFormating() {
    String sql = "Select * from Foo\nwhere tadadidada;\n";
    validateFormattedIs(sql, new SqlParserPos(1, 2), "Select * from Foo\n" + " ^\n" + "where tadadidada;\n");
    validateFormattedIs(sql, new SqlParserPos(2, 2), "Select * from Foo\n" + "where tadadidada;\n" + " ^\n");
    validateFormattedIs(sql, new SqlParserPos(1, 10), "Select * from Foo\n" + "         ^\n" + "where tadadidada;\n");
    validateFormattedIs(sql, new SqlParserPos(-11, -10), sql);
    validateFormattedIs(sql, new SqlParserPos(0, 10), sql);
    validateFormattedIs(sql, new SqlParserPos(100, 10), sql);
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) Test(org.junit.Test)

Aggregations

SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)42 SqlNode (org.apache.calcite.sql.SqlNode)17 SqlIntervalQualifier (org.apache.calcite.sql.SqlIntervalQualifier)11 RelDataType (org.apache.calcite.rel.type.RelDataType)9 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)9 BigDecimal (java.math.BigDecimal)8 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)6 SqlCall (org.apache.calcite.sql.SqlCall)5 ArrayList (java.util.ArrayList)4 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)4 SqlNodeList (org.apache.calcite.sql.SqlNodeList)4 ImmutableList (com.google.common.collect.ImmutableList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 RexNode (org.apache.calcite.rex.RexNode)3 SqlNumericLiteral (org.apache.calcite.sql.SqlNumericLiteral)3 SqlOperator (org.apache.calcite.sql.SqlOperator)3 Calendar (java.util.Calendar)2 IdentityHashMap (java.util.IdentityHashMap)2 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)2