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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations