Java Code Examples for org.apache.avro.Schema.Field#pos()
The following examples show how to use
org.apache.avro.Schema.Field#pos() .
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: JiraDeleteWriter.java From components with Apache License 2.0 | 6 votes |
/** * Removes input data resources from Jira server <br> * Method should be called only after {@link JiraDeleteWriter#open(String)} * * @param datum input data */ @Override public void write(Object datum) throws IOException { if (!opened) { throw new IOException(MESSAGES.getMessage("error.writerNotOpened")); } result.totalCount++; if (datum == null) { return; } IndexedRecord record = getFactory(datum).convertToAvro(datum); if (dataSchema == null) { dataSchema = record.getSchema(); Field idField = dataSchema.getField("id"); if (idField == null) { throw new IOException(MESSAGES.getMessage("error.schemaNotContainId")); } idPos = idField.pos(); } String id = (String) record.get(idPos); String resourceToDelete = resource + "/" + id; JiraResponse response = getConnection().delete(resourceToDelete, sharedParameters); handleResponse(response, id, record); }
Example 2
Source File: JiraInsertWriter.java From components with Apache License 2.0 | 5 votes |
/** * Inserts resources into Jira server formed from incoming data input <br> * Method should be called only after {@link JiraInsertWriter#open(String)} * * @param datum input data */ @Override public void write(Object datum) throws IOException { if (!opened) { throw new IOException(MESSAGES.getMessage("error.writerNotOpened")); } result.totalCount++; if (datum == null) { return; } IndexedRecord record = getFactory(datum).convertToAvro(datum); if (dataSchema == null) { dataSchema = record.getSchema(); Field jsonField = dataSchema.getField("json"); if (jsonField == null) { throw new IOException(MESSAGES.getMessage("error.schemaNotContainJson")); } jsonPos = jsonField.pos(); } String json = (String) record.get(jsonPos); validateRequestBody(json); JiraResponse response = getConnection().post(resource, json); handleResponse(response, json, record); }
Example 3
Source File: JiraUpdateWriter.java From components with Apache License 2.0 | 5 votes |
/** * Updates Jira resources according incoming data <br> * Method should be called only after {@link JiraUpdateWriter#open(String)} * * @param datum input data */ @Override public void write(Object datum) throws IOException { if (!opened) { throw new IOException(MESSAGES.getMessage("error.writerNotOpened")); } result.totalCount++; if (datum == null) { return; } IndexedRecord record = getFactory(datum).convertToAvro(datum); if (dataSchema == null) { dataSchema = record.getSchema(); Field idField = dataSchema.getField("id"); if (idField == null) { throw new IOException(MESSAGES.getMessage("error.schemaNotContainId")); } idPos = idField.pos(); Field jsonField = dataSchema.getField("json"); if (jsonField == null) { throw new IOException(MESSAGES.getMessage("error.schemaNotContainJson")); } jsonPos = jsonField.pos(); } String id = (String) record.get(idPos); String resourceToUpdate = resource + "/" + id; String json = (String) record.get(jsonPos); validateRequestBody(json); JiraResponse response = getConnection().put(resourceToUpdate, json); handleResponse(response, json, record); }
Example 4
Source File: GenericRecordBuilder.java From avro-util with BSD 2-Clause "Simplified" License | 4 votes |
private Object getWithDefault(Field field) throws IOException { return this.fieldSetFlags()[field.pos()] ? this.record.get(field.pos()) : this.defaultValue(field); }
Example 5
Source File: RowWriter.java From components with Apache License 2.0 | 4 votes |
public RowWriter(List<JDBCSQLBuilder.Column> columnList, Schema inputSchema, Schema componentSchema, PreparedStatement statement, boolean debug, String sql) { this.debug = debug; if (debug) { debugUtil = new DebugUtil(sql); } List<TypeWriter> writers = new ArrayList<TypeWriter>(); int statementIndex = 0; for (JDBCSQLBuilder.Column column : columnList) { Field inputField = CommonUtils.getField(inputSchema, column.columnLabel); Field componentField = CommonUtils.getField(componentSchema, column.columnLabel); int inputValueLocation = inputField.pos(); String pattern = componentField.getProp("talend.field.pattern"); statementIndex++; Schema basicSchema = AvroUtils.unwrapIfNullable(componentField.schema()); // TODO any difference for nullable // boolean nullable = AvroUtils.isNullable(componentField.schema()); TypeWriter writer = null; if (AvroUtils.isSameType(basicSchema, AvroUtils._string())) { writer = new StringTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._int())) { writer = new IntTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._date())) { writer = new DateTypeWriter(statement, statementIndex, inputValueLocation, pattern); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._decimal())) { writer = new BigDecimalTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._long())) { writer = new LongTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._double())) { writer = new DoubleTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._float())) { writer = new FloatTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._boolean())) { writer = new BooleanTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._short())) { writer = new ShortTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._character())) { writer = new CharacterTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._byte())) { writer = new ByteTypeWriter(statement, statementIndex, inputValueLocation); } else if (AvroUtils.isSameType(basicSchema, AvroUtils._bytes())) { writer = new BytesTypeWriter(statement, statementIndex, inputValueLocation); } else { writer = new ObjectTypeWriter(statement, statementIndex, inputValueLocation); } writers.add(writer); } typeWriters = writers.toArray(new TypeWriter[0]); }