Search in sources :

Example 1 with SqlSetStreamingCommand

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

the class JdbcThinConnection method executeNative.

/**
 * @param sql Statement.
 * @param cmd Parsed form of {@code sql}.
 * @throws SQLException if failed.
 */
void executeNative(String sql, SqlCommand cmd) throws SQLException {
    if (cmd instanceof SqlSetStreamingCommand) {
        // If streaming is already on, we have to disable it first.
        if (stream) {
            // We have to send request regardless of actual batch size.
            executeBatch(true);
            stream = false;
        }
        boolean newVal = ((SqlSetStreamingCommand) cmd).isTurnOn();
        // Actual ON, if needed.
        if (newVal) {
            sendRequest(new JdbcQueryExecuteRequest(JdbcStatementType.ANY_STATEMENT_TYPE, schema, 1, 1, sql, null));
            streamBatchSize = ((SqlSetStreamingCommand) cmd).batchSize();
            stream = true;
        }
    } else
        throw IgniteQueryErrorCode.createJdbcSqlException("Unsupported native statement: " + sql, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
Also used : JdbcQueryExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand)

Example 2 with SqlSetStreamingCommand

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

the class JdbcThinConnection method executeNative.

/**
 * @param sql Statement.
 * @param cmd Parsed form of {@code sql}.
 * @param stmt Jdbc thin statement.
 * @throws SQLException if failed.
 */
void executeNative(String sql, SqlCommand cmd, JdbcThinStatement stmt) throws SQLException {
    if (cmd instanceof SqlSetStreamingCommand) {
        SqlSetStreamingCommand cmd0 = (SqlSetStreamingCommand) cmd;
        // If streaming is already on, we have to close it first.
        if (streamState != null) {
            streamState.close();
            streamState = null;
        }
        boolean newVal = ((SqlSetStreamingCommand) cmd).isTurnOn();
        ensureConnected();
        JdbcThinTcpIo cliIo = cliIo(null);
        // Actual ON, if needed.
        if (newVal) {
            if (!cmd0.isOrdered() && !cliIo.isUnorderedStreamSupported()) {
                throw new SQLException("Streaming without order doesn't supported by server [remoteNodeVer=" + cliIo.igniteVersion() + ']', INTERNAL_ERROR);
            }
            streamState = new StreamState((SqlSetStreamingCommand) cmd, cliIo);
            sendRequest(new JdbcQueryExecuteRequest(JdbcStatementType.ANY_STATEMENT_TYPE, schema, 1, 1, autoCommit, stmt.explicitTimeout, sql, null), stmt, cliIo);
            streamState.start();
        }
    } else
        throw IgniteQueryErrorCode.createJdbcSqlException("Unsupported native statement: " + sql, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
Also used : JdbcQueryExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest) SQLException(java.sql.SQLException) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand)

Example 3 with SqlSetStreamingCommand

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

the class SqlParserSetStreamingSelfTest method parseValidate.

/**
 * Parse and validate SQL script.
 *
 * @param sql SQL.
 * @param expOn Expected on/off value.
 * @param expAllowOverwrite Expected allow overwrite flag.
 * @param expBatchSize Expected batch size.
 * @param expParOps Expected per-node parallael operations.
 * @param expBufSize Expected per node buffer size.
 * @param expFlushFreq Expected flush frequency.
 * @param ordered Ordered stream flag.
 */
private static void parseValidate(String sql, boolean expOn, boolean expAllowOverwrite, int expBatchSize, int expParOps, int expBufSize, long expFlushFreq, boolean ordered) {
    SqlSetStreamingCommand cmd = (SqlSetStreamingCommand) new SqlParser(QueryUtils.DFLT_SCHEMA, sql).nextCommand();
    assertEquals(expOn, cmd.isTurnOn());
    assertEquals(expAllowOverwrite, cmd.allowOverwrite());
    assertEquals(expBatchSize, cmd.batchSize());
    assertEquals(expParOps, cmd.perNodeParallelOperations());
    assertEquals(expBufSize, cmd.perNodeBufferSize());
    assertEquals(expFlushFreq, cmd.flushFrequency());
    assertEquals(ordered, cmd.isOrdered());
}
Also used : SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand)

Example 4 with SqlSetStreamingCommand

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

the class QueryParser method parseNative.

/**
 * Tries to parse sql query text using native parser. Only first (leading) sql command of the multi-statement is
 * actually parsed.
 *
 * @param schemaName Schema name.
 * @param qry which sql text to parse.
 * @param remainingAllowed Whether multiple statements are allowed.
 * @return Command or {@code null} if cannot parse this query.
 */
