Search in sources :

Example 1 with MysqlTable

use of com.google.api.services.datastream.v1alpha1.model.MysqlTable in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method getMysqlObjectSchema.

private Map<String, StandardSQLTypeName> getMysqlObjectSchema(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    Map<String, StandardSQLTypeName> objectSchema = new HashMap<String, StandardSQLTypeName>();
    MysqlTable table = discoverMysqlTableSchema(streamName, schemaName, tableName, sourceConnProfile);
    for (MysqlColumn column : table.getMysqlColumns()) {
        StandardSQLTypeName bqType = convertMysqlToBigQueryColumnType(column);
        objectSchema.put(column.getColumnName(), bqType);
    }
    return objectSchema;
}
Also used : MysqlTable(com.google.api.services.datastream.v1alpha1.model.MysqlTable) HashMap(java.util.HashMap) StandardSQLTypeName(com.google.cloud.bigquery.StandardSQLTypeName) MysqlColumn(com.google.api.services.datastream.v1alpha1.model.MysqlColumn)

Example 2 with MysqlTable

use of com.google.api.services.datastream.v1alpha1.model.MysqlTable in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method getMysqlPrimaryKeys.

public List<String> getMysqlPrimaryKeys(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    List<String> primaryKeys = new ArrayList<String>();
    MysqlTable table = discoverMysqlTableSchema(streamName, schemaName, tableName, sourceConnProfile);
    for (MysqlColumn column : table.getMysqlColumns()) {
        Boolean isPrimaryKey = column.getPrimaryKey();
        if (BooleanUtils.isTrue(isPrimaryKey)) {
            primaryKeys.add(column.getColumnName());
        }
    }
    return primaryKeys;
}
Also used : MysqlTable(com.google.api.services.datastream.v1alpha1.model.MysqlTable) ArrayList(java.util.ArrayList) MysqlColumn(com.google.api.services.datastream.v1alpha1.model.MysqlColumn)

Example 3 with MysqlTable

use of com.google.api.services.datastream.v1alpha1.model.MysqlTable in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method discoverMysqlTableSchema.

/**
 * Return a {@link MysqlTable} object with schema and PK information.
 *
 * @param streamName A fully qualified Stream name (ie. projects/my-project/stream/my-stream)
 * @param schemaName The name of the schema for the table being discovered.
 * @param tableName The name of the table to discover.
 * @param sourceConnProfile The SourceConfig connection profile to be discovered.
 */
public MysqlTable discoverMysqlTableSchema(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    DataStream.Projects.Locations.ConnectionProfiles.Discover discoverConnProfile = getDiscoverTableRequest(streamName, schemaName, tableName, sourceConnProfile);
    MysqlRdbms tableResponse = discoverConnProfile.execute().getMysqlRdbms();
    MysqlDatabase schema = tableResponse.getMysqlDatabases().get(0);
    MysqlTable table = schema.getMysqlTables().get(0);
    return table;
}
Also used : MysqlRdbms(com.google.api.services.datastream.v1alpha1.model.MysqlRdbms) MysqlTable(com.google.api.services.datastream.v1alpha1.model.MysqlTable) MysqlDatabase(com.google.api.services.datastream.v1alpha1.model.MysqlDatabase)

Example 4 with MysqlTable

use of com.google.api.services.datastream.v1alpha1.model.MysqlTable in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method buildMysqlRdbmsForTable.

private MysqlRdbms buildMysqlRdbmsForTable(String databaseName, String tableName) {
    List<MysqlTable> mysqlTables = new ArrayList<MysqlTable>();
    mysqlTables.add(new MysqlTable().setTableName(tableName));
    List<MysqlDatabase> mysqlDatabases = new ArrayList<MysqlDatabase>();
    mysqlDatabases.add(new MysqlDatabase().setDatabaseName(databaseName).setMysqlTables(mysqlTables));
    MysqlRdbms rdbms = new MysqlRdbms().setMysqlDatabases(mysqlDatabases);
    return rdbms;
}
Also used : MysqlRdbms(com.google.api.services.datastream.v1alpha1.model.MysqlRdbms) MysqlTable(com.google.api.services.datastream.v1alpha1.model.MysqlTable) MysqlDatabase(com.google.api.services.datastream.v1alpha1.model.MysqlDatabase) ArrayList(java.util.ArrayList)

Aggregations

MysqlTable (com.google.api.services.datastream.v1alpha1.model.MysqlTable)4 MysqlColumn (com.google.api.services.datastream.v1alpha1.model.MysqlColumn)2 MysqlDatabase (com.google.api.services.datastream.v1alpha1.model.MysqlDatabase)2 MysqlRdbms (com.google.api.services.datastream.v1alpha1.model.MysqlRdbms)2 ArrayList (java.util.ArrayList)2 StandardSQLTypeName (com.google.cloud.bigquery.StandardSQLTypeName)1 HashMap (java.util.HashMap)1