org.junit.contrib.java.lang.system.Assertion#org.apache.avro.SchemaBuilder源码实例Demo

下面列出了org.junit.contrib.java.lang.system.Assertion#org.apache.avro.SchemaBuilder 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: beam   文件: AvroCoderTest.java
@Test
public void testAvroCoderNestedRecords() {
  // Nested Record
  assertDeterministic(
      AvroCoder.of(
          SchemaBuilder.record("nestedRecord")
              .fields()
              .name("subRecord")
              .type()
              .record("subRecord")
              .fields()
              .name("innerField")
              .type()
              .stringType()
              .noDefault()
              .endRecord()
              .noDefault()
              .endRecord()));
}
 
源代码2 项目: presto   文件: TestAvroDecoder.java
@Test
public void testMapOfArrayOfMapsWithDifferentValues()
{
    Schema schema = SchemaBuilder.map()
            .values()
            .array()
            .items()
            .map()
            .values()
            .floatType();

    Map<String, List<Map<String, Float>>> data = buildMapFromKeysAndValues(ImmutableList.of("k1", "k2"),
            Arrays.asList(Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk1", "sk2", "sk3"), Arrays.asList(1.3F, -5.3F, 2.3F))),
                    Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk11", "sk21", "sk31"), Arrays.asList(11.3F, -1.5F, 12.3F)))));
    Map<String, List<Map<String, Float>>> mismatchedData = buildMapFromKeysAndValues(ImmutableList.of("k1", "k2"),
            Arrays.asList(Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk1", "sk2", "sk3"), Arrays.asList(1.3F, -5.3F, -2.3F))),
                    Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk11", "sk21", "sk31"), Arrays.asList(11.3F, -1.5F, 12.3F)))));

    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", MAP_OF_ARRAY_OF_MAP_TYPE, "map_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "map_field", schema.toString(), data);
    assertThrows(AssertionError.class, () -> checkArrayValue(decodedRow, row, mismatchedData));
}
 
源代码3 项目: nifi   文件: TestKiteProcessorsCluster.java
@Test
public void testSchemaFromDistributedFileSystem() throws IOException {
    Schema expected = SchemaBuilder.record("Test").fields()
            .requiredLong("id")
            .requiredString("color")
            .optionalDouble("price")
            .endRecord();

    Path schemaPath = new Path("hdfs:/tmp/schema.avsc");
    FileSystem fs = schemaPath.getFileSystem(DefaultConfiguration.get());
    OutputStream out = fs.create(schemaPath);
    out.write(bytesFor(expected.toString(), Charset.forName("utf8")));
    out.close();

    Schema schema = AbstractKiteProcessor.getSchema(
            schemaPath.toString(), DefaultConfiguration.get());

    Assert.assertEquals("Schema from file should match", expected, schema);
}
 
源代码4 项目: components   文件: MarketoConstants.java
public static Schema getRESTSchemaForGetLeadOrGetMultipleLeads() {
    return SchemaBuilder.builder().record("getLeadOrGetMultipleLeadsREST").fields() //
            .name("id").prop(SchemaConstants.TALEND_COLUMN_IS_KEY, "true").type().nullable().intType().noDefault() //
            .name("email").type().nullable().stringType().noDefault() //
            .name("firstName").type().nullable().stringType().noDefault() //
            .name("lastName").type().nullable().stringType().noDefault() //
            .name(FIELD_CREATED_AT)//
            .prop(SchemaConstants.TALEND_COLUMN_PATTERN, DATETIME_PATTERN_REST)//
            .prop(SchemaConstants.JAVA_CLASS_FLAG, Date.class.getCanonicalName()) //
            .type(AvroUtils._date()).noDefault()//
            .name(FIELD_UPDATED_AT)//
            .prop(SchemaConstants.TALEND_COLUMN_PATTERN, DATETIME_PATTERN_REST)//
            .prop(SchemaConstants.JAVA_CLASS_FLAG, Date.class.getCanonicalName()) //
            .type(AvroUtils._date()).noDefault()//
            .endRecord();
}
 
@Test
public void testSpecificRecordWithConfluentSchemaRegistry() throws Exception {
	MockSchemaRegistryClient client = new MockSchemaRegistryClient();

	Schema schema = SchemaBuilder.record("testRecord")
		.fields()
		.optionalString("testField")
		.endRecord();
	int schemaId = client.register("testTopic", schema);

	ConfluentSchemaRegistryCoder registryCoder = new ConfluentSchemaRegistryCoder(client);
	ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
	DataOutputStream dataOutputStream = new DataOutputStream(byteOutStream);
	dataOutputStream.writeByte(0);
	dataOutputStream.writeInt(schemaId);
	dataOutputStream.flush();

	ByteArrayInputStream byteInStream = new ByteArrayInputStream(byteOutStream.toByteArray());
	Schema readSchema = registryCoder.readSchema(byteInStream);

	assertEquals(schema, readSchema);
	assertEquals(0, byteInStream.available());
}
 
源代码6 项目: kite   文件: TestJsonUtil.java
@Test
public void testSchemaInferenceNullableMap() throws Exception {
  Schema recordSchema = SchemaBuilder.record("Test").fields()
      .requiredString("aString")
      .name("aMap").type().map().values()
          .unionOf().nullType().and().stringType().endUnion().noDefault()
      .endRecord();

  String jsonSample = "{" +
      "\"aString\": \"triangle\"," +
      "\"aMap\": { \"left\": null, \"right\": \"dictionary\" }" +
      "}";

  JsonNode datum = JsonUtil.parse(jsonSample);
  Assert.assertEquals("Should produce expected schema",
      recordSchema, JsonUtil.inferSchemaWithMaps(datum, "Test"));

  Map<String, Object> aMap = Maps.newLinkedHashMap();
  aMap.put("left", null);
  aMap.put("right", "dictionary");
  GenericData.Record expected = new GenericData.Record(recordSchema);
  expected.put("aString", "triangle");
  expected.put("aMap", aMap);
  Assert.assertEquals("Should convert to record",
      expected, convertGeneric(datum, recordSchema));
}
 
源代码7 项目: parquet-mr   文件: TestReflectLogicalTypes.java
@Test
public void testReadUUIDArray() throws IOException {
  Schema uuidArraySchema = SchemaBuilder.record(RecordWithUUIDArray.class.getName())
      .fields()
      .name("uuids").type().array().items().stringType().noDefault()
      .endRecord();
  LogicalTypes.uuid().addToSchema(
      uuidArraySchema.getField("uuids").schema().getElementType());

  UUID u1 = UUID.randomUUID();
  UUID u2 = UUID.randomUUID();

  GenericRecord r = new GenericData.Record(uuidArraySchema);
  r.put("uuids", Arrays.asList(u1.toString(), u2.toString()));

  RecordWithUUIDArray expected = new RecordWithUUIDArray();
  expected.uuids = new UUID[] {u1, u2};

  File test = write(uuidArraySchema, r);

  Assert.assertEquals("Should convert Strings to UUIDs",
      expected,
      read(REFLECT, uuidArraySchema, test).get(0));
}
 
源代码8 项目: kite   文件: TestJsonUtil.java
@Test
public void testSchemaInferenceNullablePrimitiveArray() throws Exception {
  Schema recordSchema = SchemaBuilder.record("Test").fields()
      .requiredString("aString")
      .name("anArray").type().array().items()
          .unionOf().nullType().and().intType().endUnion().noDefault()
      .endRecord();

  String jsonSample = "{" +
      "\"aString\": \"triangle\"," +
      "\"anArray\": [ null, 1, 2, 3, 4 ]" +
      "}";

  JsonNode datum = JsonUtil.parse(jsonSample);
  Assert.assertEquals("Should produce expected schema",
      recordSchema, JsonUtil.inferSchema(datum, "Test"));

  GenericData.Record expected = new GenericData.Record(recordSchema);
  expected.put("aString", "triangle");
  expected.put("anArray", Lists.newArrayList(null, 1, 2, 3, 4));
  Assert.assertEquals("Should convert to record",
      expected, convertGeneric(datum, recordSchema));
}
 
@Override
public Schema getMakeRowSchema(boolean isDynamic) {
    SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
            .name("Id").type(AvroUtils._string()).noDefault() //
            .name("Name").type(AvroUtils._string()).noDefault() //
            .name("ShippingStreet").type(AvroUtils._string()).noDefault() //
            .name("ShippingPostalCode").type(AvroUtils._int()).noDefault() //
            .name("BillingStreet").type(AvroUtils._string()).noDefault() //
            .name("BillingState").type(AvroUtils._string()).noDefault() //
            .name("BillingPostalCode").type(AvroUtils._string()).noDefault();
    if (isDynamic) {
        fa = fa.name("ShippingState").type(AvroUtils._string()).noDefault();
    }

    return fa.endRecord();
}
 
源代码10 项目: components   文件: GoogleDriveDeleteProperties.java
public void setupProperties() {
    super.setupProperties();

    Schema schema = SchemaBuilder.builder().record(GoogleDriveDeleteDefinition.COMPONENT_NAME).fields() //
            .name(GoogleDriveDeleteDefinition.RETURN_FILE_ID)//
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//
            .type().nullable().stringType().noDefault() //
            .endRecord();
    schema.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
    schemaMain.schema.setValue(schema);

    deleteMode.setPossibleValues(AccessMethod.values());
    deleteMode.setValue(AccessMethod.Name);
    file.setValue("");
    useTrash.setValue(true);
}
 
源代码11 项目: components   文件: SnowflakeRuntimeIT.java
public Schema getMakeRowSchema() {
    SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
            .name("ID").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "ID").type(AvroUtils._decimal()).noDefault() //
            .name("C1").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C1").type().nullable().stringType().noDefault() //
            .name("C2").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C2").type().nullable().booleanType().noDefault() //
            .name("C3").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C3").type().nullable().doubleType().noDefault() //
            // date
            .name("C4").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C4").type(AvroUtils._logicalDate()).noDefault() //
            // time
            .name("C5").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C5").type(AvroUtils._logicalTime()).noDefault() //
            // timestamp
            .name("C6").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C6").type(AvroUtils._logicalTimestamp())
            .noDefault() //
            // variant
            .name("C7").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "C7").type().nullable().stringType().noDefault();
    return fa.endRecord();
}
 
源代码12 项目: components   文件: SnowflakeReaderTest.java
@Before
public void setUp() throws Exception {
    schema = SchemaBuilder.builder().record("Schema").fields()
            .requiredString("field")
            .requiredString("column")
            .endRecord();
    schema.getField("field").addProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "field");
    schema.getField("column").addProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "column");

    TSnowflakeInputProperties tSnowflakeInputProperties = new TSnowflakeInputProperties("test");
    tSnowflakeInputProperties.setupProperties();

    tSnowflakeInputProperties.table.main.schema.setValue(schema);
    Mockito.when(snowflakeSourceMock.getRuntimeSchema(Mockito.any(SchemaResolver.class))).thenReturn(schema);
    tSnowflakeInputProperties.table.tableName.setValue("Table");
    Mockito.doCallRealMethod().when(snowflakeSourceMock).initialize(Mockito.any(), Mockito.eq(tSnowflakeInputProperties));
    snowflakeSourceMock.initialize(null, tSnowflakeInputProperties);
    snowflakeReader = new SnowflakeReader(runtimeContainerMock, snowflakeSourceMock, tSnowflakeInputProperties);
}
 
