Java Code Examples for org.apache.flink.table.api.Table#getQueryOperation()

The following examples show how to use org.apache.flink.table.api.Table#getQueryOperation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void registerTable(String name, Table table) {
	if (((TableImpl) table).getTableEnvironment() != this) {
		throw new TableException(
			"Only tables that belong to this TableEnvironment can be registered.");
	}

	CatalogBaseTable tableTable = new QueryOperationCatalogView(table.getQueryOperation());
	registerTableInternal(name, tableTable);
}
 
Example 2
Source File: StreamTableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T> DataStream<T> toAppendStream(Table table, TypeInformation<T> typeInfo) {
	OutputConversionModifyOperation modifyOperation = new OutputConversionModifyOperation(
		table.getQueryOperation(),
		TypeConversions.fromLegacyInfoToDataType(typeInfo),
		OutputConversionModifyOperation.UpdateMode.APPEND);
	return toDataStream(table, modifyOperation);
}
 
Example 3
Source File: StreamTableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T> DataStream<Tuple2<Boolean, T>> toRetractStream(Table table, TypeInformation<T> typeInfo) {
	OutputConversionModifyOperation modifyOperation = new OutputConversionModifyOperation(
		table.getQueryOperation(),
		wrapWithChangeFlag(typeInfo),
		OutputConversionModifyOperation.UpdateMode.RETRACT);
	return toDataStream(table, modifyOperation);
}
 
Example 4
Source File: FlinkSqlParser.java    From sylph with Apache License 2.0 5 votes vote down vote up
private void translateJoin(JoinInfo joinInfo, Map<String, CreateTable> batchTables)
{
    Table streamTable = getTable(tableEnv, joinInfo.getStreamTable());
    RowTypeInfo streamRowType = (RowTypeInfo) streamTable.getSchema().toRowType();
    DataStream<Row> inputStream = tableEnv.toAppendStream(streamTable, org.apache.flink.types.Row.class);
    inputStream.getTransformation().setOutputType(streamRowType);

    //get batch table schema
    CreateTable batchTable = requireNonNull(batchTables.get(joinInfo.getBatchTable().getName()), "batch table [" + joinInfo.getJoinTableName() + "] not exits");
    RowTypeInfo batchTableRowType = StreamSqlUtil.schemaToRowTypeInfo(StreamSqlUtil.getTableSchema(batchTable));
    List<SelectField> joinSelectFields = getAllSelectFields(joinInfo, streamRowType, batchTableRowType);

    //It is recommended to do keyby first.
    JoinContext joinContext = JoinContextImpl.createContext(joinInfo, streamRowType, joinSelectFields);
    RealTimeTransForm transForm = getJoinTransForm(joinContext, batchTable);
    DataStream<Row> joinResultStream = AsyncFunctionHelper.translate(inputStream, transForm);

    //set schema
    RowTypeInfo rowTypeInfo = getJoinOutScheam(joinSelectFields);
    joinResultStream.getTransformation().setOutputType(rowTypeInfo);
    //--register tmp joinTable

    Catalog catalog = tableEnv.getCatalog(tableEnv.getCurrentCatalog()).get();
    if (catalog.tableExists(ObjectPath.fromString(joinInfo.getJoinTableName()))) {
        Table table = tableEnv.fromDataStream(joinResultStream);
        CatalogBaseTable tableTable = new QueryOperationCatalogView(table.getQueryOperation());
        try {
            catalog.createTable(ObjectPath.fromString(joinInfo.getJoinTableName()), tableTable, true);
        }
        catch (TableAlreadyExistException | DatabaseNotExistException e) {
            e.printStackTrace();
        }
        //tableEnv.replaceRegisteredTable(joinInfo.getJoinTableName(), new RelTable(table.getRelNode()));
    }
    else {
        tableEnv.registerDataStream(joinInfo.getJoinTableName(), joinResultStream);
    }
    //next update join select query
    joinQueryUpdate(joinInfo, rowTypeInfo.getFieldNames());
}
 
Example 5
Source File: StreamTableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T> DataStream<T> toAppendStream(Table table, TypeInformation<T> typeInfo) {
	OutputConversionModifyOperation modifyOperation = new OutputConversionModifyOperation(
		table.getQueryOperation(),
		TypeConversions.fromLegacyInfoToDataType(typeInfo),
		OutputConversionModifyOperation.UpdateMode.APPEND);
	return toDataStream(table, modifyOperation);
}
 
Example 6
Source File: StreamTableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T> DataStream<Tuple2<Boolean, T>> toRetractStream(Table table, TypeInformation<T> typeInfo) {
	OutputConversionModifyOperation modifyOperation = new OutputConversionModifyOperation(
		table.getQueryOperation(),
		wrapWithChangeFlag(typeInfo),
		OutputConversionModifyOperation.UpdateMode.RETRACT);
	return toDataStream(table, modifyOperation);
}
 
Example 7
Source File: ApiExpressionUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
public static TableReferenceExpression tableRef(String name, Table table) {
	return new TableReferenceExpression(name, table.getQueryOperation());
}