org.apache.calcite.sql.SqlLiteral - java examples

Here are the examples of the java api org.apache.calcite.sql.SqlLiteral taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

72 Examples 7

19 View Complete Implementation : SqlSetApprox.java
Copyright Apache License 2.0
Author : dremio
/**
 * SQL node tree for <code>ALTER TABLE table_identifier <ENABLE|DISABLE> APPROXIMATE STATS</code>
 */
public clreplaced SqlSetApprox extends SqlSystemCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("ENABLE_APPROXIMATE_STATS", SqlKind.OTHER) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            return new SqlSetApprox(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1]);
        }
    };

    private SqlIdentifier table;

    private SqlLiteral enable;

    /**
     * Creates a SqlSetApprox.
     */
    public SqlSetApprox(SqlParserPos pos, SqlIdentifier table, SqlLiteral enable) {
        super(pos);
        this.table = table;
        this.enable = enable;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("ALTER");
        writer.keyword("TABLE");
        table.unparse(writer, leftPrec, rightPrec);
        if ((Boolean) enable.getValue()) {
            writer.keyword("ENABLE");
        } else {
            writer.keyword("DISABLE");
        }
        writer.keyword("APPROXIMATE");
        writer.keyword("STATS");
    }

    @Override
    public void setOperand(int i, SqlNode operand) {
        switch(i) {
            case 0:
                table = (SqlIdentifier) operand;
                break;
            case 1:
                enable = (SqlLiteral) operand;
                break;
            default:
                throw new replacedertionError(i);
        }
    }

    public boolean isEnable() {
        return (Boolean) enable.getValue();
    }

    public NamespaceKey getPath() {
        return new NamespaceKey(table.names);
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableNullableList.<SqlNode>of(table, enable);
    }

    public SqlIdentifier getTable() {
        return table;
    }
}

19 View Complete Implementation : SqlNodes.java
Copyright Apache License 2.0
Author : dremio
@Override
public Void visit(SqlLiteral literal) {
    return format(literal);
}

19 View Complete Implementation : SqlAbstractParserImpl.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a call.
 *
 * @param funName           Name of function
 * @param pos               Position in source code
 * @param funcType          Type of function
 * @param functionQualifier Qualifier
 * @param operands          Operands to call
 * @return Call
 */
protected SqlCall createCall(SqlIdentifier funName, SqlParserPos pos, SqlFunctionCategory funcType, SqlLiteral functionQualifier, Iterable<? extends SqlNode> operands) {
    return createCall(funName, pos, funcType, functionQualifier, Iterables.toArray(operands, SqlNode.clreplaced));
}

19 View Complete Implementation : SqlRefreshReflection.java
Copyright Apache License 2.0
Author : dremio
public clreplaced SqlRefreshReflection extends SqlCall implements SqlToPlanHandler.Creator {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("REFRESH_REFLECTION", SqlKind.OTHER) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 2, "SqlRefreshReflection.createCall() has to get 3 operands!");
            return new SqlRefreshReflection(pos, (SqlLiteral) operands[0], (SqlLiteral) operands[1]);
        }
    };

    private final SqlLiteral reflectionId;

    private final SqlLiteral materializationId;

    public SqlRefreshReflection(SqlParserPos pos, SqlNode reflectionId, SqlNode materializationId) {
        super(pos);
        this.reflectionId = (SqlLiteral) reflectionId;
        this.materializationId = (SqlLiteral) materializationId;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        List<SqlNode> ops = Lists.newArrayList();
        ops.add(reflectionId);
        ops.add(materializationId);
        return ops;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("REFRESH");
        writer.keyword("REFLECTION");
        reflectionId.unparse(writer, leftPrec, rightPrec);
        writer.keyword("AS");
        materializationId.unparse(writer, leftPrec, rightPrec);
    }

    public SqlParserPos getReflectionIdPos() {
        return reflectionId.getParserPosition();
    }

    public SqlParserPos getMaterializationIdPos() {
        return materializationId.getParserPosition();
    }

    public String getReflectionId() {
        return ((NlsString) reflectionId.getValue()).getValue();
    }

    public String getMaterializationId() {
        return ((NlsString) materializationId.getValue()).getValue();
    }

    @Override
    public SqlToPlanHandler toPlanHandler() {
        try {
            return (SqlToPlanHandler) Clreplaced.forName("com.dremio.service.reflection.refresh.RefreshHandler").newInstance();
        } catch (ReflectiveOperationException e) {
            throw Throwables.propagate(e);
        }
    }
}

19 View Complete Implementation : IdentifierWithGranularity.java
Copyright Apache License 2.0
Author : dremio
public clreplaced IdentifierWithGranularity extends SqlIdentifier {

    private final SqlLiteral byDay;

    public IdentifierWithGranularity(SqlIdentifier identifier, SqlLiteral byDay, SqlParserPos pos) {
        super(identifier.names, pos);
        this.byDay = byDay;
    }

    public boolean getByDay() {
        return byDay.booleanValue();
    }
}

