/** If this is a record, enum or fixed, returns its namespace-qualified name, * otherwise returns the name of the primitive type. */ public String getFullName() { return getName(); }
private String getNestedClassName(Schema schema) { String namespace = schema.getNamespace(); String name = schema.getName(); if (namespace == null || "".equals(namespace)) return name; return namespace + "$" + name; }
/** Returns the Java class name indicated by a schema's name and namespace. */ public static String getClassName(Schema schema) { String namespace = schema.getNamespace(); String name = schema.getName(); if (namespace == null || "".equals(namespace)) return name; String dot = namespace.endsWith("$") ? "" : "."; // back-compatibly handle $ return namespace + dot + name; }
@Override public String getFingerprint(Schema schema) { final String subject = schema.getName(); final int guid; try { guid = theClient.register(subject, schema); } catch (IOException | RestClientException e) { throw new RuntimeException(e); } return Integer.toString(guid); }
private void print(Schema schema, File outputDirectory, boolean pretty) throws FileNotFoundException { String dirpath = outputDirectory.getAbsolutePath(); String filename = dirpath + "/" + schema.getName() + ".avsc"; FileOutputStream fileOutputStream = new FileOutputStream(filename); PrintStream printStream = new PrintStream(fileOutputStream); printStream.println(schema.toString(pretty)); printStream.close(); }
/** * 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())); }
/** * Use the name field of {@link #schema} to partition path */ @Override protected String getPartitionedFileName(State properties, String originalFileName) { Schema schema = this.getSchema(); if (schema != null) { return new Path(schema.getName(), originalFileName).toString(); } else { return originalFileName; } }
@Override public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException { Preconditions.checkArgument(inputSchema.getFields().equals(gobblinTrackingEventSchema.getFields())); Schema outputSchema = Schema .createRecord(ConfigUtils.getString(config, NEW_SCHEMA_NAME, inputSchema.getName()), inputSchema.getDoc(), inputSchema.getNamespace(), inputSchema.isError()); outputSchema.setFields(newFields); return outputSchema; }
/** * Convert a raw value to an Avro object to serialize in Avro type system, using the provided character set when necessary. * The counter-part method which reads an Avro object back to a raw value is {@link #normalizeValue(Object, Schema, String)}. */ public static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema, final Charset charset) { return convertToAvroObject(rawValue, fieldSchema, fieldSchema.getName(), charset); }
@Override public SchemaVisitorAction visitNonTerminal(final Schema nt) { Schema.Type type = nt.getType(); if (type == RECORD) { Schema newSchema = Schema.createRecord(nt.getName(), copyDocs ? nt.getDoc() : null, nt.getNamespace(), nt.isError()); copyProperties.copy(nt, newSchema); replace.put(nt, newSchema); } return SchemaVisitorAction.CONTINUE; }
@Override public Integer register(Schema schema) throws SchemaRegistryException { return register(schema, schema.getName()); }
@Override public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException { List<Field> outputSchemaFields = new ArrayList<>(); for (Field field : inputSchema.getFields()) { outputSchemaFields.add(convertFieldSchema(inputSchema, field, workUnit)); } Schema outputSchema = Schema .createRecord(inputSchema.getName(), inputSchema.getDoc(), inputSchema.getNamespace(), inputSchema.isError()); outputSchema.setFields(outputSchemaFields); return outputSchema; }
private String processHeaderTemplate(String templateName, Schema schema, String namespace) { VelocityContext context = new VelocityContext(); context.put("record_name", StyleUtils.toLowerUnderScore(schema.getName())); context.put("namespace", namespace); return generateSourceFromTemplate(TEMPLATE_DIR + File.separator + templateName, context); }
@Override protected List<Tag<?>> getTagsForMetrics() { List<Tag<?>> tags = super.getTagsForMetrics(); tags.add(new Tag<>(RuntimeMetrics.SCHEMA, this.schema.getName())); return tags; }
@Override protected void customizeRecordFields(Schema recordSchema, List<Field> fields) { super.customizeRecordFields(recordSchema, fields); if (eventClassTypes.contains(recordSchema.getName())) { int index = getFieldIndex(fields, RECORD_NAMESPACE); if (index > -1) { fields.add(index + 1, createClassTypeField()); } } }
@Override protected void customizeFieldSchema(Schema fieldSchema, GenericRecord fieldType) { if (eventClassTypes.contains(fieldType.getSchema().getName())) { GenericData.EnumSymbol classType = (GenericData.EnumSymbol) fieldType.get(CLASS_TYPE); if (classType != null) { fieldSchema.addProp(CLASS_TYPE, classType.toString().toLowerCase()); } else { fieldSchema.addProp(CLASS_TYPE, OBJECT.toLowerCase()); } } }
@Override protected void customizeFieldSchema(Schema fieldSchema, GenericRecord fieldType) { if (fieldType != null && fieldType.getSchema().getName().equals(RECORD_FIELD_TYPE)) { Boolean addressable = (Boolean) fieldType.get(ADDRESSABLE); if (addressable != null && !addressable) { fieldSchema.addProp(ADDRESSABLE, BooleanNode.getFalse()); } } }
public static RecordSchema createSchema(final Schema avroSchema, final boolean includeText) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build(); return createSchema(avroSchema, includeText ? avroSchema.toString() : null, identifier); }