Search in sources :

Example 6 with SqlCharStringLiteral

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlCharStringLiteral in project flink by apache.

the class SqlAddHivePartitions method toProps.

private static List<SqlNodeList> toProps(List<SqlCharStringLiteral> partLocations) {
    List<SqlNodeList> res = new ArrayList<>(partLocations.size());
    for (SqlCharStringLiteral partLocation : partLocations) {
        SqlNodeList prop = null;
        if (partLocation != null) {
            prop = new SqlNodeList(partLocation.getParserPosition());
            prop.add(HiveDDLUtils.toTableOption(SqlCreateHiveTable.TABLE_LOCATION_URI, partLocation, partLocation.getParserPosition()));
        }
        res.add(prop);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlCharStringLiteral(org.apache.calcite.sql.SqlCharStringLiteral)

Example 7 with SqlCharStringLiteral

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlCharStringLiteral in project flink by apache.

the class SqlCreateHiveTable method unparseRowFormat.

private void unparseRowFormat(SqlWriter writer, int leftPrec, int rightPrec) {
    if (rowFormat == null) {
        return;
    }
    writer.newlineAndIndent();
    writer.keyword("ROW FORMAT");
    if (rowFormat.serdeClass != null) {
        writer.keyword("SERDE");
        rowFormat.serdeClass.unparse(writer, leftPrec, rightPrec);
        if (rowFormat.serdeProps != null) {
            writer.keyword("WITH SERDEPROPERTIES");
            unparsePropList(rowFormat.serdeProps, writer, leftPrec, rightPrec);
        }
    } else {
        writer.keyword("DELIMITED");
        SqlCharStringLiteral fieldDelim = rowFormat.delimitPropToValue.get(HiveTableRowFormat.FIELD_DELIM);
        SqlCharStringLiteral escape = rowFormat.delimitPropToValue.get(HiveTableRowFormat.ESCAPE_CHAR);
        if (fieldDelim != null) {
            writer.newlineAndIndent();
            writer.print("  ");
            writer.keyword("FIELDS TERMINATED BY");
            fieldDelim.unparse(writer, leftPrec, rightPrec);
            if (escape != null) {
                writer.keyword("ESCAPED BY");
                escape.unparse(writer, leftPrec, rightPrec);
            }
        }
        SqlCharStringLiteral collectionDelim = rowFormat.delimitPropToValue.get(HiveTableRowFormat.COLLECTION_DELIM);
        if (collectionDelim != null) {
            writer.newlineAndIndent();
            writer.print("  ");
            writer.keyword("COLLECTION ITEMS TERMINATED BY");
            collectionDelim.unparse(writer, leftPrec, rightPrec);
        }
        SqlCharStringLiteral mapKeyDelim = rowFormat.delimitPropToValue.get(HiveTableRowFormat.MAPKEY_DELIM);
        if (mapKeyDelim != null) {
            writer.newlineAndIndent();
            writer.print("  ");
            writer.keyword("MAP KEYS TERMINATED BY");
            mapKeyDelim.unparse(writer, leftPrec, rightPrec);
        }
        SqlCharStringLiteral lineDelim = rowFormat.delimitPropToValue.get(HiveTableRowFormat.LINE_DELIM);
        if (lineDelim != null) {
            writer.newlineAndIndent();
            writer.print("  ");
            writer.keyword("LINES TERMINATED BY");
            lineDelim.unparse(writer, leftPrec, rightPrec);
        }
        SqlCharStringLiteral nullAs = rowFormat.delimitPropToValue.get(HiveTableRowFormat.SERIALIZATION_NULL_FORMAT);
        if (nullAs != null) {
            writer.newlineAndIndent();
            writer.print("  ");
            writer.keyword("NULL DEFINED AS");
            nullAs.unparse(writer, leftPrec, rightPrec);
        }
    }
}
Also used : SqlCharStringLiteral(org.apache.calcite.sql.SqlCharStringLiteral)

Example 8 with SqlCharStringLiteral

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlCharStringLiteral in project calcite by apache.

the class SqlLiteralChainOperator method unparse.

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);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) BitString(org.apache.calcite.util.BitString) SqlCollation(org.apache.calcite.sql.SqlCollation) NlsString(org.apache.calcite.util.NlsString) SqlCharStringLiteral(org.apache.calcite.sql.SqlCharStringLiteral) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlNode(org.apache.calcite.sql.SqlNode)

Example 9 with SqlCharStringLiteral

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

the class ShowSchemasHandler method rewrite.