19 View Complete Implementation : SqlMetastoreAnalyzeTable.java
Copyright Apache License 2.0
Author : apache
public clreplaced SqlMetastorereplacedyzeTable extends DrillSqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("METASTORE_replacedYZE_TABLE", SqlKind.OTHER_DDL) {

        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            return new SqlMetastorereplacedyzeTable(pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1], operands[2], (SqlLiteral) operands[3], (SqlNumerireplacederal) operands[4]);
        }
    };

    private final SqlIdentifier tableName;

    private final SqlNodeList fieldList;

    private final SqlLiteral level;

    private final SqlLiteral estimate;

    private final SqlNumerireplacederal samplePercent;

    public SqlMetastorereplacedyzeTable(SqlParserPos pos, SqlIdentifier tableName, SqlNodeList fieldList, SqlNode level, SqlLiteral estimate, SqlNumerireplacederal samplePercent) {
        super(pos);
        this.tableName = tableName;
        this.fieldList = fieldList;
        this.level = level != null ? SqlLiteral.unchain(level) : null;
        this.estimate = estimate;
        this.samplePercent = samplePercent;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return Arrays.asList(tableName, fieldList, level, estimate, samplePercent);
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("replacedYZE");
        writer.keyword("TABLE");
        tableName.unparse(writer, leftPrec, rightPrec);
        if (fieldList != null) {
            writer.keyword("COLUMNS");
            if (fieldList.size() > 0) {
                writer.keyword("(");
                fieldList.get(0).unparse(writer, leftPrec, rightPrec);
                for (int i = 1; i < fieldList.size(); i++) {
                    writer.keyword(",");
                    fieldList.get(i).unparse(writer, leftPrec, rightPrec);
                }
                writer.keyword(")");
            } else {
                writer.keyword("NONE");
            }
        }
        writer.keyword("REFRESH");
        writer.keyword("METADATA");
        if (level != null) {
            level.unparse(writer, leftPrec, rightPrec);
        }
        if (estimate != null) {
            writer.keyword(estimate.booleanValue() ? "ESTIMATE" : "COMPUTE");
            writer.keyword("STATISTICS");
        }
        if (samplePercent != null) {
            writer.keyword("SAMPLE");
            samplePercent.unparse(writer, leftPrec, rightPrec);
            writer.keyword("PERCENT");
        }
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config, Pointer<String> textPlan) {
        return new MetastorereplacedyzeTableHandler(config, textPlan);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
        return getSqlHandler(config, null);
    }

    public List<String> getSchemaPath() {
        if (tableName.isSimple()) {
            return Collections.emptyList();
        }
        return tableName.names.subList(0, tableName.names.size() - 1);
    }

    public SqlIdentifier getTableIdentifier() {
        return tableName;
    }

    public String getName() {
        return Util.last(tableName.names);
    }

    public List<SchemaPath> getFieldNames() {
        if (fieldList == null) {
            return null;
        }
        return fieldList.getList().stream().map(SqlNode::toString).map(SchemaPath::parseFromString).collect(Collectors.toList());
    }

    public SqlNodeList getFieldList() {
        return fieldList;
    }

    public SqlLiteral getLevel() {
        return level;
    }

    public SqlLiteral getEstimate() {
        return estimate;
    }

    public SqlNumerireplacederal getSamplePercent() {
        return samplePercent;
    }
}

19 View Complete Implementation : ExpressionGenerator.java
Copyright Apache License 2.0
Author : hortonworks
@Override
public Expression visit(SqlLiteral literal) {
    return new Literal(literal.toString());
}

19 View Complete Implementation : SqlAbstractParserImpl.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a call.
 *
 * @param funName           Name of function
 * @param pos               Position in source code
 * @param funcType          Type of function
 * @param functionQualifier Qualifier
 * @param operands          Operands to call
 * @return Call
 */
protected SqlCall createCall(SqlIdentifier funName, SqlParserPos pos, SqlFunctionCategory funcType, SqlLiteral functionQualifier, SqlNode[] operands) {
    // Create a placeholder function.  Later, during
    // validation, it will be resolved into a real function reference.
    SqlOperator fun = new SqlUnresolvedFunction(funName, null, null, null, null, funcType);
    return fun.createCall(functionQualifier, pos, operands);
}

19 View Complete Implementation : BaseSqlVisitor.java
Copyright Apache License 2.0
Author : dremio
@Override
public T visit(SqlLiteral lit) {
    throw new UnsupportedOperationException("SqlLiteral " + lit);
}

19 View Complete Implementation : SqlJsonObjectFunction.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    if (operands[0] == null) {
        operands[0] = SqlLiteral.createSymbol(SqlJsonConstructorNullClause.NULL_ON_NULL, pos);
    }
    return super.createCall(functionQualifier, pos, operands);
}

19 View Complete Implementation : SqlCreateTable.java
Copyright Apache License 2.0
Author : dremio
public clreplaced SqlCreateTable extends SqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_TABLE", SqlKind.CREATE_TABLE) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 9, "SqlCreateTable.createCall() has to get 9 operands!");
            return new SqlCreateTable(pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1], ((SqlLiteral) operands[2]).symbolValue(ParreplacedionDistributionStrategy.clreplaced), (SqlNodeList) operands[3], (SqlNodeList) operands[4], (SqlLiteral) operands[5], operands[6], (SqlNodeList) operands[7], (SqlNodeList) operands[8]);
        }
    };

    private final SqlIdentifier tblName;

    private final SqlNodeList fieldList;

    private final ParreplacedionDistributionStrategy parreplacedionDistributionStrategy;

    private final SqlNodeList parreplacedionColumns;

    private final SqlNodeList sortColumns;

    private final SqlNodeList distributionColumns;

    private final SqlNodeList formatOptions;

    private final SqlLiteral singleWriter;

    private final SqlNode query;

    public SqlCreateTable(SqlParserPos pos, SqlIdentifier tblName, SqlNodeList fieldList, ParreplacedionDistributionStrategy parreplacedionDistributionStrategy, SqlNodeList parreplacedionColumns, SqlNodeList formatOptions, SqlLiteral singleWriter, SqlNode query, SqlNodeList sortFieldList, SqlNodeList distributionColumns) {
        super(pos);
        this.tblName = tblName;
        this.fieldList = fieldList;
        this.parreplacedionDistributionStrategy = parreplacedionDistributionStrategy;
        this.parreplacedionColumns = parreplacedionColumns;
        this.formatOptions = formatOptions;
        this.singleWriter = singleWriter;
        this.query = query;
        this.sortColumns = sortFieldList;
        this.distributionColumns = distributionColumns;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        List<SqlNode> ops = Lists.newArrayList();
        ops.add(tblName);
        ops.add(fieldList);
        ops.add(SqlLiteral.createSymbol(parreplacedionDistributionStrategy, SqlParserPos.ZERO));
        ops.add(parreplacedionColumns);
        ops.add(formatOptions);
        ops.add(singleWriter);
        ops.add(query);
        ops.add(sortColumns);
        ops.add(distributionColumns);
        return ops;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("CREATE");
        writer.keyword("TABLE");
        tblName.unparse(writer, leftPrec, rightPrec);
        if (fieldList.size() > 0) {
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, fieldList);
        }
        if (parreplacedionColumns.size() > 0) {
            switch(parreplacedionDistributionStrategy) {
                case UNSPECIFIED:
                    break;
                case HASH:
                    writer.keyword("HASH");
                    break;
                case ROUND_ROBIN:
                    writer.keyword("ROUNDROBIN");
                    break;
                case STRIPED:
                    writer.keyword("STRIPED");
                    break;
            }
            writer.keyword("PARreplacedION");
            writer.keyword("BY");
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, parreplacedionColumns);
        }
        if (distributionColumns.size() > 0) {
            writer.keyword("DISTRIBUTE");
            writer.keyword("BY");
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, distributionColumns);
        }
        if (sortColumns.size() > 0) {
            writer.keyword("LOCALSORT");
            writer.keyword("BY");
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, sortColumns);
        }
        if (formatOptions.size() > 0) {
            writer.keyword("STORE");
            writer.keyword("AS");
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, formatOptions);
        }
        if (singleWriter.booleanValue()) {
            writer.keyword("WITH");
            writer.keyword("SINGLE");
            writer.keyword("WRITER");
        }
        writer.keyword("AS");
        query.unparse(writer, leftPrec, rightPrec);
    }

    public NamespaceKey getPath() {
        return new NamespaceKey(tblName.names);
    }

    public List<String> getFieldNames() {
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : fieldList.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public List<String> getSortColumns() {
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : sortColumns.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public List<String> getDistributionColumns() {
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : distributionColumns.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public List<String> getParreplacedionColumns() {
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : parreplacedionColumns.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public SqlNodeList getFormatOptions() {
        return formatOptions;
    }

    public boolean isSingleWriter() {
        return singleWriter.booleanValue();
    }

    public SqlNode getQuery() {
        return query;
    }

    public ParreplacedionDistributionStrategy getParreplacedionDistributionStrategy() {
        return parreplacedionDistributionStrategy;
    }
}

19 View Complete Implementation : SqlAccelToggle.java
Copyright Apache License 2.0
Author : dremio
public clreplaced SqlAccelToggle extends SqlSystemCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("ACCEL_TOGGLE", SqlKind.OTHER_DDL) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 3, "SqlAccelToggle.createCall() has to get 3 operands!");
            return new SqlAccelToggle(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1], (SqlLiteral) operands[2]);
        }
    };

    private final SqlIdentifier tblName;

    private final SqlLiteral raw;

    private final SqlLiteral enable;

    public SqlAccelToggle(SqlParserPos pos, SqlIdentifier tblName, SqlLiteral raw, SqlLiteral enable) {
        super(pos);
        this.tblName = tblName;
        this.raw = raw;
        this.enable = enable;
    }

    public SqlIdentifier getTblName() {
        return tblName;
    }

    public boolean isRaw() {
        return raw.booleanValue();
    }

    public boolean isEnable() {
        return enable.booleanValue();
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableList.<SqlNode>of(tblName, raw, enable);
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }
}

