Search in sources :

Example 1 with OracleTable

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

the class DataStreamClientTest method testDataStreamClientDiscoverOracleTableSchema.

/**
 * Test whether {@link DataStreamClient#discoverTableSchema(...)} gets a Streams source connection
 * profile name.
 */
@Ignore
@Test
public void testDataStreamClientDiscoverOracleTableSchema() throws IOException, GeneralSecurityException {
    String projectId = "dataflow-bigstream-integration";
    String streamName = "projects/dataflow-bigstream-integration/locations/us-central1/streams/dfstream1";
    String schemaName = "HR";
    String tableName = "JOBS";
    DataStreamClient datastream = new DataStreamClient(null);
    SourceConfig sourceConnProfile = datastream.getSourceConnectionProfile(streamName);
    OracleTable table = datastream.discoverOracleTableSchema(streamName, schemaName, tableName, sourceConnProfile);
    String columnName = table.getOracleColumns().get(0).getColumnName();
    Boolean isPrimaryKey = table.getOracleColumns().get(0).getPrimaryKey();
    assertEquals(columnName, "JOB_TITLE");
    assertEquals(isPrimaryKey, null);
}
Also used : OracleTable(com.google.api.services.datastream.v1alpha1.model.OracleTable) SourceConfig(com.google.api.services.datastream.v1alpha1.model.SourceConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with OracleTable

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

the class DataStreamClient method getOraclePrimaryKeys.

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

Example 3 with OracleTable

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

the class DataStreamClient method discoverOracleTableSchema.

/**
 * Return a {@link OracleTable} 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 OracleTable discoverOracleTableSchema(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    DataStream.Projects.Locations.ConnectionProfiles.Discover discoverConnProfile = getDiscoverTableRequest(streamName, schemaName, tableName, sourceConnProfile);
    OracleRdbms tableResponse = discoverConnProfile.execute().getOracleRdbms();
    OracleSchema schema = tableResponse.getOracleSchemas().get(0);
    OracleTable table = schema.getOracleTables().get(0);
    return table;
}
Also used : OracleSchema(com.google.api.services.datastream.v1alpha1.model.OracleSchema) OracleTable(com.google.api.services.datastream.v1alpha1.model.OracleTable) OracleRdbms(com.google.api.services.datastream.v1alpha1.model.OracleRdbms)

Example 4 with OracleTable

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

the class DataStreamClient method buildOracleRdbmsForTable.

private OracleRdbms buildOracleRdbmsForTable(String schemaName, String tableName) {
    List<OracleTable> oracleTables = new ArrayList<OracleTable>();
    oracleTables.add(new OracleTable().setTableName(tableName));
    List<OracleSchema> oracleSchemas = new ArrayList<OracleSchema>();
    oracleSchemas.add(new OracleSchema().setSchemaName(schemaName).setOracleTables(oracleTables));
    OracleRdbms rdbms = new OracleRdbms().setOracleSchemas(oracleSchemas);
    return rdbms;
}
Also used : OracleTable(com.google.api.services.datastream.v1alpha1.model.OracleTable) OracleSchema(com.google.api.services.datastream.v1alpha1.model.OracleSchema) ArrayList(java.util.ArrayList) OracleRdbms(com.google.api.services.datastream.v1alpha1.model.OracleRdbms)

Example 5 with OracleTable

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

the class DataStreamClient method getOracleObjectSchema.

private Map<String, StandardSQLTypeName> getOracleObjectSchema(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    Map<String, StandardSQLTypeName> objectSchema = new HashMap<String, StandardSQLTypeName>();
    OracleTable table = discoverOracleTableSchema(streamName, schemaName, tableName, sourceConnProfile);
    for (OracleColumn column : table.getOracleColumns()) {
        StandardSQLTypeName bqType = convertOracleToBigQueryColumnType(column);
        objectSchema.put(column.getColumnName(), bqType);
    }
    return objectSchema;
}
Also used : OracleTable(com.google.api.services.datastream.v1alpha1.model.OracleTable) HashMap(java.util.HashMap) OracleColumn(com.google.api.services.datastream.v1alpha1.model.OracleColumn) StandardSQLTypeName(com.google.cloud.bigquery.StandardSQLTypeName)

Aggregations

OracleTable (com.google.api.services.datastream.v1alpha1.model.OracleTable)5 OracleColumn (com.google.api.services.datastream.v1alpha1.model.OracleColumn)2 OracleRdbms (com.google.api.services.datastream.v1alpha1.model.OracleRdbms)2 OracleSchema (com.google.api.services.datastream.v1alpha1.model.OracleSchema)2 ArrayList (java.util.ArrayList)2 SourceConfig (com.google.api.services.datastream.v1alpha1.model.SourceConfig)1 StandardSQLTypeName (com.google.cloud.bigquery.StandardSQLTypeName)1 HashMap (java.util.HashMap)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1