Search in sources :

Example 1 with DatastreamRow

use of com.google.cloud.teleport.v2.values.DatastreamRow in project DataflowTemplates by GoogleCloudPlatform.

the class DatastreamToDMLTest method testGetPostgresSchemaName.

/**
 * Test whether {@link DatastreamToDML#getTargetSchemaName(row)} converts the Oracle schema into
 * the correct Postgres schema.
 */
@Test
public void testGetPostgresSchemaName() {
    DatastreamToDML datastreamToDML = DatastreamToPostgresDML.of(null);
    JsonNode rowObj = this.getRowObj();
    DatastreamRow row = DatastreamRow.of(rowObj);
    String expectedSchemaName = "my_schema";
    String schemaName = datastreamToDML.getTargetSchemaName(row);
    assertEquals(schemaName, expectedSchemaName);
}
Also used : DatastreamRow(com.google.cloud.teleport.v2.values.DatastreamRow) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 2 with DatastreamRow

use of com.google.cloud.teleport.v2.values.DatastreamRow in project DataflowTemplates by GoogleCloudPlatform.

the class DatastreamToDML method convertJsonToDmlInfo.

public DmlInfo convertJsonToDmlInfo(JsonNode rowObj, String failsafeValue) {
    DatastreamRow row = DatastreamRow.of(rowObj);
    try {
        // Oracle uses upper case while Postgres uses all lowercase.
        // We lowercase the values of these metadata fields to align with
        // our schema conversion rules.
        String catalogName = this.getTargetCatalogName(row);
        String schemaName = this.getTargetSchemaName(row);
        String tableName = this.getTargetTableName(row);
        Map<String, String> tableSchema = this.getTableSchema(catalogName, schemaName, tableName);
        if (tableSchema.isEmpty()) {
            // If the table DNE we return null (NOOP)
            return null;
        }
        List<String> primaryKeys = this.getPrimaryKeys(catalogName, schemaName, tableName, rowObj);
        List<String> orderByFields = row.getSortFields();
        List<String> primaryKeyValues = getFieldValues(rowObj, primaryKeys, tableSchema);
        List<String> orderByValues = getFieldValues(rowObj, orderByFields, tableSchema);
        String dmlSqlTemplate = getDmlTemplate(rowObj, primaryKeys);
        Map<String, String> sqlTemplateValues = getSqlTemplateValues(rowObj, catalogName, schemaName, tableName, primaryKeys, tableSchema);
        String dmlSql = StringSubstitutor.replace(dmlSqlTemplate, sqlTemplateValues, "{", "}");
        return DmlInfo.of(failsafeValue, dmlSql, schemaName, tableName, primaryKeys, orderByFields, primaryKeyValues, orderByValues);
    } catch (DeletedWithoutPrimaryKey e) {
        LOG.error("CDC Error: {} :: {}", rowObj.toString(), e.toString());
        return null;
    } catch (Exception e) {
        // TODO(dhercher): Consider raising an error and pushing to DLQ
        LOG.error("Value Error: {} :: {}", rowObj.toString(), e.toString());
        return null;
    }
}
Also used : DatastreamRow(com.google.cloud.teleport.v2.values.DatastreamRow) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 3 with DatastreamRow

use of com.google.cloud.teleport.v2.values.DatastreamRow in project DataflowTemplates by GoogleCloudPlatform.

the class DatastreamToDMLTest method testGetPostgresTableName.

/**
 * Test whether {@link DatastreamToPostgresDML#getTargetTableName(row)} converts the Oracle table
 * into the correct Postgres table.
 */
@Test
public void testGetPostgresTableName() {
    DatastreamToDML datastreamToDML = DatastreamToPostgresDML.of(null);
    JsonNode rowObj = this.getRowObj();
    DatastreamRow row = DatastreamRow.of(rowObj);
    String expectedTableName = "my_table$name";
    String tableName = datastreamToDML.getTargetTableName(row);
    assertEquals(expectedTableName, tableName);
}
Also used : DatastreamRow(com.google.cloud.teleport.v2.values.DatastreamRow) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Aggregations

DatastreamRow (com.google.cloud.teleport.v2.values.DatastreamRow)3 JsonNode (org.codehaus.jackson.JsonNode)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1