private static List<Schema.Field> _cloneFieldsAndResetPosition( List<Schema.Field> fields) { List<Schema.Field> copyFieldList = new ArrayList<>(); for (Schema.Field schemaEntry : fields) { Schema.Field field = new Schema.Field( schemaEntry.name(), schemaEntry.schema(), schemaEntry.doc(), schemaEntry.defaultVal(), schemaEntry.order()); Map<String, Object> objectProperties = schemaEntry.getObjectProps(); for (Map.Entry<String, Object> entry : objectProperties.entrySet()) { field.addProp(entry.getKey(), entry.getValue()); } copyFieldList.add(field); } return copyFieldList; }
designField.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
private static List<Schema.Field> cloneFieldsAndResetPosition(List<Field> fields) { List<Schema.Field> copyFieldList = new ArrayList<>(); for (Schema.Field se : fields) { Schema.Field field = new Schema.Field(se.name(), se.schema(), se.doc(), se.defaultVal(), se.order()); field.getObjectProps().putAll(se.getObjectProps()); for (Map.Entry<String, Object> entry : se.getObjectProps().entrySet()) { field.addProp(entry.getKey(), entry.getValue()); } copyFieldList.add(field); } return copyFieldList; }
recordField.addProp(meta.key(), meta.value()); for(Schema.Field f : fields) { if (f.name().equals(fieldName))
recordField.addProp(meta.key(), meta.value()); for(Schema.Field f : fields) { if (f.name().equals(fieldName))
String prop = i.next(); if (!FIELD_RESERVED.contains(prop)) f.addProp(prop, field.get(prop));
String prop = i.next(); if (!FIELD_RESERVED.contains(prop)) f.addProp(prop, field.get(prop));
String prop = i.next(); if (!FIELD_RESERVED.contains(prop)) // ignore reserved newField.addProp(prop, field.get(prop));
String prop = i.next(); if (!FIELD_RESERVED.contains(prop)) // ignore reserved newField.addProp(prop, field.get(prop));
assertEquals("bar", Schema.parse(schema.toString()) .getField("f").getProp("foo")); schema.getField("f").addProp("baz", "boo"); assertEquals("boo", schema.getField("f").getProp("baz"));
private Schema buildRecordSchema(JsonSchema schema, WorkUnitState workUnit, String name, String namespace) { List<Schema.Field> fields = new ArrayList<>(); for (int i = 0; i < schema.fieldsCount(); i++) { JsonSchema map = schema.getFieldSchemaAt(i); String childNamespace = buildNamespace(namespace, name); JsonElementConverter converter; String sourceType; Schema fldSchema; try { sourceType = map.isType(UNION) ? UNION.toString().toLowerCase() : map.getType().toString().toLowerCase(); converter = getConvertor(map, childNamespace, workUnit); this.converters.put(map.getColumnName(), converter); fldSchema = converter.schema(); } catch (UnsupportedDateTypeException e) { throw new UnsupportedOperationException(e); } Schema.Field fld = new Schema.Field(map.getColumnName(), fldSchema, map.getComment(), map.isNullable() ? JsonNodeFactory.instance.nullNode() : null); fld.addProp(SOURCE_TYPE, sourceType); fields.add(fld); } Schema avroSchema = Schema.createRecord(name.isEmpty() ? null : name, "", namespace, false); avroSchema.setFields(fields); return avroSchema; }
/** * Creates the override strategy field. * * @return the field */ private Field createOverrideStrategyField() { List<String> overrideStrategySymbols = Arrays.asList(OverrideStrategy.APPEND.name(), OverrideStrategy.REPLACE.name()); Schema overrideStrategyEnum = Schema.createEnum(OVERRIDE_STRATEGY_TYPE_NAME, null, BASE_SCHEMA_FORM_NAMESPACE, overrideStrategySymbols); Field overrideStrategyField = new Field(OVERRIDE_STRATEGY, Schema.createUnion(Arrays.asList( overrideStrategyEnum, Schema.create(Type.NULL))), null, null); overrideStrategyField.addProp(DISPLAY_NAME, "Override strategy"); JsonNodeFactory jsonFactory = JsonNodeFactory.instance; ArrayNode displayNamesNode = jsonFactory.arrayNode(); displayNamesNode.add(TextNode.valueOf("Append")); displayNamesNode.add(TextNode.valueOf("Replace")); overrideStrategyField.addProp(DISPLAY_NAMES, displayNamesNode); overrideStrategyField.addProp(DISPLAY_PROMPT, "Select array override strategy"); return overrideStrategyField; }
private Field getUuidField() { if (uuidField == null) { Schema uuidFieldSchema = null; if (strategy.isUuidOptional()) { List<Schema> union = new ArrayList<Schema>(2); union.add(getUuidType()); union.add(Schema.create(Type.NULL)); uuidFieldSchema = Schema.createUnion(union); } else { uuidFieldSchema = getUuidType(); } uuidField = new Field(UUID_FIELD, uuidFieldSchema, null, null); uuidField.addProp(DISPLAY_NAME_FIELD, UUID_FIELD_DISPLAY_NAME); uuidField.addProp(FIELD_ACCESS_FIELD, FIELD_ACCESS_READ_ONLY); return uuidField; } Field newUuidField = new Field(uuidField.name(), uuidField.schema(), null, null); AvroUtils.copyJsonProperties(uuidField, newUuidField); return newUuidField; }
/** * Creates the class type field. * * @return the field */ private Field createClassTypeField() { List<String> classTypeSymbols = Arrays.asList(OBJECT, EVENT); Schema classTypeEnum = Schema.createEnum(CLASS_TYPE_TYPE_NAME, null, BASE_SCHEMA_FORM_NAMESPACE, classTypeSymbols); Field classTypeField = new Field(CLASS_TYPE, classTypeEnum, null, null); classTypeField.addProp(DISPLAY_NAME, "Class type"); JsonNodeFactory jsonFactory = JsonNodeFactory.instance; ArrayNode displayNamesNode = jsonFactory.arrayNode(); displayNamesNode.add(TextNode.valueOf("Object")); displayNamesNode.add(TextNode.valueOf("Event")); classTypeField.addProp(DISPLAY_NAMES, displayNamesNode); classTypeField.addProp(DISPLAY_PROMPT, "Select class type"); classTypeField.addProp(BY_DEFAULT, OBJECT); return classTypeField; }
/** * Creates the addressable field. * * @return the field */ private Field createAddressableField() { Field addressableField = new Field(ADDRESSABLE, Schema.createUnion(Arrays.asList( Schema.create(Type.BOOLEAN), Schema.create(Type.NULL))), null, null); addressableField.addProp(DISPLAY_NAME, "Is addressable"); addressableField.addProp(BY_DEFAULT, BooleanNode.valueOf(true)); addressableField.addProp(DISPLAY_PROMPT, "Click to enable/disable partial updates support"); return addressableField; }
@Override protected void customizeSchemaField(Field avroField, Record fieldType) { if (fieldType.getSchema().getName().equals(ARRAY_FIELD_TYPE)) { GenericData.EnumSymbol overrideStrategy = (GenericData.EnumSymbol) fieldType.get(OVERRIDE_STRATEGY); if (overrideStrategy != null && !overrideStrategy.toString().equalsIgnoreCase(OverrideStrategy.REPLACE.name())) { avroField.addProp(OVERRIDE_STRATEGY, overrideStrategy.toString().toLowerCase()); } } }
private void _setupSchemas() { Schema.Field docIdField = new Schema.Field( "resourceId", AvroUtils._string(), null, (Object)null, Schema.Field.Order.ASCENDING); docIdField.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true"); docIdField.addProp(SchemaConstants.TALEND_IS_LOCKED, "true"); List<Schema.Field> fields = new ArrayList<>(); fields.add(docIdField); Schema initialSchema = Schema.createRecord( "liferay", null, null, false, fields); resource.main.schema.setValue(initialSchema); _updateOutputSchemas(); }
public static Schema createRejectSchema(Schema inputSchema) { final List<Schema.Field> rejectFields = new ArrayList<>(); Schema.Field field = new Schema.Field( FIELD_ERROR_MESSAGE, AvroUtils.wrapAsNullable(AvroUtils._string()), null, (Object)null); field.addProp(SchemaConstants.TALEND_COLUMN_DB_LENGTH, "255"); field.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true"); field.addProp(SchemaConstants.TALEND_IS_LOCKED, "true"); rejectFields.add(field); Schema rejectSchema = SchemaUtils.newSchema( inputSchema, "rejectOutput", rejectFields); return rejectSchema; }
private static Schema _getDeleteSchema() { List<Schema.Field> schemaFields = new ArrayList<>(1); Schema.Field designField = new Schema.Field( AvroConstants.ID, AvroUtils._string(), null, (Object)null); designField.addProp(SchemaConstants.TALEND_IS_LOCKED, "true"); schemaFields.add(designField); Schema schema = Schema.createRecord( "Runtime", null, null, false, schemaFields); return schema; }