源代码13 项目: components   文件: SnowflakeRowReaderTest.java
@Before
public void setup() throws IOException, SQLException {
    source = Mockito.mock(SnowflakeRowSource.class);

    connection = Mockito.mock(Connection.class);
    Mockito.when(source.createConnection(Mockito.any())).thenReturn(connection);
    Mockito.doNothing().when(source).closeConnection(Mockito.any(), Mockito.any(Connection.class));
    properties = new TSnowflakeRowProperties("rowProperties");
    schema = SchemaBuilder.builder().record("test").fields().requiredString("name").endRecord();
    query = "SELECT id, name from " + TABLE_NAME;
    properties.query.setValue(query);
    properties.schemaFlow.schema.setValue(schema);
    properties.setupProperties();
    properties.table.tableName.setValue(TABLE_NAME);
    Mockito.when(source.getRowProperties()).thenReturn(properties);
    Mockito.when(source.getRuntimeSchema(null)).thenReturn(schema);
    reader = new SnowflakeRowReader(null, source);
    Mockito.doCallRealMethod().when(source).getQuery();
}
 
源代码14 项目: components   文件: RootSchemaUtilsTest.java
/**
 * Checks {@link RootSchemaUtils#getMainSchema(Schema)} returns correct Main schema retrieved from incoming
 * Root schema
 */
