Search in sources :

Example 1 with SetOperation

use of org.apache.flink.table.operations.command.SetOperation in project flink by apache.

the class SetOperationParseStrategy method convert.

@Override
public Operation convert(String statement) {
    Matcher matcher = pattern.matcher(statement.trim());
    final List<String> operands = new ArrayList<>();
    if (matcher.find()) {
        if (matcher.group("key") != null) {
            operands.add(matcher.group("key"));
            operands.add(matcher.group("quotedVal") != null ? matcher.group("quotedVal") : matcher.group("val"));
        }
    }
    // only capture SET
    if (operands.isEmpty()) {
        return new SetOperation();
    } else if (operands.size() == 2) {
        return new SetOperation(operands.get(0), operands.get(1));
    } else {
        // impossible
        throw new TableException(String.format("Failed to convert the statement to SET operation: %s.", statement));
    }
}
Also used : SetOperation(org.apache.flink.table.operations.command.SetOperation) TableException(org.apache.flink.table.api.TableException) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 2 with SetOperation

use of org.apache.flink.table.operations.command.SetOperation in project flink by apache.

the class SqlToOperationConverterTest method testSet.

@Test
public void testSet() {
    Operation operation1 = parse("SET", SqlDialect.DEFAULT);
    assertThat(operation1).isInstanceOf(SetOperation.class);
    SetOperation setOperation1 = (SetOperation) operation1;
    assertThat(setOperation1.getKey()).isNotPresent();
    assertThat(setOperation1.getValue()).isNotPresent();
    Operation operation2 = parse("SET 'test-key' = 'test-value'", SqlDialect.DEFAULT);
    assertThat(operation2).isInstanceOf(SetOperation.class);
    SetOperation setOperation2 = (SetOperation) operation2;
    assertThat(setOperation2.getKey()).hasValue("test-key");
    assertThat(setOperation2.getValue()).hasValue("test-value");
}
Also used : EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) Test(org.junit.Test)

Aggregations

SetOperation (org.apache.flink.table.operations.command.SetOperation)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 TableException (org.apache.flink.table.api.TableException)1 BeginStatementSetOperation (org.apache.flink.table.operations.BeginStatementSetOperation)1 EndStatementSetOperation (org.apache.flink.table.operations.EndStatementSetOperation)1 ExplainOperation (org.apache.flink.table.operations.ExplainOperation)1 LoadModuleOperation (org.apache.flink.table.operations.LoadModuleOperation)1 Operation (org.apache.flink.table.operations.Operation)1 QueryOperation (org.apache.flink.table.operations.QueryOperation)1 ShowFunctionsOperation (org.apache.flink.table.operations.ShowFunctionsOperation)1 ShowModulesOperation (org.apache.flink.table.operations.ShowModulesOperation)1 SinkModifyOperation (org.apache.flink.table.operations.SinkModifyOperation)1 SourceQueryOperation (org.apache.flink.table.operations.SourceQueryOperation)1 StatementSetOperation (org.apache.flink.table.operations.StatementSetOperation)1 UnloadModuleOperation (org.apache.flink.table.operations.UnloadModuleOperation)1 UseCatalogOperation (org.apache.flink.table.operations.UseCatalogOperation)1 UseDatabaseOperation (org.apache.flink.table.operations.UseDatabaseOperation)1 UseModulesOperation (org.apache.flink.table.operations.UseModulesOperation)1 AddJarOperation (org.apache.flink.table.operations.command.AddJarOperation)1