Search in sources :

Example 16 with TableEnvironmentInternal

use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project zeppelin by apache.

the class Flink112Shims method parseSql.

/**
 * Parse it via flink SqlParser first, then fallback to regular expression matching.
 *
 * @param tableEnv
 * @param stmt
 * @return
 */
@Override
public Optional<SqlCommandParser.SqlCommandCall> parseSql(Object tableEnv, String stmt) {
    Parser sqlParser = ((TableEnvironmentInternal) tableEnv).getParser();
    SqlCommandCall sqlCommandCall = null;
    try {
        // parse statement via regex matching first
        Optional<SqlCommandCall> callOpt = parseByRegexMatching(stmt);
        if (callOpt.isPresent()) {
            sqlCommandCall = callOpt.get();
        } else {
            sqlCommandCall = parseBySqlParser(sqlParser, stmt);
        }
    } catch (Exception e) {
        return Optional.empty();
    }
    return Optional.of(sqlCommandCall);
}
Also used : TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) SqlCommandCall(org.apache.zeppelin.flink.sql.SqlCommandParser.SqlCommandCall) FlinkException(org.apache.flink.util.FlinkException) TableException(org.apache.flink.table.api.TableException) IOException(java.io.IOException) SqlCommandParser(org.apache.zeppelin.flink.sql.SqlCommandParser) Parser(org.apache.flink.table.delegation.Parser)

Example 17 with TableEnvironmentInternal

use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project flink by apache.

the class LocalExecutor method parseStatement.

@Override
public Operation parseStatement(String sessionId, String statement) throws SqlExecutionException {
    final ExecutionContext context = getExecutionContext(sessionId);
    final TableEnvironment tableEnv = context.getTableEnvironment();
    Parser parser = ((TableEnvironmentInternal) tableEnv).getParser();
    List<Operation> operations;
    try {
        operations = context.wrapClassLoader(() -> parser.parse(statement));
    } catch (Exception e) {
        throw new SqlExecutionException("Failed to parse statement: " + statement, e);
    }
    if (operations.isEmpty()) {
        throw new SqlExecutionException("Failed to parse statement: " + statement);
    }
    return operations.get(0);
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) ExecutionContext(org.apache.flink.table.client.gateway.context.ExecutionContext) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) TableEnvironment(org.apache.flink.table.api.TableEnvironment) ModifyOperation(org.apache.flink.table.operations.ModifyOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) Operation(org.apache.flink.table.operations.Operation) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Parser(org.apache.flink.table.delegation.Parser)

Example 18 with TableEnvironmentInternal

use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project flink by apache.

the class LocalExecutor method executeModifyOperations.

@Override
public TableResultInternal executeModifyOperations(String sessionId, List<ModifyOperation> operations) throws SqlExecutionException {
    final ExecutionContext context = getExecutionContext(sessionId);
    final TableEnvironmentInternal tEnv = (TableEnvironmentInternal) context.getTableEnvironment();
    try {
        return context.wrapClassLoader(() -> tEnv.executeInternal(operations));
    } catch (Exception e) {
        throw new SqlExecutionException(MESSAGE_SQL_EXECUTION_ERROR, e);
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) ExecutionContext(org.apache.flink.table.client.gateway.context.ExecutionContext) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException)

Aggregations

TableEnvironmentInternal (org.apache.flink.table.api.internal.TableEnvironmentInternal)18 Parser (org.apache.flink.table.delegation.Parser)7 Test (org.junit.Test)5 TableEnvironment (org.apache.flink.table.api.TableEnvironment)4 CatalogTable (org.apache.flink.table.catalog.CatalogTable)4 ExecutionContext (org.apache.flink.table.client.gateway.context.ExecutionContext)4 IOException (java.io.IOException)3 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)3 Table (org.apache.flink.table.api.Table)3 TableException (org.apache.flink.table.api.TableException)3 TableResult (org.apache.flink.table.api.TableResult)3 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)3 HiveParser (org.apache.flink.table.planner.delegation.hive.HiveParser)3 Row (org.apache.flink.types.Row)3 ArrayList (java.util.ArrayList)2 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 StreamTableEnvironment (org.apache.flink.table.api.bridge.java.StreamTableEnvironment)2 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)2 CsvTableSink (org.apache.flink.table.sinks.CsvTableSink)2