@Test
public void testGetMainSchema() {
    Schema mainSchema = SchemaBuilder.builder().record("Main").fields() //
            .name("id").type().intType().noDefault() //
            .endRecord(); //

    Schema outOfBandSchema = SchemaBuilder.builder().record("EmptySchema").fields().endRecord(); //$NON-NLS-1$

    Schema rootSchema = SchemaBuilder.record("Root").fields() //$NON-NLS-1$
            .name("Main").type(mainSchema).noDefault() // $NON-NLS-1$
            .name("OutOfBand").type(outOfBandSchema).noDefault() // $NON-NLS-1$
            .endRecord(); //

    Schema actualMainSchema = RootSchemaUtils.getMainSchema(rootSchema);
    assertEquals(mainSchema, actualMainSchema);
}
 
源代码15 项目: envelope   文件: TestAvroUtils.java
@Test
public void toDataTypeRecordNested() {
  Schema inner = SchemaBuilder.record("inner").fields()
      .name("field1").type().intType().noDefault()
      .endRecord();

  Schema outer = SchemaBuilder.record("outer").fields()
      .name("inner").type(inner).noDefault()
      .endRecord();

  assertEquals("Invalid DataType",
      DataTypes.createStructType(Lists.newArrayList(
        // Outer
        DataTypes.createStructField("inner",
          // Inner
          DataTypes.createStructType(Lists.newArrayList(
            DataTypes.createStructField("field1", DataTypes.IntegerType, false)
          )), false))
      ),
      AvroUtils.dataTypeFor(outer));
}
 