/**
 * Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.SCHEMATA ...
 */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws ForemanSetupException {
    SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class);
    List<SqlNode> selectList = Collections.singletonList(new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO));
    SqlNode fromClause = new SqlIdentifier(Arrays.asList(IS_SCHEMA_NAME, InfoSchemaTableType.SCHEMATA.name()), SqlParserPos.ZERO);
    SqlNode where = null;
    SqlNode likePattern = node.getLikePattern();
    if (likePattern != null) {
        SqlNode column = new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO);
        // schema names are case insensitive, wrap column in lower function, pattern to lower case
        if (likePattern instanceof SqlCharStringLiteral) {
            NlsString conditionString = ((SqlCharStringLiteral) likePattern).getNlsString();
            likePattern = SqlCharStringLiteral.createCharString(conditionString.getValue().toLowerCase(), conditionString.getCharsetName(), likePattern.getParserPosition());
            column = SqlStdOperatorTable.LOWER.createCall(SqlParserPos.ZERO, column);
        }
        where = DrillParserUtil.createCondition(column, SqlStdOperatorTable.LIKE, likePattern);
    } else if (node.getWhereClause() != null) {
        where = node.getWhereClause();
    }
    return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO), fromClause, where, null, null, null, null, null, null);
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlShowSchemas(org.apache.drill.exec.planner.sql.parser.SqlShowSchemas) NlsString(org.apache.calcite.util.NlsString) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlCharStringLiteral(org.apache.calcite.sql.SqlCharStringLiteral) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 10 with SqlCharStringLiteral

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

the class DropFunctionHandler method getPlan.

/**
 * Unregisters UDFs dynamically. Process consists of several steps:
 * <ol>
 * <li>Registering jar in jar registry to ensure that several jars with the same name is not being unregistered.</li>
 * <li>Starts remote unregistration process, gets list of all jars and excludes jar to be deleted.</li>
 * <li>Signals drill bits to start local unregistration process.</li>
 * <li>Removes source and binary jars from registry area.</li>
 * </ol>
 *
 * UDFs unregistration is allowed only if dynamic UDFs support is enabled.
 * Only jars registered dynamically can be unregistered,
 * built-in functions loaded at start up are not allowed to be unregistered.
 *
 * Limitation: before jar unregistration make sure no one is using functions from this jar.
 * There is no guarantee that running queries will finish successfully or give correct result.
 *
 * @return - Single row indicating list of unregistered UDFs, raise exception otherwise
 */
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
    if (!context.getOption(ExecConstants.DYNAMIC_UDF_SUPPORT_ENABLED).bool_val) {
        throw UserException.validationError().message("Dynamic UDFs support is disabled.").build(logger);
    }
    SqlDropFunction node = unwrap(sqlNode, SqlDropFunction.class);
    String jarName = ((SqlCharStringLiteral) node.getJar()).toValue();
    RemoteFunctionRegistry remoteFunctionRegistry = context.getRemoteFunctionRegistry();
    boolean inProgress = false;
    try {
        final String action = remoteFunctionRegistry.addToJars(jarName, RemoteFunctionRegistry.Action.UNREGISTRATION);
        if (!(inProgress = action == null)) {
            return DirectPlan.createDirectPlan(context, false, String.format("Jar with %s name is used. Action: %s", jarName, action));
        }
        Jar deletedJar = unregister(jarName, remoteFunctionRegistry);
        if (deletedJar == null) {
            return DirectPlan.createDirectPlan(context, false, String.format("Jar %s is not registered in remote registry", jarName));
        }
        remoteFunctionRegistry.submitForUnregistration(jarName);
        removeJarFromArea(jarName, remoteFunctionRegistry.getFs(), remoteFunctionRegistry.getRegistryArea());
        removeJarFromArea(JarUtil.getSourceName(jarName), remoteFunctionRegistry.getFs(), remoteFunctionRegistry.getRegistryArea());
        return DirectPlan.createDirectPlan(context, true, String.format("The following UDFs in jar %s have been unregistered:\n%s", jarName, deletedJar.getFunctionSignatureList()));
    } catch (Exception e) {
        logger.error("Error during UDF unregistration", e);
        return DirectPlan.createDirectPlan(context, false, e.getMessage());
    } finally {
        if (inProgress) {
            remoteFunctionRegistry.finishUnregistration(jarName);
            remoteFunctionRegistry.removeFromJars(jarName);
        }
    }
}
Also used : RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) Jar(org.apache.drill.exec.proto.UserBitShared.Jar) SqlCharStringLiteral(org.apache.calcite.sql.SqlCharStringLiteral) UserException(org.apache.drill.common.exceptions.UserException) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) SqlDropFunction(org.apache.drill.exec.planner.sql.parser.SqlDropFunction)

Aggregations

SqlCharStringLiteral (org.apache.calcite.sql.SqlCharStringLiteral)10 SqlNode (org.apache.calcite.sql.SqlNode)5 SqlNodeList (org.apache.calcite.sql.SqlNodeList)5 NlsString (org.apache.calcite.util.NlsString)4 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)3 SqlSelect (org.apache.calcite.sql.SqlSelect)3 UserException (org.apache.drill.common.exceptions.UserException)3 ForemanSetupException (org.apache.drill.exec.work.foreman.ForemanSetupException)3 IOException (java.io.IOException)2 SchemaPlus (org.apache.calcite.schema.SchemaPlus)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)2 RemoteFunctionRegistry (org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry)2 SqlDropFunction (org.apache.drill.exec.planner.sql.parser.SqlDropFunction)2 Jar (org.apache.drill.exec.proto.UserBitShared.Jar)2 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)2 AggregateFunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression)1 ArrayFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression)1 AsExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.AsExpression)1 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)1