org.apache.avro.generic.GenericEnumSymbol Java Examples
The following examples show how to use
org.apache.avro.generic.GenericEnumSymbol.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroColumnDecoder.java From presto with Apache License 2.0 | 6 votes |
private static Slice getSlice(Object value, Type type, String columnName) { if (type instanceof VarcharType && (value instanceof CharSequence || value instanceof GenericEnumSymbol)) { return truncateToLength(utf8Slice(value.toString()), type); } if (type instanceof VarbinaryType) { if (value instanceof ByteBuffer) { return Slices.wrappedBuffer((ByteBuffer) value); } else if (value instanceof GenericFixed) { return Slices.wrappedBuffer(((GenericFixed) value).bytes()); } } throw new PrestoException(DECODER_CONVERSION_NOT_SUPPORTED, format("cannot decode object of '%s' as '%s' for column '%s'", value.getClass(), type, columnName)); }
Example #2
Source File: AvroTupleWrapper.java From spork with Apache License 2.0 | 6 votes |
public static Object unionResolver(Object o) { if (o instanceof org.apache.avro.util.Utf8) { return o.toString(); } else if (o instanceof IndexedRecord) { return new AvroTupleWrapper<IndexedRecord>((IndexedRecord) o); } else if (o instanceof GenericArray) { return new AvroBagWrapper<GenericData.Record>( (GenericArray<GenericData.Record>) o); } else if (o instanceof Map) { return new AvroMapWrapper((Map<CharSequence, Object>) o); } else if (o instanceof GenericData.Fixed) { return new DataByteArray(((GenericData.Fixed) o).bytes()); } else if (o instanceof ByteBuffer) { return new DataByteArray(((ByteBuffer) o).array()); } else if (o instanceof GenericEnumSymbol) { return o.toString(); } else { return o; } }
Example #3
Source File: AvroDecoderTestUtil.java From presto with Apache License 2.0 | 5 votes |
public static void checkPrimitiveValue(Object actual, Object expected) { if (actual == null || expected == null) { assertNull(expected); assertNull(actual); } else if (actual instanceof CharSequence) { assertTrue(expected instanceof CharSequence || expected instanceof GenericEnumSymbol); assertEquals(actual.toString(), expected.toString()); } else if (actual instanceof SqlVarbinary) { if (expected instanceof GenericFixed) { assertEquals(((SqlVarbinary) actual).getBytes(), ((GenericFixed) expected).bytes()); } else if (expected instanceof ByteBuffer) { assertEquals(((SqlVarbinary) actual).getBytes(), ((ByteBuffer) expected).array()); } else { fail(format("Unexpected value type %s", actual.getClass())); } } else if (isIntegralType(actual) && isIntegralType(expected)) { assertEquals(((Number) actual).longValue(), ((Number) expected).longValue()); } else if (isRealType(actual) && isRealType(expected)) { assertEquals(((Number) actual).doubleValue(), ((Number) expected).doubleValue()); } else { assertEquals(actual, expected); } }
Example #4
Source File: GeneratorFunctions.java From components with Apache License 2.0 | 5 votes |
public GenericEnumSymbol apply(GeneratorContext input) { if (constants == null) { if (schema == null) { schema = new Schema.Parser().parse(jsonSchema); } constants = new GenericEnumSymbol[schema.getEnumSymbols().size()]; for (int i = 0; i < constants.length; i++) { constants[i] = new GenericData.EnumSymbol(schema, schema.getEnumSymbols().get(i)); } } return constants[input.getRandom().nextInt(constants.length)]; }
Example #5
Source File: Generator.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 4 votes |
private GenericEnumSymbol generateEnumSymbol(Schema schema) { List<String> enums = schema.getEnumSymbols(); return new GenericData.EnumSymbol(schema, enums.get(random.nextInt(enums.size()))); }
Example #6
Source File: AvroRandomDataGenerator.java From avro-util with BSD 2-Clause "Simplified" License | 4 votes |
private GenericEnumSymbol generateEnumSymbol(Schema schema) { List<String> enums = schema.getEnumSymbols(); return AvroCompatibilityHelper.newEnumSymbol(schema, enums.get(random.nextInt(enums.size()))); }
Example #7
Source File: Generator.java From avro-random-generator with Do What The F*ck You Want To Public License | 4 votes |
private GenericEnumSymbol generateEnumSymbol(Schema schema) { List<String> enums = schema.getEnumSymbols(); return new GenericData.EnumSymbol(schema, enums.get(random.nextInt(enums.size()))); }