use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project flink by apache.
the class LocalExecutor method completeStatement.
@Override
public List<String> completeStatement(String sessionId, String statement, int position) {
final ExecutionContext context = getExecutionContext(sessionId);
final TableEnvironmentInternal tableEnv = (TableEnvironmentInternal) context.getTableEnvironment();
try {
return context.wrapClassLoader(() -> Arrays.asList(tableEnv.getParser().getCompletionHints(statement, position)));
} catch (Throwable t) {
// catch everything such that the query does not crash the executor
if (LOG.isDebugEnabled()) {
LOG.debug("Could not complete statement at " + position + ":" + statement, t);
}
return Collections.emptyList();
}
}
use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project flink by apache.
the class BuiltInFunctionTestBase method testFunction.
@Test
public void testFunction() {
final TableEnvironment env = TableEnvironment.create(EnvironmentSettings.newInstance().build());
env.getConfig().addConfiguration(configuration());
testSpec.functions.forEach(f -> env.createTemporarySystemFunction(f.getSimpleName(), f));
final DataTypeFactory dataTypeFactory = ((TableEnvironmentInternal) env).getCatalogManager().getDataTypeFactory();
final Table inputTable;
if (testSpec.fieldDataTypes == null) {
inputTable = env.fromValues(Row.of(testSpec.fieldData));
} else {
final DataTypes.UnresolvedField[] fields = IntStream.range(0, testSpec.fieldDataTypes.length).mapToObj(i -> DataTypes.FIELD("f" + i, testSpec.fieldDataTypes[i])).toArray(DataTypes.UnresolvedField[]::new);
inputTable = env.fromValues(DataTypes.ROW(fields), Row.of(testSpec.fieldData));
}
for (TestItem testItem : testSpec.testItems) {
try {
if (testItem instanceof ResultTestItem<?>) {
testResult(dataTypeFactory, env, inputTable, (ResultTestItem<?>) testItem);
} else if (testItem instanceof ErrorTestItem<?>) {
testError(env, inputTable, (ErrorTestItem<?>) testItem);
}
} catch (Throwable t) {
throw new AssertionError("Failing test item: " + testItem, t);
}
}
}
use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project zeppelin by apache.
the class Flink114Shims 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);
}
use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project flink by apache.
the class HiveDynamicTableFactoryTest method getTableSource.
private DynamicTableSource getTableSource(String tableName) throws Exception {
TableEnvironmentInternal tableEnvInternal = (TableEnvironmentInternal) tableEnv;
ObjectIdentifier tableIdentifier = ObjectIdentifier.of(hiveCatalog.getName(), "default", tableName);
CatalogTable catalogTable = (CatalogTable) hiveCatalog.getTable(tableIdentifier.toObjectPath());
return FactoryUtil.createDynamicTableSource((DynamicTableSourceFactory) hiveCatalog.getFactory().orElseThrow(IllegalStateException::new), tableIdentifier, tableEnvInternal.getCatalogManager().resolveCatalogTable(catalogTable), tableEnv.getConfig().getConfiguration(), Thread.currentThread().getContextClassLoader(), false);
}
use of org.apache.flink.table.api.internal.TableEnvironmentInternal in project zeppelin by apache.
the class Flink113Shims 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);
}
Aggregations