19 View Complete Implementation : SqlAnalyzeTable.java
Copyright Apache License 2.0
Author : apache
/**
 * SQL tree for replacedYZE statement.
 */
public clreplaced SqlreplacedyzeTable extends DrillSqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("replacedYZE_TABLE", SqlKind.OTHER_DDL) {

        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 4, "SqlreplacedyzeTable.createCall() has to get 4 operands!");
            return new SqlreplacedyzeTable(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1], (SqlNodeList) operands[2], (SqlNumerireplacederal) operands[3]);
        }
    };

    private final SqlIdentifier tblName;

    private final SqlLiteral estimate;

    private final SqlNodeList fieldList;

    private final SqlNumerireplacederal samplePercent;

    public SqlreplacedyzeTable(SqlParserPos pos, SqlIdentifier tblName, SqlLiteral estimate, SqlNodeList fieldList, SqlNumerireplacederal samplePercent) {
        super(pos);
        this.tblName = tblName;
        this.estimate = estimate;
        this.fieldList = fieldList;
        this.samplePercent = samplePercent;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        final List<SqlNode> operands = Lists.newArrayListWithCapacity(4);
        operands.add(tblName);
        operands.add(estimate);
        operands.add(fieldList);
        operands.add(samplePercent);
        return operands;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("replacedYZE");
        writer.keyword("TABLE");
        tblName.unparse(writer, leftPrec, rightPrec);
        writer.keyword(estimate.booleanValue() ? "ESTIMATE" : "COMPUTE");
        writer.keyword("STATISTICS");
        if (fieldList != null && fieldList.size() > 0) {
            writer.keyword("(");
            fieldList.get(0).unparse(writer, leftPrec, rightPrec);
            for (int i = 1; i < fieldList.size(); i++) {
                writer.keyword(",");
                fieldList.get(i).unparse(writer, leftPrec, rightPrec);
            }
            writer.keyword(")");
        }
        writer.keyword("SAMPLE");
        samplePercent.unparse(writer, leftPrec, rightPrec);
        writer.keyword("PERCENT");
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config, Pointer<String> textPlan) {
        return new replacedyzeTableHandler(config, textPlan);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
        return getSqlHandler(config, null);
    }

    public List<String> getSchemaPath() {
        if (tblName.isSimple()) {
            return ImmutableList.of();
        }
        return tblName.names.subList(0, tblName.names.size() - 1);
    }

    public SqlIdentifier getTableIdentifier() {
        return tblName;
    }

    public String getName() {
        return Util.last(tblName.names);
    }

    public List<String> getFieldNames() {
        if (fieldList == null) {
            return ImmutableList.of();
        }
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : fieldList.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public SqlNodeList getFieldList() {
        return fieldList;
    }

    public boolean getEstimate() {
        return estimate.booleanValue();
    }

    public int getSamplePercent() {
        return samplePercent.intValue(true);
    }
}

19 View Complete Implementation : SqlRefreshTable.java
Copyright Apache License 2.0
Author : dremio
/**
 * SQL node tree for <code>FORGET TABLE table_identifier </code>
 */