@SuppressWarnings("IfMayBeConditional")
@Nullable
private QueryParserResult parseNative(String schemaName, SqlFieldsQuery qry, boolean remainingAllowed) {
    String sql = qry.getSql();
    // Heuristic check for fast return.
    if (!INTERNAL_CMD_RE.matcher(sql.trim()).find())
        return null;
    try {
        SqlParser parser = new SqlParser(schemaName, sql);
        SqlCommand nativeCmd = parser.nextCommand();
        assert nativeCmd != null : "Empty query. Parser met end of data";
        if (!(nativeCmd instanceof SqlCreateIndexCommand || nativeCmd instanceof SqlDropIndexCommand || nativeCmd instanceof SqlBeginTransactionCommand || nativeCmd instanceof SqlCommitTransactionCommand || nativeCmd instanceof SqlRollbackTransactionCommand || nativeCmd instanceof SqlBulkLoadCommand || nativeCmd instanceof SqlAlterTableCommand || nativeCmd instanceof SqlSetStreamingCommand || nativeCmd instanceof SqlCreateUserCommand || nativeCmd instanceof SqlAlterUserCommand || nativeCmd instanceof SqlDropUserCommand || nativeCmd instanceof SqlKillQueryCommand || nativeCmd instanceof SqlKillComputeTaskCommand || nativeCmd instanceof SqlKillServiceCommand || nativeCmd instanceof SqlKillTransactionCommand || nativeCmd instanceof SqlKillScanQueryCommand || nativeCmd instanceof SqlKillContinuousQueryCommand || nativeCmd instanceof SqlAnalyzeCommand || nativeCmd instanceof SqlRefreshStatitsicsCommand || nativeCmd instanceof SqlDropStatisticsCommand))
            return null;
        SqlFieldsQuery newQry = cloneFieldsQuery(qry).setSql(parser.lastCommandSql());
        QueryDescriptor newPlanKey = queryDescriptor(schemaName, newQry);
        SqlFieldsQuery remainingQry = null;
        if (!F.isEmpty(parser.remainingSql())) {
            checkRemainingAllowed(remainingAllowed);
            remainingQry = cloneFieldsQuery(qry).setSql(parser.remainingSql()).setArgs(qry.getArgs());
        }
        QueryParserResultCommand cmd = new QueryParserResultCommand(nativeCmd, null, false);
        return new QueryParserResult(newPlanKey, queryParameters(newQry), remainingQry, // Currently none of native statements supports parameters.
        Collections.emptyList(), null, null, cmd);
    } catch (SqlStrictParseException e) {
        throw new IgniteSQLException(e.getMessage(), e.errorCode(), e);
    } 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);
    }
}
Also used : SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) SqlStrictParseException(org.apache.ignite.internal.sql.SqlStrictParseException) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) SqlKillContinuousQueryCommand(org.apache.ignite.internal.sql.command.SqlKillContinuousQueryCommand) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand) SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) SqlKillScanQueryCommand(org.apache.ignite.internal.sql.command.SqlKillScanQueryCommand) SqlAnalyzeCommand(org.apache.ignite.internal.sql.command.SqlAnalyzeCommand) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) SqlDropStatisticsCommand(org.apache.ignite.internal.sql.command.SqlDropStatisticsCommand) SqlParser(org.apache.ignite.internal.sql.SqlParser) SqlKillComputeTaskCommand(org.apache.ignite.internal.sql.command.SqlKillComputeTaskCommand) SqlRefreshStatitsicsCommand(org.apache.ignite.internal.sql.command.SqlRefreshStatitsicsCommand) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlStrictParseException(org.apache.ignite.internal.sql.SqlStrictParseException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) SqlKillTransactionCommand(org.apache.ignite.internal.sql.command.SqlKillTransactionCommand) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) SqlKillServiceCommand(org.apache.ignite.internal.sql.command.SqlKillServiceCommand) SqlKillQueryCommand(org.apache.ignite.internal.sql.command.SqlKillQueryCommand) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SqlBeginTransactionCommand(org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with SqlSetStreamingCommand

use of org.apache.ignite.internal.sql.command.SqlSetStreamingCommand 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

SqlSetStreamingCommand (org.apache.ignite.internal.sql.command.SqlSetStreamingCommand)5 SQLException (java.sql.SQLException)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 JdbcQueryExecuteRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest)2 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)2 SqlParseException (org.apache.ignite.internal.sql.SqlParseException)2 SqlParser (org.apache.ignite.internal.sql.SqlParser)2 SqlAlterTableCommand (org.apache.ignite.internal.sql.command.SqlAlterTableCommand)2 SqlAlterUserCommand (org.apache.ignite.internal.sql.command.SqlAlterUserCommand)2 SqlBulkLoadCommand (org.apache.ignite.internal.sql.command.SqlBulkLoadCommand)2 SqlCommand (org.apache.ignite.internal.sql.command.SqlCommand)2 SqlCreateIndexCommand (org.apache.ignite.internal.sql.command.SqlCreateIndexCommand)2 SqlCreateUserCommand (org.apache.ignite.internal.sql.command.SqlCreateUserCommand)2 SqlDropIndexCommand (org.apache.ignite.internal.sql.command.SqlDropIndexCommand)2 SqlDropUserCommand (org.apache.ignite.internal.sql.command.SqlDropUserCommand)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CacheException (javax.cache.CacheException)1 IgniteException (org.apache.ignite.IgniteException)1 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)1