Search in sources :

Example 96 with GenericRecordBuilder

use of org.apache.avro.generic.GenericRecordBuilder in project dwh-assessment-extraction-tool by google.

the class InternalScriptLoaderTest method loadScripts_queryReferences.

@Test
public void loadScripts_queryReferences() throws SQLException, IOException {
    String scriptName = "query_references";
    String sqlScript = getScript(scriptName);
    Schema schema = scriptRunner.extractSchema(connection, sqlScript, scriptName, "namespace");
    ImmutableList<GenericRecord> records = executeScriptToAvro(sqlScript, schema);
    GenericRecord expectedRecord = new GenericRecordBuilder(schema).set("ProcID", ByteBuffer.wrap(BigInteger.ONE.toByteArray())).set("CollectTimeStamp", Instant.parse("2021-07-01T18:23:42Z").toEpochMilli()).set("QueryID", ByteBuffer.wrap(BigInteger.valueOf(123).toByteArray())).set("ObjectDatabaseName", "dbname").set("ObjectTableName", "tablename").set("ObjectColumnName", "columnname").set("ObjectID", 5).set("ObjectNum", 10).set("ObjectType", "Col").set("FreqofUse", 10).set("TypeofUse", 8).build();
    assertThat(records).containsExactly(expectedRecord);
    // Verify records serialization.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executeScript(scriptName, outputStream);
    assertThat(getAvroDataOutputReader(outputStream).next()).isEqualTo(expectedRecord);
}
Also used : Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 97 with GenericRecordBuilder

use of org.apache.avro.generic.GenericRecordBuilder in project dwh-assessment-extraction-tool by google.

the class InternalScriptLoaderTest method loadScripts_temptables.

@Test
public void loadScripts_temptables() throws IOException, SQLException {
    String scriptName = "temp_tables";
    String sqlScript = getScript(scriptName);
    // Get schema and verify records.
    Schema schema = scriptRunner.extractSchema(connection, sqlScript, scriptName, "namespace");
    ImmutableList<GenericRecord> records = executeScriptToAvro(/*sqlScript=*/
    sqlScript, schema);
    GenericRecord expectedRecord = new GenericRecordBuilder(schema).set("HostNo", 1).set("SessionNo", 1).set("UserName", "user_name").set("B_DatabaseName", "database_name").set("B_TableName", "table_name").set("E_TableId", ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6 })).build();
    assertThat(records).containsExactly(expectedRecord);
    // Verify records serialization.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executeScript(scriptName, outputStream);
    assertThat(readOutputStreamToAvro(outputStream, 1)).containsExactly(expectedRecord);
}
Also used : Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 98 with GenericRecordBuilder

use of org.apache.avro.generic.GenericRecordBuilder in project dwh-assessment-extraction-tool by google.

the class InternalScriptLoaderTest method loadScripts_users.

@Test
public void loadScripts_users() throws IOException, SQLException {
    String scriptName = "users";
    String sqlScript = getScript(scriptName);
    // Get schema and verify records.
    Schema schema = scriptRunner.extractSchema(connection, sqlScript, scriptName, "namespace");
    ImmutableList<GenericRecord> records = executeScriptToAvro(/*sqlScript=*/
    sqlScript, schema);
    GenericRecord expectedRecordUser1 = new GenericRecordBuilder(schema).set("UserName", "user_1").set("CreatorName", "user_0").set("CreateTimeStamp", Instant.parse("2021-07-02T02:00:00Z").toEpochMilli()).set("LastAccessTimeStamp", null).build();
    GenericRecord expectedRecordUser2 = new GenericRecordBuilder(schema).set("UserName", "user_2").set("CreatorName", "user_0").set("CreateTimeStamp", Instant.parse("2021-07-02T02:00:00Z").toEpochMilli()).set("LastAccessTimeStamp", Instant.parse("2021-07-03T02:00:00Z").toEpochMilli()).build();
    assertThat(records).containsExactly(expectedRecordUser1, expectedRecordUser2);
    // Verify records serialization.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executeScript(scriptName, outputStream);
    assertThat(readOutputStreamToAvro(outputStream, 2)).containsExactly(expectedRecordUser1, expectedRecordUser2);
}
Also used : Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 99 with GenericRecordBuilder

