@Override public Schema getSchema() { return SchemaBuilder.unionOf().array().prop(SchemaConstants.JAVA_CLASS_FLAG, getDatumClass().getCanonicalName()).items() .fixed("Inet4").size(4).and().fixed("Inet6").size(16).endUnion(); }
/** * Create a builder for an Avro fixed type with the specified name and size. * This is equivalent to: * <pre> * builder().fixed(name); * </pre> * @param name the fixed name */ public static FixedBuilder<Schema> fixed(String name) { return builder().fixed(name); }
/** * Checks {@link RootSchemaUtils#getMainSchema(Schema)} throws {@link IllegalArgumentException} in case of * not Root schema is passed with following message "Input schema should be Root schema" */ @Test public void testGetMainSchemaIllegalArgumentException() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Input schema should be Root schema"); Schema notRoot = SchemaBuilder.builder().fixed("Root").size(16); RootSchemaUtils.getMainSchema(notRoot); }
/** * Checks {@link RootSchemaUtils#getOutOfBandSchema(Schema)} throws {@link IllegalArgumentException} in case of * not Root schema is passed with following message "Input schema should be Root schema" */ @Test public void testGetOutOfBandSchemaIllegalArgumentException() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Input schema should be Root schema"); Schema notRoot = SchemaBuilder.builder().fixed("Root").size(16); RootSchemaUtils.getMainSchema(notRoot); }
/** * Checks {@link RootSchemaUtils#isRootSchema(Schema)} returns <code>false</code>, when not Root schema is passed * Schema has correct name, but it's type is not {@link Type#RECORD} */ @Test public void testIsRootSchemaRootWithWrongType() { Schema wrongTypeSchema = SchemaBuilder.builder().fixed("Root").size(16); // boolean actual = RootSchemaUtils.isRootSchema(wrongTypeSchema); assertFalse(actual); }
/** * Create a builder for an Avro fixed type with the specified name and size. * This is equivalent to: * <pre> * builder().fixed(name); * </pre> * @param name the fixed name */ public static FixedBuilder<Schema> fixed(String name) { return builder().fixed(name); }
/** * Create a builder for an Avro fixed type with the specified name and size. * This is equivalent to: * <pre> * builder().fixed(name); * </pre> * @param name the fixed name */ public static FixedBuilder<Schema> fixed(String name) { return builder().fixed(name); }
@Test public void testFixedDefaultValueDrop() { Schema md5 = SchemaBuilder.builder().fixed("MD5").size(16); Schema frec = SchemaBuilder.builder().record("test") .fields().name("hash").type(md5).withDefault(new byte[16]).endRecord(); Schema.Field field = frec.getField("hash"); Assert.assertNotNull(field.defaultVal()); Assert.assertArrayEquals(new byte[16], (byte[]) field.defaultVal()); }
/** * Create a builder for an Avro fixed type with the specified name and size. * This is equivalent to: * <pre> * builder().fixed(name); * </pre> * @param name the fixed name */ public static FixedBuilder<Schema> fixed(String name) { return builder().fixed(name); }