@Test(expected = InvalidPiiAnnotationException.class)
public void addPiiToExistingFieldFails() throws Exception {
  Schema newSchema = SchemaBuilder
      .record("r")
      .fields()
      .name("f")
      .prop("sensitivity", "PII")
      .type(SchemaBuilder.builder().stringType())
      .noDefault()
      .endRecord();

  Schema currentSchema = SchemaBuilder
      .record("r")
      .fields()
      .name("f")
      .type(SchemaBuilder.builder().stringType())
      .noDefault()
      .endRecord();
  client.registerSchema("road1", currentSchema);
  client.registerSchema("road1", newSchema);
}
 
源代码17 项目: components   文件: MarketoInputReaderTestIT.java
@Test
public void testCustomObjectDynamicSchema() throws Exception {
    TMarketoInputProperties props = getRESTProperties();
    String coName = "smartphone_c";
    String brand = "Apple";
    String models = "iPhone 7";
    props.inputOperation.setValue(CustomObject);
    props.customObjectAction.setValue(CustomObjectAction.get);
    props.batchSize.setValue(1);
    props.afterCustomObjectAction();
    props.customObjectName.setValue(coName);
    props.customObjectFilterType.setValue("model");
    props.customObjectFilterValues.setValue(models);
    Schema design = SchemaBuilder.builder().record("test").prop(SchemaConstants.INCLUDE_ALL_FIELDS, "true").fields()
            .endRecord();
    design.addProp(SchemaConstants.INCLUDE_ALL_FIELDS, "true");
    props.schemaInput.schema.setValue(design);
    reader = getReader(props);
    assertTrue(reader.start());
    IndexedRecord r = reader.getCurrent();
    assertNotNull(r);
    assertTrue(r.getSchema().getFields().size() > 6);
    assertFalse(reader.advance());
}
 