use of org.apache.avro.generic.GenericRecordBuilder in project dwh-assessment-extraction-tool by google.

the class InternalScriptLoaderTest method loadScripts_sqlLogs_with_timeRange.

@Test
public void loadScripts_sqlLogs_with_timeRange() throws IOException, SQLException {
    String scriptName = "sql_logs";
    String sqlScript = getScript(scriptName, getSqlTemplateRendererWithEndTime("2021-07-01 23:23:23.23"));
    Schema schema = scriptRunner.extractSchema(connection, sqlScript, scriptName, "namespace");
    ImmutableList<GenericRecord> records = executeScriptToAvro(sqlScript, schema);
    GenericRecord expectedRecord = new GenericRecordBuilder(schema).set("ProcID", ByteBuffer.wrap(BigInteger.ONE.toByteArray())).set("QueryID", ByteBuffer.wrap(BigInteger.valueOf(123).toByteArray())).set("CollectTimeStamp", Instant.parse("2021-07-01T18:23:42Z").toEpochMilli()).set("SqlRowNo", 1).set("SqlText", "SELECT * FROM MyTable;").build();
    assertThat(records).containsExactly(expectedRecord);
    // Verify records serialization.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executeScript(scriptName, outputStream);
    assertThat(getAvroDataOutputReader(outputStream).next()).isEqualTo(expectedRecord);
}
Also used : Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 100 with GenericRecordBuilder

use of org.apache.avro.generic.GenericRecordBuilder in project dwh-assessment-extraction-tool by google.

the class InternalScriptLoaderTest method loadScripts_functioninfo.

@Test
public void loadScripts_functioninfo() throws IOException, SQLException {
    String scriptName = "functioninfo";
    String sqlScript = getScript(scriptName);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executeScript(scriptName, outputStream);
    Schema schema = scriptRunner.extractSchema(connection, sqlScript, scriptName, "namespace");
    ImmutableList<GenericRecord> records = executeScriptToAvro(sqlScript, schema);
    GenericRecord expectedRecord = new GenericRecordBuilder(schema).set("DatabaseName", "db_name").set("FunctionName", "function_name").set("SpecificName", "specific_name").set("FunctionId", ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6 })).set("NumParameters", 3).set("ParameterDataTypes", "I1BF").set("FunctionType", "F").set("ExternalName", "JSONGETVALUE").set("SrcFileLanguage", "P").set("NoSQLDataAccess", "Y").set("ParameterStyle", "I").set("DeterministicOpt", "Y").set("NullCall", "Y").set("PrepareCount", "N").set("ExecProtectionMode", "S").set("ExtFileReference", "SS!TD_GetFunctionContext!/var").set("CharacterType", 1).set("Platform", "LINUX64").set("InterimFldSize", 0).set("RoutineKind", "C").set("ParameterUDTIds", ByteBuffer.wrap(new byte[] { 0, 0, (byte) 0xEC, 0xC, 0, (byte) 0xC0, 0x30, 0, 0, (byte) 0xC0, 0x16, 0 })).set("MaxOutParameters", 0).set("RefQueryband", "N").build();
    assertThat(records).containsExactly(expectedRecord);
    assertThat(getAvroDataOutputReader(outputStream).next()).isEqualTo(expectedRecord);
}
Also used : Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Aggregations

GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)368 GenericRecord (org.apache.avro.generic.GenericRecord)254 Test (org.junit.Test)242 Schema (org.apache.avro.Schema)199 GenericData (org.apache.avro.generic.GenericData)60 ArrayList (java.util.ArrayList)44 EnumTest (foo.bar.EnumTest)41 Schema (org.apache.kafka.connect.data.Schema)41 IndexedRecord (org.apache.avro.generic.IndexedRecord)39 File (java.io.File)37 SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)35 Path (org.apache.hadoop.fs.Path)33 Struct (org.apache.kafka.connect.data.Struct)30 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)28 List (java.util.List)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)26 ByteBuffer (java.nio.ByteBuffer)26 HashMap (java.util.HashMap)25 Record (org.apache.avro.generic.GenericData.Record)25 Test (org.testng.annotations.Test)21