public clreplaced SqlRefreshTable extends SqlSystemCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("REFRESH_TABLE", SqlKind.OTHER) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            return new SqlRefreshTable(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1], (SqlLiteral) operands[2], (SqlLiteral) operands[3]);
        }
    };

    private SqlIdentifier table;

    private SqlLiteral deleteUnavail;

    private SqlLiteral forceUp;

    private SqlLiteral promotion;

    /**
     * Creates a SqlForgetTable.
     */
    public SqlRefreshTable(SqlParserPos pos, SqlIdentifier table, SqlLiteral deleteUnavail, SqlLiteral forceUp, SqlLiteral promotion) {
        super(pos);
        this.table = table;
        this.deleteUnavail = deleteUnavail;
        this.forceUp = forceUp;
        this.promotion = promotion;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("ALTER");
        writer.keyword("TABLE");
        table.unparse(writer, leftPrec, rightPrec);
        writer.keyword("REFRESH");
        writer.keyword("METADATA");
        if (deleteUnavail.getValue() != null) {
            if (deleteUnavail.booleanValue()) {
                writer.keyword("DELETE");
                writer.keyword("WHEN");
                writer.keyword("MISSING");
            } else {
                writer.keyword("MAINTAIN");
                writer.keyword("WHEN");
                writer.keyword("MISSING");
            }
        }
        if (forceUp.getValue() != null) {
            if (forceUp.booleanValue()) {
                writer.keyword("FORCE");
                writer.keyword("UPDATE");
            } else {
                writer.keyword("LAZY");
                writer.keyword("UPDATE");
            }
        }
        if (promotion.getValue() != null) {
            if (promotion.booleanValue()) {
                writer.keyword("AUTO");
                writer.keyword("PROMOTION");
            } else {
                writer.keyword("AVOID");
                writer.keyword("PROMOTION");
            }
        }
    }

    @Override
    public void setOperand(int i, SqlNode operand) {
        switch(i) {
            case 0:
                table = (SqlIdentifier) operand;
                break;
            case 1:
                deleteUnavail = (SqlLiteral) operand;
                break;
            case 2:
                forceUp = (SqlLiteral) operand;
                break;
            case 3:
                promotion = (SqlLiteral) operand;
                break;
            default:
                throw new replacedertionError(i);
        }
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableNullableList.<SqlNode>of(table, deleteUnavail, forceUp, promotion);
    }

    public SqlIdentifier getTable() {
        return table;
    }

    public SqlLiteral getDeleteUnavail() {
        return deleteUnavail;
    }

    public SqlLiteral getForceUpdate() {
        return forceUp;
    }

    public SqlLiteral getPromotion() {
        return promotion;
    }
}

19 View Complete Implementation : SqlJsonValueFunction.java
Copyright Apache License 2.0
Author : apache
private boolean isDefaultLiteral(SqlLiteral literal) {
    return literal.getValueAs(SqlJsonValueEmptyOrErrorBehavior.clreplaced) == SqlJsonValueEmptyOrErrorBehavior.DEFAULT;
}

19 View Complete Implementation : AncestorsVisitor.java
Copyright Apache License 2.0
Author : dremio
@Override
public List<SqlIdentifier> visit(SqlLiteral literal) {
    return Collections.emptyList();
}

19 View Complete Implementation : SqlRefreshMetadata.java
Copyright Apache License 2.0
Author : apache
/**
 * Sql parse tree node to represent statement:
 * REFRESH TABLE METADATA tblname
 */
public clreplaced SqlRefreshMetadata extends DrillSqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("REFRESH_TABLE_METADATA", SqlKind.OTHER_DDL) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            return new SqlRefreshMetadata(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1], (SqlNodeList) operands[2]);
        }
    };

    private SqlIdentifier tblName;

    private final SqlLiteral allColumns;

    private final SqlNodeList fieldList;

    public SqlRefreshMetadata(SqlParserPos pos, SqlIdentifier tblName, SqlLiteral allColumns, SqlNodeList fieldList) {
        super(pos);
        this.tblName = tblName;
        this.allColumns = allColumns;
        this.fieldList = fieldList;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        List<SqlNode> ops = Lists.newArrayList();
        ops.add(tblName);
        ops.add(allColumns);
        ops.add(fieldList);
        return ops;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("REFRESH");
        writer.keyword("TABLE");
        writer.keyword("METADATA");
        if (!allColumns.booleanValue()) {
            writer.keyword("COLUMNS");
            if (fieldList == null) {
                writer.keyword("NONE");
            } else if (fieldList != null && fieldList.size() > 0) {
                writer.keyword("(");
                fieldList.get(0).unparse(writer, leftPrec, rightPrec);
                for (int i = 1; i < fieldList.size(); i++) {
                    writer.keyword(",");
                    fieldList.get(i).unparse(writer, leftPrec, rightPrec);
                }
                writer.keyword(")");
            }
        }
        tblName.unparse(writer, leftPrec, rightPrec);
    }

    public String getName() {
        if (tblName.isSimple()) {
            return tblName.getSimple();
        }
        return tblName.names.get(tblName.names.size() - 1);
    }

    public List<String> getSchemaPath() {
        if (tblName.isSimple()) {
            return ImmutableList.of();
        }
        return tblName.names.subList(0, tblName.names.size() - 1);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
        return new RefreshMetadataHandler(config);
    }

    public SqlNodeList getFieldList() {
        return fieldList;
    }

    public SqlLiteral getAllColumns() {
        return allColumns;
    }
}

19 View Complete Implementation : SqlAnalyzeTable.java
Copyright Apache License 2.0
Author : lealone
/**
 * SQL tree for replacedYZE statement.
 */
public clreplaced SqlreplacedyzeTable extends DrillSqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("replacedYZE_TABLE", SqlKind.OTHER) {

        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 4, "SqlreplacedyzeTable.createCall() has to get 4 operands!");
            return new SqlreplacedyzeTable(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1], (SqlNodeList) operands[2], (SqlNumerireplacederal) operands[3]);
        }
    };

    private final SqlIdentifier tblName;

    private final SqlLiteral estimate;

    private final SqlNodeList fieldList;

    private final SqlNumerireplacederal samplePercent;

    public SqlreplacedyzeTable(SqlParserPos pos, SqlIdentifier tblName, SqlLiteral estimate, SqlNodeList fieldList, SqlNumerireplacederal samplePercent) {
        super(pos);
        this.tblName = tblName;
        this.estimate = estimate;
        this.fieldList = fieldList;
        this.samplePercent = samplePercent;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        final List<SqlNode> operands = Lists.newArrayListWithCapacity(4);
        operands.add(tblName);
        operands.add(estimate);
        operands.add(fieldList);
        operands.add(samplePercent);
        return operands;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("replacedYZE");
        writer.keyword("TABLE");
        tblName.unparse(writer, leftPrec, rightPrec);
        writer.keyword(estimate.booleanValue() ? "ESTIMATE" : "COMPUTE");
        writer.keyword("STATISTICS");
        if (fieldList != null && fieldList.size() > 0) {
            writer.keyword("(");
            fieldList.get(0).unparse(writer, leftPrec, rightPrec);
            for (int i = 1; i < fieldList.size(); i++) {
                writer.keyword(",");
                fieldList.get(i).unparse(writer, leftPrec, rightPrec);
            }
            writer.keyword(")");
        }
        writer.keyword("SAMPLE");
        samplePercent.unparse(writer, leftPrec, rightPrec);
        writer.keyword("PERCENT");
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config, Pointer<String> textPlan) {
        return new replacedyzeTableHandler(config, textPlan);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
        return getSqlHandler(config, null);
    }

    public List<String> getSchemaPath() {
        if (tblName.isSimple()) {
            return ImmutableList.of();
        }
        return tblName.names.subList(0, tblName.names.size() - 1);
    }

    public SqlIdentifier getTableIdentifier() {
        return tblName;
    }

    public String getName() {
        return Util.last(tblName.names);
    }

    public List<String> getFieldNames() {
        if (fieldList == null) {
            return ImmutableList.of();
        }
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : fieldList.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public SqlNodeList getFieldList() {
        return fieldList;
    }

    public boolean getEstimate() {
        return estimate.booleanValue();
    }

    public int getSamplePercent() {
        return samplePercent.intValue(true);
    }
}

