protected Class findStringClass(Schema schema) { final String name = schema.getProp(GenericData.STRING_PROP); if ("String".equals(name)) { return String.class; } return CharSequence.class; } }
public static boolean isTypeIn(Schema schema) { String prop = schema.getProp(DIRECTION_FIELD); return prop == null || prop.equalsIgnoreCase("in"); }
public static boolean isTypeOut(Schema schema) { String prop = schema.getProp(DIRECTION_FIELD); return prop == null || prop.equalsIgnoreCase("out"); }
@Override protected Object readInt(Object old, Schema s, Decoder in) throws IOException { String type = s.getProp(ThriftData.THRIFT_PROP); int value = in.readInt(); if (type != null) { if ("byte".equals(type)) return (byte)value; if ("short".equals(type)) return (short)value; } return value; }
/** * get the unresolved schema name. * * @param schema * @return */ static String getUnresolvedSchemaName(final Schema schema) { if (!isUnresolvedSchema(schema)) { throw new IllegalArgumentException("Not a unresolved schema: " + schema); } return schema.getProp(UR_SCHEMA_ATTR); }
@Override protected Object newArray(Object old, int size, Schema schema) { if ("set".equals(schema.getProp(ThriftData.THRIFT_PROP))) { if (old instanceof Set) { ((Set) old).clear(); return old; } return new HashSet(); } else { return super.newArray(old, size, schema); } }
public Reference(Schema schema) { super(REFERENCE); this.refFieldName = schema.getProp(REF_FIELD_NAME); }
public Referenceable(Schema schema) { super(REFERENCEABLE); this.idFieldName = schema.getProp(ID_FIELD_NAME); }
@Override protected Object readInt(Object old, Schema expected, Decoder in) throws IOException { Object value = in.readInt(); String intClass = expected.getProp(SpecificData.CLASS_PROP); if (Byte.class.getName().equals(intClass)) value = ((Integer)value).byteValue(); else if (Short.class.getName().equals(intClass)) value = ((Integer)value).shortValue(); else if (Character.class.getName().equals(intClass)) value = ((Character)(char)(int)(Integer)value); return value; }
@Override protected Object readInt(Object old, Schema expected, Decoder in) throws IOException { Object value = in.readInt(); String intClass = expected.getProp(SpecificData.CLASS_PROP); if (Byte.class.getName().equals(intClass)) value = ((Integer)value).byteValue(); else if (Short.class.getName().equals(intClass)) value = ((Integer)value).shortValue(); else if (Character.class.getName().equals(intClass)) value = ((Character)(char)(int)(Integer)value); return value; }
static Class getClassProp(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; Class c = CLASS_CACHE.get(name); if (c != null) return c; try { c = ClassUtils.forName(name); CLASS_CACHE.put(name, c); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } return c; }
static Class getClassProp(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; Class c = CLASS_CACHE.get(name); if (c != null) return c; try { c = ClassUtils.forName(name); CLASS_CACHE.put(name, c); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } return c; }
/** Determines the class to used to represent a string Schema. By default * uses {@link GenericData#STRING_PROP} to determine whether {@link Utf8} or * {@link String} is used. Subclasses may override for alternate * representations. */ protected Class findStringClass(Schema schema) { String name = schema.getProp(GenericData.STRING_PROP); if (name == null) return CharSequence.class; switch (GenericData.StringType.valueOf(name)) { case String: return String.class; default: return CharSequence.class; } }
/** * Is this a unresolved schema. * * @param schema * @return */ static boolean isUnresolvedSchema(final Schema schema) { return (schema.getType() == Schema.Type.RECORD && schema.getProp(UR_SCHEMA_ATTR) != null && UR_SCHEMA_NAME.equals(schema.getName()) && UR_SCHEMA_NS.equals(schema.getNamespace())); }
private Class getPropAsClass(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; try { return ClassUtils.forName(getData().getClassLoader(), name); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } }
private Class getPropAsClass(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; try { return ClassUtils.forName(getData().getClassLoader(), name); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } }
private static void checkProp(Schema s0) throws Exception { if(s0.getType().equals(Schema.Type.UNION)) return; // unions have no props assertNull(s0.getProp("foo")); Schema s1 = Schema.parse(s0.toString()); s1.addProp("foo", "bar"); assertEquals("bar", s1.getProp("foo")); assertNotEquals(s0, s1); Schema s2 = Schema.parse(s1.toString()); assertEquals("bar", s2.getProp("foo")); assertEquals(s1, s2); assertNotEquals(s0, s2); }
@Test public void testComplexProp() { String json = "{\"type\":\"null\", \"foo\": [0]}"; Schema s = Schema.parse(json); assertNull(s.getProp("foo")); }
@Test public void testR10() throws Exception { Schema r10Schema = ReflectData.get().getSchema(R10.class); assertEquals(Schema.Type.STRING, r10Schema.getType()); assertEquals(R10.class.getName(), r10Schema.getProp("java-class")); checkReadWrite(new R10("foo"), r10Schema); }
@Test public void testProps() { Schema s = SchemaBuilder.builder().intBuilder() .prop("p1", "v1") .prop("p2", "v2") .prop("p2", "v2real") // overwrite .endInt(); int size = s.getObjectProps().size(); Assert.assertEquals(2, size); Assert.assertEquals("v1", s.getProp("p1")); Assert.assertEquals("v2real", s.getProp("p2")); }