@Test
public void shouldCleanUpInternalTopicSchemasFromSchemaRegistry() throws Exception {
  final List<QueryMetadata> queries
      = ksqlEngine.buildMultipleQueries(
      "create stream s1  with (value_format = 'avro') as select * from test1;"
      + "create table t1 as select col1, count(*) from s1 group by col1;",
      Collections.emptyMap());
  Schema schema = SchemaBuilder
      .record("Test").fields()
      .name("clientHash").type().fixed("MD5").size(16).noDefault()
      .endRecord();
  ksqlEngine.getSchemaRegistryClient().register
      ("_confluent-ksql-default_query_CTAS_T1-KSTREAM-AGGREGATE-STATE-STORE-0000000006"
       + "-changelog-value", schema);
  ksqlEngine.getSchemaRegistryClient().register("_confluent-ksql-default_query_CTAS_T1-KSTREAM-AGGREGATE-STATE-STORE-0000000006-repartition-value", schema);

  assertThat(schemaRegistryClient.getAllSubjects().contains("_confluent-ksql-default_query_CTAS_T1-KSTREAM-AGGREGATE-STATE-STORE-0000000006-changelog-value"), equalTo(true));
  assertThat(schemaRegistryClient.getAllSubjects().contains("_confluent-ksql-default_query_CTAS_T1-KSTREAM-AGGREGATE-STATE-STORE-0000000006-repartition-value"), equalTo(true));
  ksqlEngine.terminateQuery(new QueryId("CTAS_T1"), true);
  assertThat(schemaRegistryClient.getAllSubjects().contains("_confluent-ksql-default_query_CTAS_T1-KSTREAM-AGGREGATE-STATE-STORE-0000000006-changelog-value"), equalTo(false));
  assertThat(schemaRegistryClient.getAllSubjects().contains("_confluent-ksql-default_query_CTAS_T1-KSTREAM-AGGREGATE-STATE-STORE-0000000006-repartition-value"), equalTo(false));
}
 
源代码19 项目: kite   文件: TestSchemaManager.java
@Test(expected = IncompatibleSchemaException.class)
public void testIndirectIncompatibleUpdate() {
  SchemaManager manager = SchemaManager.create(getConfiguration(), testDirectory);

  // Write two schemas that are compatible since they use optional fields.
  manager.writeSchema(SchemaBuilder.record("test")
      .fields()
      .optionalString("foo")
      .endRecord());

  manager.writeSchema(SchemaBuilder.record("test")
      .fields()
      .optionalString("bar")
      .endRecord());

  // This schema creates a schema compatible with the immediately previous
  // version, but incompatible with the original.
  manager.writeSchema(SchemaBuilder.record("test")
      .fields()
      .optionalInt("foo")
      .endRecord());
}
 
源代码20 项目: presto   文件: TestAvroDecoder.java
@Test
public void testMapOfMapsWithNulls()
{
    Schema schema = SchemaBuilder.map()
            .values()
            .nullable().map()
            .values()
            .nullable().floatType();

    Map<String, Map<String, Float>> data = buildMapFromKeysAndValues(ImmutableList.of("k1", "k2", "k3"),
            Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("key1", "key2", "key3"), ImmutableList.of(1.3F, 2.3F, -.5F)),
                    null,
                    buildMapFromKeysAndValues(ImmutableList.of("key10", "key20", "key30"), Arrays.asList(11.3F, null, -1.5F))));
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", MAP_OF_REAL_MAP_TYPE, "map_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "map_field", schema.toString(), data);
    checkMapValue(decodedRow, row, data);
}
 
源代码21 项目: components   文件: MarketoConstants.java
public static Schema getListOperationFlowRESTSchema() {
    return SchemaBuilder.builder().record("REST").fields() //
            .name(FIELD_LIST_ID)//
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//
            .type().nullable().intType().noDefault() //
            .name(FIELD_LEAD_ID)//
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//
            .type().nullable().intType().noDefault() //
            .name(FIELD_STATUS)//
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//
            .type().nullable().stringType().noDefault() //
            .endRecord();
}
 