19 View Complete Implementation : SqlBasicVisitor.java
Copyright Apache License 2.0
Author : apache
// ~ Methods ----------------------------------------------------------------
public R visit(SqlLiteral literal) {
    return null;
}

19 View Complete Implementation : SqlJsonValueFunction.java
Copyright Apache License 2.0
Author : apache
private void unparseEnum(SqlWriter writer, SqlLiteral literal) {
    writer.keyword(((Enum) literal.getValue()).name());
}

19 View Complete Implementation : SqlShuttle.java
Copyright Apache License 2.0
Author : apache
// ~ Methods ----------------------------------------------------------------
public SqlNode visit(SqlLiteral literal) {
    return literal;
}

19 View Complete Implementation : SqlCompactMaterialization.java
Copyright Apache License 2.0
Author : dremio
public clreplaced SqlCompactMaterialization extends SqlCall implements SqlToPlanHandler.Creator {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("COMPACT_MATERIALIZATION", SqlKind.OTHER) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 2, "SqlCompactRefresh.createCall() has to get 2 operands!");
            return new SqlCompactMaterialization(pos, operands[0], operands[1]);
        }
    };

    private SqlIdentifier materializationPath;

    private SqlLiteral newMaterializationId;

    public SqlCompactMaterialization(SqlParserPos pos, SqlNode materializationPath, SqlNode newMaterializationPath) {
        super(pos);
        this.materializationPath = (SqlIdentifier) materializationPath;
        this.newMaterializationId = (SqlLiteral) newMaterializationPath;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableList.of(materializationPath, newMaterializationId);
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("COMPACT");
        writer.keyword("REFRESH");
        materializationPath.unparse(writer, leftPrec, rightPrec);
        writer.keyword("AS");
        newMaterializationId.unparse(writer, leftPrec, rightPrec);
    }

    public List<String> getMaterializationPath() {
        return materializationPath.names;
    }

    public String getNewMaterializationId() {
        return newMaterializationId.toValue();
    }

    @Override
    public SqlToPlanHandler toPlanHandler() {
        try {
            return (SqlToPlanHandler) Clreplaced.forName("com.dremio.service.reflection.compact.CompactRefreshHandler").newInstance();
        } catch (ReflectiveOperationException e) {
            throw Throwables.propagate(e);
        }
    }
}

18 View Complete Implementation : SqlJsonQueryFunction.java
Copyright Apache License 2.0
Author : lealone
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    if (operands[1] == null) {
        operands[1] = SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITHOUT_ARRAY, pos);
    }
    if (operands[2] == null) {
        operands[2] = SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, pos);
    }
    if (operands[3] == null) {
        operands[3] = SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, pos);
    }
    return super.createCall(functionQualifier, pos, operands);
}

18 View Complete Implementation : SqlCaseOperator.java
Copyright Apache License 2.0
Author : apache
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    replacedert functionQualifier == null;
    replacedert operands.length == 4;
    return new SqlCase(pos, operands[0], (SqlNodeList) operands[1], (SqlNodeList) operands[2], operands[3]);
}

18 View Complete Implementation : SqlJsonArrayFunction.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    if (operands[0] == null) {
        operands[0] = SqlLiteral.createSymbol(SqlJsonConstructorNullClause.ABSENT_ON_NULL, pos);
    }
    return super.createCall(functionQualifier, pos, operands);
}

18 View Complete Implementation : SqlJsonDepthFunction.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    return super.createCall(functionQualifier, pos, operands);
}

18 View Complete Implementation : SqlJsonQueryFunction.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    if (operands[2] == null) {
        operands[2] = SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITHOUT_ARRAY, pos);
    }
    if (operands[3] == null) {
        operands[3] = SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, pos);
    }
    if (operands[4] == null) {
        operands[4] = SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, pos);
    }
    return super.createCall(functionQualifier, pos, operands);
}

18 View Complete Implementation : SqlPosixRegexOperator.java
Copyright Apache License 2.0
Author : apache
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    pos = pos.plusAll(Arrays.asList(operands));
    operands = Arrays.copyOf(operands, operands.length + 1);
    operands[operands.length - 1] = SqlLiteral.createBoolean(caseSensitive, SqlParserPos.ZERO);
    return new SqlBasicCall(this, operands, pos, false, functionQualifier);
}

18 View Complete Implementation : DrillCalciteSqlOperatorWrapper.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    return operator.createCall(functionQualifier, pos, operands);
}

