public IntegerStore(String name, KeyValueTable kvTable) throws UnsupportedTypeException { super(name, kvTable, new TypeRepresentation(Integer.class), new ReflectionSchemaGenerator().generate(Integer.class)); }
@Override protected Schema generateRecord(TypeToken<?> typeToken, Set<String> knowRecords, boolean acceptRecursion) throws UnsupportedTypeException { String recordName = typeToken.getRawType().getName(); Map<String, TypeToken<?>> recordFieldTypes = typeToken.getRawType().isInterface() ? collectByMethods(typeToken, new TreeMap<>()) : collectByFields(typeToken, new TreeMap<>()); // Recursively generate field type schema. List<Schema.Field> fields = new ArrayList<>(); for (Map.Entry<String, TypeToken<?>> fieldType : recordFieldTypes.entrySet()) { Set<String> records = new HashSet<>(knowRecords); records.add(recordName); Schema fieldSchema = doGenerate(fieldType.getValue(), records, acceptRecursion); if (!fieldType.getValue().getRawType().isPrimitive()) { boolean isNotNull = typeToken.getRawType().isAnnotationPresent(Nonnull.class); boolean isNull = typeToken.getRawType().isAnnotationPresent(Nullable.class); // For non-primitive, allows "null" value // i) if it is nullable by default and notnull annotation is not present // ii) if it is not nullable by default and nullable annotation is present if ((isNullableByDefault && !isNotNull) || (!isNullableByDefault && isNull)) { fieldSchema = Schema.unionOf(fieldSchema, Schema.of(Schema.Type.NULL)); } } fields.add(Schema.Field.of(fieldType.getKey(), fieldSchema)); } return Schema.recordOf(recordName, Collections.unmodifiableList(fields)); }
/** * Create a hive schema from the given type using reflection. * * @param type type of class to derive the schema from. * @return hive schema that can be used in a create statement. * @throws UnsupportedTypeException if there is an unsupported type. */ public String toHiveSchema(Type type) throws UnsupportedTypeException { // false is to disallow recursive schemas, which hive can't handle return toHiveSchema(schemaGenerator.generate(type, false)); }
ArtifactInspector(CConfiguration cConf, ArtifactClassLoaderFactory artifactClassLoaderFactory) { this.cConf = cConf; this.artifactClassLoaderFactory = artifactClassLoaderFactory; this.schemaGenerator = new ReflectionSchemaGenerator(false); }
/** * Create a hive schema from the given type using reflection. * * @param type type of class to derive the schema from. * @return hive schema that can be used in a create statement. * @throws UnsupportedTypeException if there is an unsupported type. */ public String toHiveSchema(Type type) throws UnsupportedTypeException { // false is to disallow recursive schemas, which hive can't handle return toHiveSchema(schemaGenerator.generate(type, false)); }
ArtifactInspector(CConfiguration cConf, ArtifactClassLoaderFactory artifactClassLoaderFactory) { this.cConf = cConf; this.artifactClassLoaderFactory = artifactClassLoaderFactory; this.schemaGenerator = new ReflectionSchemaGenerator(false); }
private <T> Schema getSchema(TypeToken<T> type) throws UnsupportedTypeException { return new ReflectionSchemaGenerator().generate(type.getType()); }
Schema configSchema = configType == Config.class ? null : schemaGenerator.generate(configType); builder.addApp(new ApplicationClass(mainClassName, "", configSchema)); } catch (ClassNotFoundException e) {
/** * Constructor with hit for handling type. */ public LocalArtifactLoaderStage(CConfiguration cConf, Store store, ArtifactRepository artifactRepository, Impersonator impersonator, AuthorizationEnforcer authorizationEnforcer, AuthenticationContext authenticationContext) { super(TypeToken.of(AppDeploymentInfo.class)); this.cConf = cConf; this.store = store; this.adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator()); this.artifactRepository = artifactRepository; this.impersonator = impersonator; this.authorizationEnforcer = authorizationEnforcer; this.authenticationContext = authenticationContext; }
private String hiveSchemaFor(Type type) throws UnsupportedTypeException { new ReflectionSchemaGenerator().generate(type, false); } catch (Exception e) { throw new UnsupportedTypeException("Unable to derive schema from " + type, e);
Schema configSchema = configType == Config.class ? null : schemaGenerator.generate(configType); builder.addApp(new ApplicationClass(mainClassName, "", configSchema)); } catch (ClassNotFoundException e) {
/** * Gets all consumer group configurations for the given queue. */ private static Set<ConsumerGroupConfig> getAllConsumerGroups( Program program, FlowSpecification flowSpec, QueueName queueName, Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecs) { Set<ConsumerGroupConfig> groupConfigs = Sets.newHashSet(); SchemaGenerator schemaGenerator = new ReflectionSchemaGenerator(); // Get all the consumers of this queue. for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) { String flowletId = entry.getKey(); for (QueueSpecification queueSpec : Iterables.concat(queueSpecs.column(flowletId).values())) { if (!queueSpec.getQueueName().equals(queueName)) { continue; } try { // Inspect the flowlet consumer FlowletDefinition flowletDefinition = entry.getValue(); Class<?> flowletClass = program.getClassLoader().loadClass(flowletDefinition.getFlowletSpec().getClassName()); long groupId = generateConsumerGroupId(program.getId(), flowletId); addConsumerGroup(queueSpec, flowletClass, groupId, flowletDefinition.getInstances(), schemaGenerator, groupConfigs); } catch (ClassNotFoundException e) { // There is no way for not able to load a Flowlet class as it should be verified during deployment. throw Throwables.propagate(e); } } } return groupConfigs; }
private String hiveSchemaFor(Type type) throws UnsupportedTypeException { new ReflectionSchemaGenerator().generate(type, false); } catch (Exception e) { throw new UnsupportedTypeException("Unable to derive schema from " + type, e);
Schema appConfigSchema = schemaGenerator.generate(ConfigTestApp.ConfigClass.class); ArtifactInfo actualInfo = getArtifact(configTestAppId);
return ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator()).toJson(specification);
@Test public void testCompatible() throws UnsupportedTypeException { Schema s1 = new ReflectionSchemaGenerator().generate(Node.class); Schema s2 = new ReflectionSchemaGenerator().generate(Node3.class); Schema s3 = new ReflectionSchemaGenerator().generate(Node4.class); Assert.assertNotEquals(s1, s2); Assert.assertTrue(s1.isCompatible(s2)); Assert.assertFalse(s2.isCompatible(s1)); Assert.assertTrue(s2.isCompatible(s3)); }
/** * Creates properties for {@link ObjectStore} dataset instance. * * @param type type of objects to be stored in dataset * @return {@link DatasetProperties} for the dataset * @throws UnsupportedTypeException */ public static DatasetProperties objectStoreProperties(Type type, DatasetProperties props) throws UnsupportedTypeException { Schema schema = new ReflectionSchemaGenerator().generate(type); TypeRepresentation typeRep = new TypeRepresentation(type); return DatasetProperties.builder() .add("schema", schema.toString()) .add("type", new Gson().toJson(typeRep)) .addAll(props.getProperties()) .build(); }
@Test public void testSchemaHash() throws UnsupportedTypeException { Schema s1 = new ReflectionSchemaGenerator().generate(Node.class); Schema s2 = new ReflectionSchemaGenerator().generate(Node2.class); Assert.assertEquals(s1.getSchemaHash(), s2.getSchemaHash()); Assert.assertEquals(s1, s2); Schema schema = (new ReflectionSchemaGenerator()).generate((new TypeToken<Child<Node>>() { }).getType()); Assert.assertNotEquals(s1.getSchemaHash(), schema.getSchemaHash()); }
@Test public void testGenerateSchema() throws UnsupportedTypeException { Schema schema = (new ReflectionSchemaGenerator()).generate((new TypeToken<Child<Node>>() { }).getType()); Gson gson = new GsonBuilder() .registerTypeAdapter(Schema.class, new SchemaTypeAdapter()) .create(); Assert.assertEquals(schema, gson.fromJson(gson.toJson(schema), Schema.class)); }
@Test public void testParseJson() throws IOException, UnsupportedTypeException { Schema schema = new ReflectionSchemaGenerator().generate(Node.class); Assert.assertEquals(schema, Schema.parseJson(schema.toString())); }