源代码22 项目: iceberg   文件: TestSchemaConversions.java
@Test
public void testList() {
  Type list = Types.ListType.ofRequired(34, Types.UUIDType.get());
  Schema schema = addElementId(34, SchemaBuilder.array().items(
      LogicalTypes.uuid().addToSchema(Schema.createFixed("uuid_fixed", null, null, 16))));

  Assert.assertEquals("Avro schema to list",
      list, AvroSchemaUtil.convert(schema));
  Assert.assertEquals("List to Avro schema",
      schema, AvroSchemaUtil.convert(list));
}
 
源代码23 项目: parquet-mr   文件: TestReflectLogicalTypes.java
@Test
public void testWriteUUIDArrayWithParquetUUID() throws IOException {
  Schema uuidArraySchema = SchemaBuilder.record(RecordWithUUIDArray.class.getName())
      .fields()
      .name("uuids").type().array().items().stringType().noDefault()
      .endRecord();
  LogicalTypes.uuid().addToSchema(
      uuidArraySchema.getField("uuids").schema().getElementType());

  Schema stringArraySchema = SchemaBuilder.record("RecordWithUUIDArray")
      .fields()
      .name("uuids").type().array().items().stringType().noDefault()
      .endRecord();
  LogicalTypes.uuid().addToSchema(
      stringArraySchema.getField("uuids").schema().getElementType());
  stringArraySchema.getField("uuids").schema()
      .addProp(SpecificData.CLASS_PROP, List.class.getName());

  UUID u1 = UUID.randomUUID();
  UUID u2 = UUID.randomUUID();

  GenericRecord expected = new GenericData.Record(stringArraySchema);
  List<String> uuids = new ArrayList<String>();
  uuids.add(u1.toString());
  uuids.add(u2.toString());
  expected.put("uuids", uuids);

  RecordWithUUIDArray r = new RecordWithUUIDArray();
  r.uuids = new UUID[] {u1, u2};

  File test = write(AvroTestUtil.conf(AvroWriteSupport.WRITE_PARQUET_UUID, true), REFLECT, uuidArraySchema, r);

  Assert.assertEquals("Should read UUIDs as Strings",
      expected,
      read(ReflectData.get(), stringArraySchema, test).get(0));
}
 
源代码24 项目: secor   文件: SecorSchemaRegistryClientTest.java
@Test
public void testDecodeMessage() {
    Schema schemaV1 = SchemaBuilder.record("Foo")
            .fields()
            .name("data_field_1").type().intType().noDefault()
            .name("timestamp").type().longType().noDefault()
            .endRecord();
    //backward compatible schema change
    Schema schemaV2 = SchemaBuilder.record("Foo")
            .fields()
            .name("data_field_1").type().intType().noDefault()
            .name("data_field_2").type().stringType().noDefault()
            .name("timestamp").type().longType().noDefault()
            .endRecord();
    GenericRecord record1 = new GenericRecordBuilder(schemaV1)
            .set("data_field_1", 1)
            .set("timestamp", 1467176315L)
            .build();
    GenericRecord record2 = new GenericRecordBuilder(schemaV2)
            .set("data_field_1", 1)
            .set("data_field_2", "hello")
            .set("timestamp", 1467176316L)
            .build();
    GenericRecord output = secorSchemaRegistryClient.deserialize("test-avr-topic", avroSerializer.serialize("test-avr-topic", record1));
    assertEquals(secorSchemaRegistryClient.getSchema("test-avr-topic"), schemaV1);
    assertEquals(output.get("data_field_1"), 1);
    assertEquals(output.get("timestamp"), 1467176315L);

    output = secorSchemaRegistryClient.deserialize("test-avr-topic", avroSerializer.serialize("test-avr-topic", record2));
    assertEquals(secorSchemaRegistryClient.getSchema("test-avr-topic"), schemaV2);
    assertEquals(output.get("data_field_1"), 1);
    assertTrue(StringUtils.equals((output.get("data_field_2")).toString(), "hello"));
    assertEquals(output.get("timestamp"), 1467176316L);

    output = secorSchemaRegistryClient.deserialize("test-avr-topic", new byte[0]);
    assertNull(output);
}
 