18 View Complete Implementation : SqlCreateTable.java
Copyright Apache License 2.0
Author : apache
public clreplaced SqlCreateTable extends DrillSqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_TABLE", SqlKind.CREATE_TABLE) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            Preconditions.checkArgument(operands.length == 6, "SqlCreateTable.createCall() has to get 6 operands!");
            return new SqlCreateTable(pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1], (SqlNodeList) operands[2], operands[3], (SqlLiteral) operands[4], (SqlLiteral) operands[5]);
        }
    };

    private final SqlIdentifier tblName;

    private final SqlNodeList fieldList;

    private final SqlNodeList parreplacedionColumns;

    private final SqlNode query;

    private final SqlLiteral isTemporary;

    private final SqlLiteral tableNonExistenceCheck;

    public SqlCreateTable(SqlParserPos pos, SqlIdentifier tblName, SqlNodeList fieldList, SqlNodeList parreplacedionColumns, SqlNode query, SqlLiteral isTemporary, SqlLiteral tableNonExistenceCheck) {
        super(pos);
        this.tblName = tblName;
        this.fieldList = fieldList;
        this.parreplacedionColumns = parreplacedionColumns;
        this.query = query;
        this.isTemporary = isTemporary;
        this.tableNonExistenceCheck = tableNonExistenceCheck;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        List<SqlNode> ops = Lists.newArrayList();
        ops.add(tblName);
        ops.add(fieldList);
        ops.add(parreplacedionColumns);
        ops.add(query);
        ops.add(isTemporary);
        ops.add(tableNonExistenceCheck);
        return ops;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("CREATE");
        if (isTemporary.booleanValue()) {
            writer.keyword("TEMPORARY");
        }
        writer.keyword("TABLE");
        if (tableNonExistenceCheck.booleanValue()) {
            writer.keyword("IF");
            writer.keyword("NOT");
            writer.keyword("EXISTS");
        }
        tblName.unparse(writer, leftPrec, rightPrec);
        if (fieldList.size() > 0) {
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, fieldList);
        }
        if (parreplacedionColumns.size() > 0) {
            writer.keyword("PARreplacedION BY");
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, parreplacedionColumns);
        }
        writer.keyword("AS");
        query.unparse(writer, leftPrec, rightPrec);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
        return getSqlHandler(config, null);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config, Pointer<String> textPlan) {
        replacedert textPlan != null : "Create table statement should have a plan";
        return new CreateTableHandler(config, textPlan);
    }

    public List<String> getSchemaPath() {
        if (tblName.isSimple()) {
            return ImmutableList.of();
        }
        return tblName.names.subList(0, tblName.names.size() - 1);
    }

    public String getName() {
        if (tblName.isSimple()) {
            return tblName.getSimple();
        }
        return tblName.names.get(tblName.names.size() - 1);
    }

    public List<String> getFieldNames() {
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : fieldList.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public List<String> getParreplacedionColumns() {
        List<String> columnNames = Lists.newArrayList();
        for (SqlNode node : parreplacedionColumns.getList()) {
            columnNames.add(node.toString());
        }
        return columnNames;
    }

    public SqlNode getQuery() {
        return query;
    }

    public boolean isTemporary() {
        return isTemporary.booleanValue();
    }

    public boolean checkTableNonExistence() {
        return tableNonExistenceCheck.booleanValue();
    }
}

18 View Complete Implementation : SqlCreateView.java
Copyright Apache License 2.0
Author : apache
public clreplaced SqlCreateView extends DrillSqlCall {

    public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_VIEW", SqlKind.CREATE_VIEW) {

        @Override
        public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
            return new SqlCreateView(pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1], operands[2], (SqlLiteral) operands[3]);
        }
    };

    private SqlIdentifier viewName;

    private SqlNodeList fieldList;

    private SqlNode query;

    private SqlLiteral createType;

    public SqlCreateView(SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList, SqlNode query, SqlLiteral createType) {
        super(pos);
        this.viewName = viewName;
        this.query = query;
        this.fieldList = fieldList;
        this.createType = createType;
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        List<SqlNode> ops = Lists.newArrayList();
        ops.add(viewName);
        ops.add(fieldList);
        ops.add(query);
        ops.add(createType);
        return ops;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("CREATE");
        switch(SqlCreateType.valueOf(createType.toValue())) {
            case SIMPLE:
                writer.keyword("VIEW");
                break;
            case OR_REPLACE:
                writer.keyword("OR");
                writer.keyword("REPLACE");
                writer.keyword("VIEW");
                break;
            case IF_NOT_EXISTS:
                writer.keyword("VIEW");
                writer.keyword("IF");
                writer.keyword("NOT");
                writer.keyword("EXISTS");
                break;
        }
        viewName.unparse(writer, leftPrec, rightPrec);
        if (fieldList.size() > 0) {
            SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, fieldList);
        }
        writer.keyword("AS");
        query.unparse(writer, leftPrec, rightPrec);
    }

    @Override
    public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
        return new ViewHandler.CreateView(config);
    }

    public List<String> getSchemaPath() {
        if (viewName.isSimple()) {
            return ImmutableList.of();
        }
        return viewName.names.subList(0, viewName.names.size() - 1);
    }

    public String getName() {
        if (viewName.isSimple()) {
            return viewName.getSimple();
        }
        return viewName.names.get(viewName.names.size() - 1);
    }

    public List<String> getFieldNames() {
        List<String> fieldNames = Lists.newArrayList();
        for (SqlNode node : fieldList.getList()) {
            fieldNames.add(node.toString());
        }
        return fieldNames;
    }

    public SqlNode getQuery() {
        return query;
    }

    public SqlCreateType getSqlCreateType() {
        return SqlCreateType.valueOf(createType.toValue());
    }
}

