@Override public void serialize( Text text, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonGenerationException { jsonGenerator.writeString(text.toString()); } }
public static List<String> getRefreshPath(final JobId jobId, final JobData jobData, final Path accelerationBasePath) { // extract written path from writer's metadata JobDataFragment data = jobData.range(0, 1); Text text = (Text) Preconditions.checkNotNull(data.extractValue(RecordWriter.PATH_COLUMN, 0), "Empty write path for job %s", jobId.getId()); // relative path to the acceleration base path final String path = PathUtils.relativePath(new Path(text.toString()), accelerationBasePath); // extract first 2 components of the path "<reflection-id>."<modified-materialization-id>" List<String> components = PathUtils.toPathComponents(path); Preconditions.checkState(components.size() >= 2, "Refresh path %s is incomplete", path); return ImmutableList.of(ACCELERATOR_STORAGEPLUGIN_NAME, components.get(0), components.get(1)); }
@Override public void writeVar16Char(FieldReader reader) throws IOException { if (reader.isSet()) { writeVar16Char(reader.readText().toString()); } else { writeVar16charNull(); } }
@Override public void writeVarChar(FieldReader reader) throws IOException { if (reader.isSet()) { writeVarChar(reader.readText().toString()); } else { writeVarcharNull(); } }
public void writeVarChar(FieldReader reader, JsonOutputContext context) throws IOException { if (reader.isSet()) { // NB: For UnionReader(s), reader.isSet() checks if the reader has a type set, not if the data itself is null final Text text = reader.readText(); if (text != null) { String value = text.toString(); if (value.length() > context.getRemaining()) { // Truncate the string if the space is limited value = value.substring(0, context.getRemaining()); context.setTruncated(); } writeVarChar(value); context.used(value.length()); return; } } // Either the type or the value is not set writeNull(context); }
/** * This method is a helper method added for DRILL-951 * TextRecordReader to call this method to get field names out * @return array of field data strings */ public String [] getTextOutput () throws ExecutionSetupException { if (recordCount == 0 || fieldIndex == -1) { return null; } //Currently only first line header is supported. Return only first record. int retSize = fieldIndex+1; String [] out = new String [retSize]; try { ListVector listVector = output.addField(new Field(COL_NAME, true, MinorType.LIST.getType(), null), ListVector.class); List outputlist = (List) listVector.getObject((int)(recordCount-1)); for (int i=0; i<retSize; i++){ out[i] = ((Text) outputlist.get(i)).toString(); } return out; } catch (SchemaChangeException e) { throw new ExecutionSetupException(e); } }
/** Helper method to get the values in given range in colVarChar vector used in this test class. */ private static List<String> getVarCharValues(VectorContainer container, int start, int end) { FieldReader reader = container.getValueAccessorById(VarCharVector.class, 1).getValueVector().getReader(); List<String> values = Lists.newArrayList(); for(int i=start; i<end; i++) { reader.setPosition(i); if (reader.isSet()) { final Text val = reader.readText(); values.add(val == null ? null : val.toString()); } else { values.add(null); } } return values; }