use of co.cask.cdap.api.data.schema.Schema in project cdap by caskdata.
the class MockJoiner method configurePipeline.
@Override
public void configurePipeline(MultiInputPipelineConfigurer pipelineConfigurer) {
MultiInputStageConfigurer stageConfigurer = pipelineConfigurer.getMultiInputStageConfigurer();
Map<String, Schema> inputSchemas = stageConfigurer.getInputSchemas();
stageConfigurer.setOutputSchema(getOutputSchema(inputSchemas));
config.validateConfig();
}
use of co.cask.cdap.api.data.schema.Schema in project cdap by caskdata.
the class MockRuntimeDatasetSink method readOutput.
/**
* Used to read the records written by this sink.
*
* @param tableManager dataset manager used to get the sink dataset to read from
*/
public static List<StructuredRecord> readOutput(DataSetManager<Table> tableManager) throws Exception {
Table table = tableManager.get();
try (Scanner scanner = table.scan(null, null)) {
List<StructuredRecord> records = new ArrayList<>();
Row row;
while ((row = scanner.next()) != null) {
Schema schema = Schema.parseJson(row.getString(SCHEMA_COL));
String recordStr = row.getString(RECORD_COL);
records.add(StructuredRecordStringConverter.fromJsonString(recordStr, schema));
}
return records;
}
}
use of co.cask.cdap.api.data.schema.Schema in project cdap by caskdata.
the class MockSink method readOutput.
/**
* Used to read the records written by this sink.
*
* @param tableManager dataset manager used to get the sink dataset to read from
*/
public static List<StructuredRecord> readOutput(DataSetManager<Table> tableManager) throws Exception {
tableManager.flush();
Table table = tableManager.get();
try (Scanner scanner = table.scan(null, null)) {
List<StructuredRecord> records = new ArrayList<>();
Row row;
while ((row = scanner.next()) != null) {
Schema schema = Schema.parseJson(row.getString(SCHEMA_COL));
String recordStr = row.getString(RECORD_COL);
records.add(StructuredRecordStringConverter.fromJsonString(recordStr, schema));
}
return records;
}
}
use of co.cask.cdap.api.data.schema.Schema in project cdap by caskdata.
the class SchemaTest method testParseSQLWithWhitespace.
@Test
public void testParseSQLWithWhitespace() throws IOException {
String schemaStr = "map_field map< string , int > not null,\n" + "arr_field array< record< x:int , y:double >\t> not null";
Schema expectedSchema = Schema.recordOf("rec", Schema.Field.of("map_field", Schema.mapOf(Schema.nullableOf(Schema.of(Schema.Type.STRING)), Schema.nullableOf(Schema.of(Schema.Type.INT)))), Schema.Field.of("arr_field", Schema.arrayOf(Schema.nullableOf(Schema.recordOf("rec1", Schema.Field.of("x", Schema.nullableOf(Schema.of(Schema.Type.INT))), Schema.Field.of("y", Schema.nullableOf(Schema.of(Schema.Type.DOUBLE))))))));
Assert.assertEquals(expectedSchema, Schema.parseSQL(schemaStr));
}
use of co.cask.cdap.api.data.schema.Schema in project cdap by caskdata.
the class SchemaTest method testAvroEnumSchema.
@Test
public void testAvroEnumSchema() throws Exception {
org.apache.avro.Schema schema = org.apache.avro.Schema.createEnum("UserInterests", "Describes interests of user", "org.example.schema", ImmutableList.of("CRICKET", "BASEBALL"));
Schema parsedSchema = Schema.parseJson(schema.toString());
Assert.assertEquals(ImmutableSet.of("CRICKET", "BASEBALL"), parsedSchema.getEnumValues());
}
Aggregations