Search in sources :

Example 6 with SqlCreateUserCommand

use of org.apache.ignite.internal.sql.command.SqlCreateUserCommand in project ignite by apache.

the class IgniteH2Indexing method tryQueryDistributedSqlFieldsNative.

/**
 * Try executing query using native facilities.
 *
 * @param schemaName Schema name.
 * @param sql Query.
 * @param cliCtx Client context, or {@code null} if not applicable.
 * @return Result or {@code null} if cannot parse/process this query.
 */
private List<FieldsQueryCursor<List<?>>> tryQueryDistributedSqlFieldsNative(String schemaName, String sql, @Nullable SqlClientContext cliCtx) {
    // Heuristic check for fast return.
    if (!INTERNAL_CMD_RE.matcher(sql.trim()).find())
        return null;
    // Parse.
    SqlCommand cmd;
    try {
        SqlParser parser = new SqlParser(schemaName, sql);
        cmd = parser.nextCommand();
        // No support for multiple commands for now.
        if (parser.nextCommand() != null)
            return null;
        // CREATE/ALTER/DROP USER
        if (!(cmd instanceof SqlCreateIndexCommand || cmd instanceof SqlDropIndexCommand || cmd instanceof SqlAlterTableCommand || cmd instanceof SqlBulkLoadCommand || cmd instanceof SqlSetStreamingCommand || cmd instanceof SqlCreateUserCommand || cmd instanceof SqlAlterUserCommand || cmd instanceof SqlDropUserCommand))
            return null;
    } catch (Exception e) {
        // Cannot parse, return.
        if (log.isDebugEnabled())
            log.debug("Failed to parse SQL with native parser [qry=" + sql + ", err=" + e + ']');
        if (!IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_SQL_PARSER_DISABLE_H2_FALLBACK))
            return null;
        int code = IgniteQueryErrorCode.PARSING;
        if (e instanceof SqlParseException)
            code = ((SqlParseException) e).code();
        throw new IgniteSQLException("Failed to parse DDL statement: " + sql + ": " + e.getMessage(), code, e);
    }
    // Execute.
    if (cmd instanceof SqlBulkLoadCommand) {
        FieldsQueryCursor<List<?>> cursor = dmlProc.runNativeDmlStatement(sql, cmd);
        return Collections.singletonList(cursor);
    } else if (cmd instanceof SqlSetStreamingCommand) {
        if (cliCtx == null)
            throw new IgniteSQLException("SET STREAMING command can only be executed from JDBC or ODBC driver.");
        SqlSetStreamingCommand setCmd = (SqlSetStreamingCommand) cmd;
        boolean on = setCmd.isTurnOn();
        if (on)
            cliCtx.enableStreaming(setCmd.allowOverwrite(), setCmd.flushFrequency(), setCmd.perNodeBufferSize(), setCmd.perNodeParallelOperations());
        else
            cliCtx.disableStreaming();
        return Collections.singletonList(H2Utils.zeroCursor());
    } else {
        try {
            FieldsQueryCursor<List<?>> cursor = ddlProc.runDdlStatement(sql, cmd);
            return Collections.singletonList(cursor);
        } catch (IgniteCheckedException e) {
            throw new IgniteSQLException("Failed to execute DDL statement [stmt=" + sql + "]: " + e.getMessage(), e);
        }
    }
}
Also used : SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) SqlParser(org.apache.ignite.internal.sql.SqlParser) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) ArrayList(java.util.ArrayList) List(java.util.List) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand)

Aggregations

SqlCreateUserCommand (org.apache.ignite.internal.sql.command.SqlCreateUserCommand)6 SqlCreateIndexCommand (org.apache.ignite.internal.sql.command.SqlCreateIndexCommand)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)4 SqlAlterTableCommand (org.apache.ignite.internal.sql.command.SqlAlterTableCommand)4 SqlAlterUserCommand (org.apache.ignite.internal.sql.command.SqlAlterUserCommand)4 SqlDropIndexCommand (org.apache.ignite.internal.sql.command.SqlDropIndexCommand)4 SqlDropUserCommand (org.apache.ignite.internal.sql.command.SqlDropUserCommand)4 SqlCommand (org.apache.ignite.internal.sql.command.SqlCommand)3 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 IgniteCluster (org.apache.ignite.IgniteCluster)2 QueryIndex (org.apache.ignite.cache.QueryIndex)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)2 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)2 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)2 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)2 SqlParseException (org.apache.ignite.internal.sql.SqlParseException)2 SqlParser (org.apache.ignite.internal.sql.SqlParser)2