18 View Complete Implementation : MssqlSqlDialect.java
Copyright Apache License 2.0
Author : lealone
/**
 * 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);
    }
}

17 View Complete Implementation : SqlJsonArrayAggAggFunction.java
Copyright Apache License 2.0
Author : apache
private SqlCall createCall_(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode valueExpr) {
    return super.createCall(functionQualifier, pos, valueExpr);
}

17 View Complete Implementation : SqlTrimFunction.java
Copyright Apache License 2.0
Author : apache
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    replacedert functionQualifier == null;
    switch(operands.length) {
        case 1:
            // This variant occurs when someone writes TRIM(string)
            // as opposed to the sugared syntax TRIM(string FROM string).
            operands = new SqlNode[] { Flag.BOTH.symbol(SqlParserPos.ZERO), SqlLiteral.createCharString(" ", pos), operands[0] };
            break;
        case 3:
            replacedert operands[0] instanceof SqlLiteral && ((SqlLiteral) operands[0]).getValue() instanceof Flag;
            if (operands[1] == null) {
                operands[1] = SqlLiteral.createCharString(" ", pos);
            }
            break;
        default:
            throw new IllegalArgumentException("invalid operand count " + Arrays.toString(operands));
    }
    return super.createCall(functionQualifier, pos, operands);
}

17 View Complete Implementation : DrillConvertletTable.java
Copyright Apache License 2.0
Author : apache
private static SqlRexConvertlet timestampDiffConvertlet() {
    return (cx, call) -> {
        SqlLiteral unitLiteral = call.operand(0);
        SqlIntervalQualifier qualifier = new SqlIntervalQualifier(unitLiteral.symbolValue(TimeUnit.clreplaced), null, SqlParserPos.ZERO);
        List<RexNode> operands = Arrays.asList(cx.convertExpression(qualifier), cx.convertExpression(call.operand(1)), cx.convertExpression(call.operand(2)));
        RelDataTypeFactory typeFactory = cx.getTypeFactory();
        RelDataType returnType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), cx.getValidator().getValidatedNodeType(call.operand(1)).isNullable() || cx.getValidator().getValidatedNodeType(call.operand(2)).isNullable());
        return cx.getRexBuilder().makeCall(returnType, SqlStdOperatorTable.TIMESTAMP_DIFF, operands);
    };
}

17 View Complete Implementation : ExplainHandler.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
    SqlExplain node = unwrap(sqlNode, SqlExplain.clreplaced);
    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);
}

17 View Complete Implementation : MetastoreAnalyzeTableHandler.java
Copyright Apache License 2.0
Author : apache
private MetadataType getMetadataType(SqlMetastorereplacedyzeTable sqlreplacedyzeTable) {
    SqlLiteral stringLiteral = sqlreplacedyzeTable.getLevel();
    // for the case when metadata level is not specified in replacedYZE statement,
    // value from the `metastore.metadata.store.depth_level` option is used
    String metadataLevel;
    if (stringLiteral == null) {
        metadataLevel = context.getOption(ExecConstants.METASTORE_METADATA_STORE_DEPTH_LEVEL).string_val;
    } else {
        metadataLevel = stringLiteral.toValue();
    }
    return metadataLevel != null ? MetadataType.valueOf(metadataLevel.toUpperCase()) : MetadataType.ALL;
}

17 View Complete Implementation : IdentifierWithMeasures.java
Copyright Apache License 2.0
Author : dremio
public final List<MeasureType> getMeasureTypes() {
    try {
        List<MeasureType> measures = new ArrayList<>();
        for (SqlNode n : this.measures.getList()) {
            SqlLiteral l = SqlNodeUtil.unwrap(n, SqlLiteral.clreplaced);
            measures.add((MeasureType) l.getValue());
        }
        return measures;
    } catch (ForemanSetupException e) {
        throw Throwables.propagate(e);
    }
}

17 View Complete Implementation : SqlAbstractParserImpl.java
Copyright Apache License 2.0
Author : lealone
/**
 * Creates a call.
 *
 * @param funName           Name of function
 * @param pos               Position in source code
 * @param funcType          Type of function
 * @param functionQualifier Qualifier
 * @param operands          Operands to call
 * @return Call
 */
protected SqlCall createCall(SqlIdentifier funName, SqlParserPos pos, SqlFunctionCategory funcType, SqlLiteral functionQualifier, SqlNode[] operands) {
    SqlOperator fun = null;
    // First, try a half-hearted resolution as a builtin function.
    // If we find one, use it; this will guarantee that we
    // preserve the correct syntax (i.e. don't quote builtin function
    // / name when regenerating SQL).
    if (funName.isSimple()) {
        final List<SqlOperator> list = new ArrayList<>();
        opTab.lookupOperatorOverloads(funName, funcType, SqlSyntax.FUNCTION, list);
        if (list.size() == 1) {
            fun = list.get(0);
        }
    }
    // Otherwise, just create a placeholder function.  Later, during
    // validation, it will be resolved into a real function reference.
    if (fun == null) {
        fun = new SqlUnresolvedFunction(funName, null, null, null, null, funcType);
    }
    return fun.createCall(functionQualifier, pos, operands);
}

16 View Complete Implementation : BigQuerySqlDialect.java
Copyright Apache License 2.0
Author : apache
/**
 * For usage of TRIM, LTRIM and RTRIM in BQ see
 * <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#trim">
 *  BQ Trim Function</a>.
 */
private void unparseTrim(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
    final String operatorName;
    SqlLiteral trimFlag = call.operand(0);
    SqlLiteral valueToTrim = call.operand(1);
    switch(trimFlag.getValueAs(SqlTrimFunction.Flag.clreplaced)) {
        case LEADING:
            operatorName = "LTRIM";
            break;
        case TRAILING:
            operatorName = "RTRIM";
            break;
        default:
            operatorName = call.getOperator().getName();
            break;
    }
    final SqlWriter.Frame trimFrame = writer.startFunCall(operatorName);
    call.operand(2).unparse(writer, leftPrec, rightPrec);
    // If the trimmed character is a non-space character, add it to the target SQL.
    // eg: TRIM(BOTH 'A' from 'ABCD'
    // Output Query: TRIM('ABC', 'A')
    if (!valueToTrim.toValue().matches("\\s+")) {
        writer.literal(",");
        call.operand(1).unparse(writer, leftPrec, rightPrec);
    }
    writer.endFunCall(trimFrame);
}

16 View Complete Implementation : MysqlSqlDialect.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlNode rewriteSingleValueExpr(SqlNode aggCall) {
    final SqlNode operand = ((SqlBasicCall) aggCall).operand(0);
    final SqlLiteral nullLiteral = SqlLiteral.createNull(SqlParserPos.ZERO);
    final SqlNode unionOperand = new SqlSelect(SqlParserPos.ZERO, SqlNodeList.EMPTY, SqlNodeList.of(nullLiteral), null, null, null, null, SqlNodeList.EMPTY, null, null, null, SqlNodeList.EMPTY);
    // For MySQL, generate
    // CASE COUNT(*)
    // WHEN 0 THEN NULL
    // WHEN 1 THEN <result>
    // ELSE (SELECT NULL UNION ALL SELECT NULL)
    // END
    final SqlNode caseExpr = new SqlCase(SqlParserPos.ZERO, SqlStdOperatorTable.COUNT.createCall(SqlParserPos.ZERO, operand), SqlNodeList.of(SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO), SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO)), SqlNodeList.of(nullLiteral, operand), SqlStdOperatorTable.SCALAR_QUERY.createCall(SqlParserPos.ZERO, SqlStdOperatorTable.UNION_ALL.createCall(SqlParserPos.ZERO, unionOperand, unionOperand)));
    LOGGER.debug("SINGLE_VALUE rewritten into [{}]", caseExpr);
    return caseExpr;
}