private Schema createDecimalSchema() {
    return SchemaBuilder.builder().record("main").fields()
            .name("dec")
            .prop(SchemaConstants.TALEND_COLUMN_DB_LENGTH, "10")
            .prop(SchemaConstants.TALEND_COLUMN_PRECISION, "2")
            .type(Schema.createUnion(AvroUtils._decimal(), Schema.create(Schema.Type.NULL)))
            .noDefault()

            .endRecord();
}
 
源代码26 项目: components   文件: TypeConverterUtilsTest.java
@Test
public void testCopyFieldsValues() {
    Schema intSchema = SchemaBuilder.record("intSchema").fields().name("a").type().intType().noDefault().endRecord();
    GenericRecord intRecord = new GenericRecordBuilder(intSchema).set("a", 1).build();

    Schema stringSchema = SchemaBuilder.record("intSchema").fields().name("a").type().stringType().noDefault().endRecord();
    GenericRecordBuilder stringRecordBuilder = new GenericRecordBuilder(stringSchema).set("a", "s");
    TypeConverterUtils.copyFieldsValues(intRecord, stringRecordBuilder);
    GenericRecord stringRecord = stringRecordBuilder.build();
    Assert.assertEquals(intRecord.get("a"), stringRecord.get("a"));
}
 
源代码27 项目: components   文件: MarketoCompanyClientTestIT.java
@Before
public void setUp() throws Exception {
    iprops = new TMarketoInputProperties("test");
    iprops.connection.setupProperties();
    iprops.connection.endpoint.setValue(ENDPOINT_REST);
    iprops.connection.clientAccessId.setValue(USERID_REST);
    iprops.connection.secretKey.setValue(SECRETKEY_REST);
    iprops.schemaInput.setupProperties();
    iprops.mappingInput.setupProperties();
    iprops.setupProperties();
    iprops.includeTypes.setupProperties();
    iprops.includeTypes.type.setValue(new ArrayList<String>());
    iprops.excludeTypes.setupProperties();
    iprops.excludeTypes.type.setValue(new ArrayList<String>());
    iprops.connection.setupLayout();
    iprops.schemaInput.setupLayout();
    iprops.setupLayout();
    iprops.batchSize.setValue(300);
    //
    oprops = new TMarketoOutputProperties("test");
    oprops.connection.setupProperties();
    oprops.connection.endpoint.setValue(ENDPOINT_REST);
    oprops.connection.clientAccessId.setValue(USERID_REST);
    oprops.connection.secretKey.setValue(SECRETKEY_REST);
    oprops.schemaInput.setupProperties();
    oprops.setupProperties();
    oprops.connection.setupLayout();
    oprops.schemaInput.setupLayout();
    oprops.setupLayout();
    //
    s = SchemaBuilder.record("sn").fields().name("externalCompanyId").type().stringType().noDefault() //
            .name("company").type().stringType().noDefault()//
            .name("website").type().intType().noDefault()//
            .name("numberOfEmployees").type().intType().noDefault()//
            .endRecord();
}
 
@Test
public void schemaDoesNotContainReservedColumnName() throws Exception {
  Schema schema = SchemaBuilder.record("r").fields().name("f").type().stringType().noDefault().endRecord();
  try {
    DataHighwaySchemaValidator.validate(schema, DISALLOW_NON_NULLABLE_UNIONS);
  } catch (SchemaValidationException e) {
    fail();
  }
}
 
源代码29 项目: components   文件: TAzureStorageListProperties.java
@Override
public void setupProperties() {
    super.setupProperties();

    Schema s = SchemaBuilder.record("Main").fields().name("BlobName").prop(SchemaConstants.TALEND_COLUMN_DB_LENGTH, "300")// $NON-NLS-3$
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//$NON-NLS-1$
            .type(AvroUtils._string()).noDefault().endRecord();
    schema.schema.setValue(s);
}
 
@Test(expected = IllegalArgumentException.class)
public void threeTypesInUnion() throws SchemaValidationException {
  Schema union = SchemaBuilder.unionOf().intType().and().longType().and().nullType().endUnion();
  Schema schema = SchemaBuilder.record("r").fields().name("f").type(union).noDefault().endRecord();

  DataHighwaySchemaValidator.validate(schema, DISALLOW_NON_NULLABLE_UNIONS);
}