use of java.io.DataOutput in project asterixdb by apache.
the class TreeIndexTestUtils method createTupleFromCheckTuple.
@SuppressWarnings("unchecked")
public static void createTupleFromCheckTuple(CheckTuple checkTuple, ArrayTupleBuilder tupleBuilder, ArrayTupleReference tuple, ISerializerDeserializer[] fieldSerdes, boolean filtered) throws HyracksDataException {
int fieldCount = tupleBuilder.getFieldEndOffsets().length;
DataOutput dos = tupleBuilder.getDataOutput();
tupleBuilder.reset();
for (int i = 0; i < (filtered ? fieldCount - 1 : fieldCount); i++) {
fieldSerdes[i].serialize(checkTuple.getField(i), dos);
tupleBuilder.addFieldEndOffset();
}
if (filtered) {
fieldSerdes[0].serialize(checkTuple.getField(0), dos);
tupleBuilder.addFieldEndOffset();
}
tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
}
use of java.io.DataOutput in project asterixdb by apache.
the class HiveRecordParser method parse.
@Override
public void parse(IRawRecord<? extends Writable> record, DataOutput out) throws HyracksDataException {
try {
Writable hiveRawRecord = record.get();
Object hiveObject = hiveSerde.deserialize(hiveRawRecord);
int n = recordType.getFieldNames().length;
List<Object> attributesValues = oi.getStructFieldsDataAsList(hiveObject);
recBuilder.reset(recordType);
recBuilder.init();
for (int i = 0; i < n; i++) {
final Object value = attributesValues.get(i);
final ObjectInspector foi = fieldRefs.get(i).getFieldObjectInspector();
fieldValueBuffer.reset();
final DataOutput dataOutput = fieldValueBuffer.getDataOutput();
dataOutput.writeByte(fieldTypeTags[i]);
//get field type
parseItem(fieldTypes[i], value, foi, dataOutput, false);
recBuilder.addField(i, fieldValueBuffer);
}
recBuilder.write(out, true);
} catch (Exception e) {
throw new HyracksDataException(e);
}
}
use of java.io.DataOutput in project asterixdb by apache.
the class ADMDataParser method parseConstructor.
private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws IOException {
ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
if (targetTypeTag != null) {
DataOutput dataOutput = out;
if (targetTypeTag != typeTag) {
castBuffer.reset();
dataOutput = castBuffer.getDataOutput();
}
int token = admLexer.next();
if (token == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
token = admLexer.next();
if (token == AdmLexer.TOKEN_STRING_LITERAL) {
String unquoted = admLexer.getLastTokenImage().substring(1, admLexer.getLastTokenImage().length() - 1);
if (!parseValue(unquoted, typeTag, dataOutput)) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CONSTRUCTOR_MISSING_DESERIALIZER, AdmLexer.tokenKindToString(token));
}
token = admLexer.next();
if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
if (targetTypeTag != typeTag) {
ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
// the availability of a target type
assert promoteComputer != null;
// do the promotion; note that the type tag field should be skipped
promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, out);
}
return;
}
}
}
}
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH, objectType.getTypeName() + " got " + typeTag);
}
use of java.io.DataOutput in project asterixdb by apache.
the class ExternalRTreeSearchOperatorNodePushable method open.
// We override this method to specify the searched version of the index
@Override
public void open() throws HyracksDataException {
writer.open();
accessor = new FrameTupleAccessor(inputRecDesc);
indexHelper.open();
index = indexHelper.getIndexInstance();
if (retainMissing) {
int fieldCount = getFieldCount();
nonMatchTupleBuild = new ArrayTupleBuilder(fieldCount);
DataOutput out = nonMatchTupleBuild.getDataOutput();
for (int i = 0; i < fieldCount; i++) {
try {
nonMatchWriter.writeMissing(out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
nonMatchTupleBuild.addFieldEndOffset();
}
} else {
nonMatchTupleBuild = null;
}
ExternalRTree rTreeIndex = (ExternalRTree) index;
try {
searchPred = createSearchPredicate();
tb = new ArrayTupleBuilder(recordDesc.getFieldCount());
dos = tb.getDataOutput();
appender = new FrameTupleAppender(new VSizeFrame(ctx));
ISearchOperationCallback searchCallback = searchCallbackFactory.createSearchOperationCallback(indexHelper.getResource().getId(), ctx, null);
// The next line is the reason we override this method...
// The right thing to do would be to change the signature of createAccessor
indexAccessor = rTreeIndex.createAccessor(searchCallback, version);
cursor = createCursor();
if (retainInput) {
frameTuple = new FrameTupleReference();
}
} catch (Exception e) {
throw new HyracksDataException(e);
}
}
use of java.io.DataOutput in project asterixdb by apache.
the class ADMDataParser method parseAndCastNumeric.
private void parseAndCastNumeric(ATypeTag typeTag, IAType objectType, DataOutput out) throws IOException {
ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
DataOutput dataOutput = out;
if (targetTypeTag != typeTag) {
castBuffer.reset();
dataOutput = castBuffer.getDataOutput();
}
if ((targetTypeTag == null) || !parseValue(admLexer.getLastTokenImage(), typeTag, dataOutput)) {
throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2 + typeTag);
}
// target type
if (targetTypeTag != typeTag) {
if (ATypeHierarchy.canPromote(typeTag, targetTypeTag)) {
// can promote typeTag to targetTypeTag
ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
if (promoteComputer == null) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CAST_ERROR, typeTag, targetTypeTag);
}
// do the promotion; note that the type tag field should be skipped
promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, out);
} else if (ATypeHierarchy.canDemote(typeTag, targetTypeTag)) {
// can demote source type to the target type
ITypeConvertComputer demoteComputer = ATypeHierarchy.getTypeDemoteComputer(typeTag, targetTypeTag, true);
if (demoteComputer == null) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CAST_ERROR, typeTag, targetTypeTag);
}
// do the demotion; note that the type tag field should be skipped
demoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, out);
}
}
}
Aggregations