16 View Complete Implementation : SetOptionHandler.java
Copyright Apache License 2.0
Author : lealone
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 replacedigning literals of type %s in SET statements.", typeName).build(logger);
    }
}

16 View Complete Implementation : MysqlSqlDialect.java
Copyright Apache License 2.0
Author : lealone
@Override
public SqlNode rewriteSingleValueExpr(SqlNode aggCall) {
    final SqlNode operand = ((SqlBasicCall) aggCall).operand(0);
    final SqlLiteral nullLiteral = SqlLiteral.createNull(SqlParserPos.ZERO);
    final SqlNode unionOperand = new SqlSelect(SqlParserPos.ZERO, SqlNodeList.EMPTY, SqlNodeList.of(nullLiteral), null, null, null, null, SqlNodeList.EMPTY, null, null, null);
    // For MySQL, generate
    // CASE COUNT(*)
    // WHEN 0 THEN NULL
    // WHEN 1 THEN <result>
    // ELSE (SELECT NULL UNION ALL SELECT NULL)
    // END
    final SqlNode caseExpr = new SqlCase(SqlParserPos.ZERO, SqlStdOperatorTable.COUNT.createCall(SqlParserPos.ZERO, operand), SqlNodeList.of(SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO), SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO)), SqlNodeList.of(nullLiteral, operand), SqlStdOperatorTable.SCALAR_QUERY.createCall(SqlParserPos.ZERO, SqlStdOperatorTable.UNION_ALL.createCall(SqlParserPos.ZERO, unionOperand, unionOperand)));
    LOGGER.debug("SINGLE_VALUE rewritten into [{}]", caseExpr);
    return caseExpr;
}

15 View Complete Implementation : HsqldbSqlDialect.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlNode rewriteSingleValueExpr(SqlNode aggCall) {
    final SqlNode operand = ((SqlBasicCall) aggCall).operand(0);
    final SqlLiteral nullLiteral = SqlLiteral.createNull(SqlParserPos.ZERO);
    final SqlNode unionOperand = SqlStdOperatorTable.VALUES.createCall(SqlParserPos.ZERO, SqlLiteral.createApproxNumeric("0", SqlParserPos.ZERO));
    // For hsqldb, generate
    // CASE COUNT(*)
    // WHEN 0 THEN NULL
    // WHEN 1 THEN MIN(<result>)
    // ELSE (VALUES 1 UNION ALL VALUES 1)
    // END
    final SqlNode caseExpr = new SqlCase(SqlParserPos.ZERO, SqlStdOperatorTable.COUNT.createCall(SqlParserPos.ZERO, operand), SqlNodeList.of(SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO), SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO)), SqlNodeList.of(nullLiteral, SqlStdOperatorTable.MIN.createCall(SqlParserPos.ZERO, operand)), SqlStdOperatorTable.SCALAR_QUERY.createCall(SqlParserPos.ZERO, SqlStdOperatorTable.UNION_ALL.createCall(SqlParserPos.ZERO, unionOperand, unionOperand)));
    LOGGER.debug("SINGLE_VALUE rewritten into [{}]", caseExpr);
    return caseExpr;
}

15 View Complete Implementation : SqlJsonArrayAggAggFunction.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
    replacedert operands.length == 1 || operands.length == 2;
    final SqlNode valueExpr = operands[0];
    if (operands.length == 2) {
        final SqlNode orderList = operands[1];
        if (orderList != null) {
            // call has an order by clause, e.g. json_arrayagg(col_1 order by col_1)
            return SqlStdOperatorTable.WITHIN_GROUP.createCall(SqlParserPos.ZERO, createCall_(functionQualifier, pos, valueExpr), orderList);
        }
    }
    return createCall_(functionQualifier, pos, valueExpr);
}

15 View Complete Implementation : SqlLimitsTest.java
Copyright Apache License 2.0
Author : apache
private void printLimit(PrintWriter pw, String desc, RelDataType type, boolean sign, SqlTypeName.Limit limit, boolean beyond) {
    Object o = ((BasicSqlType) type).getLimit(sign, limit, beyond);
    if (o == null) {
        return;
    }
    pw.print(desc);
    String s;
    if (o instanceof byte[]) {
        int k = 0;
        StringBuilder buf = new StringBuilder("{");
        for (byte b : (byte[]) o) {
            if (k++ > 0) {
                buf.append(", ");
            }
            buf.append(Integer.toHexString(b & 0xff));
        }
        buf.append("}");
        s = buf.toString();
    } else if (o instanceof Calendar) {
        Calendar calendar = (Calendar) o;
        DateFormat dateFormat = getDateFormat(type.getSqlTypeName());
        dateFormat.setTimeZone(DateTimeUtils.UTC_ZONE);
        s = dateFormat.format(calendar.getTime());
    } else {
        s = o.toString();
    }
    pw.print(s);
    SqlLiteral literal = type.getSqlTypeName().createLiteral(o, SqlParserPos.ZERO);
    pw.print("; as SQL: ");
    pw.print(literal.toSqlString(AnsiSqlDialect.DEFAULT));
    pw.println();
}

15 View Complete Implementation : SetOptionHandler.java
Copyright Apache License 2.0
Author : apache
private static Object sqlLiteralToObject(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();
        case BOOLEAN:
            return object;
        default:
            throw UserException.validationError().message("Drill doesn't support replacedigning literals of type %s in SET statements.", typeName).build(logger);
    }
}

15 View Complete Implementation : CallBindingCallContext.java
Copyright Apache License 2.0
Author : apache
@Override
public <T> Optional<T> getArgumentValue(int pos, Clreplaced<T> clazz) {
    try {
        final SqlLiteral literal = SqlLiteral.unchain(adaptedArguments.get(pos));
        return Optional.ofNullable(getLiteralValueAs(literal::getValueAs, clazz));
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}

15 View Complete Implementation : SetOptionHandler.java
Copyright Apache License 2.0
Author : dremio
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 replacedigning literals of type %s in SET statements.", typeName).build(logger);
    }
}

15 View Complete Implementation : SqlLiteralChainOperator.java
Copyright Apache License 2.0
Author : lealone
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.replacedql(true, false));
            } else {
                // print without prefix
                writer.literal(nls.replacedql(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);
}