private void writeInt32( int readInt32, final MapOrListWriterImpl writer, String fieldName, boolean isList) { final IntHolder ih = new IntHolder(); ih.value = readInt32; if (isList == false) { writer.integer(fieldName).write(ih); } else { writer.list.integer().write(ih); } }
private void writeInt64( long readInt64, final MapOrListWriterImpl writer, String fieldName, boolean isList) { final BigIntHolder bh = new BigIntHolder(); bh.value = readInt64; if (isList == false) { writer.bigInt(fieldName).write(bh); } else { writer.list.bigInt().write(bh); } }
private void writeBoolean( boolean readBoolean, final MapOrListWriterImpl writer, String fieldName, boolean isList) { final BitHolder bit = new BitHolder(); bit.value = readBoolean ? 1 : 0; if (isList == false) { writer.bit(fieldName).write(bit); } else { writer.list.bit().write(bit); } }
private void writeDouble( double readDouble, final MapOrListWriterImpl writer, String fieldName, boolean isList) { final Float8Holder f8h = new Float8Holder(); f8h.value = readDouble; if (isList == false) { writer.float8(fieldName).write(f8h); } else { writer.list.float8().write(f8h); } }
private void writeBinary( final MapOrListWriterImpl writer, String fieldName, boolean isList, final VarBinaryHolder vb, final byte[] bytes) { ensure(bytes.length); workBuf.setBytes(0, bytes); vb.buffer = workBuf; vb.start = 0; vb.end = bytes.length; if (isList == false) { writer.binary(fieldName).write(vb); } else { writer.list.varBinary().write(vb); } }
private void writeString( String readString, final MapOrListWriterImpl writer, String fieldName, boolean isList) { int length; byte[] strBytes; try { strBytes = readString.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new DrillRuntimeException("Unable to read string value for field: " + fieldName, e); } length = strBytes.length; ensure(length); workBuf.setBytes(0, strBytes); final VarCharHolder vh = new VarCharHolder(); vh.buffer = workBuf; vh.start = 0; vh.end = length; if (isList == false) { writer.varChar(fieldName).write(vh); } else { writer.list.varChar().write(vh); } }
private void writeToListOrMap( BsonReader reader, final MapOrListWriterImpl writer, boolean isList, String fieldName) { writer.start(); // If isList is true, then filedName can be null as it is not required while // writing while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) { if (!isList) { fieldName = reader.readName(); } BsonType currentBsonType = reader.getCurrentBsonType(); switch (currentBsonType) { case INT32: int readInt32 = reader.readInt32(); if (readNumbersAsDouble) { writeDouble(readInt32, writer, fieldName, isList); } else { writeInt32(readInt32, writer, fieldName, isList); } atLeastOneWrite = true; break; case INT64: long readInt64 = reader.readInt64(); if (readNumbersAsDouble) { writeDouble(readInt64, writer, fieldName, isList); } else { writeInt64(readInt64, writer, fieldName, isList); } atLeastOneWrite = true; break; case ARRAY: reader.readStartArray(); writeToListOrMap(reader, (MapOrListWriterImpl) writer.list(fieldName), true, fieldName); atLeastOneWrite = true; break; case BINARY: // handle types writeBinary(reader, writer, fieldName, isList); atLeastOneWrite = true; break; case BOOLEAN: boolean readBoolean = reader.readBoolean(); writeBoolean(readBoolean, writer, fieldName, isList); atLeastOneWrite = true; break; case DATE_TIME: long readDateTime = reader.readDateTime(); writeDateTime(readDateTime, writer, fieldName, isList); atLeastOneWrite = true; break; case DOCUMENT: reader.readStartDocument(); // To handle nested Documents. MapOrListWriterImpl _writer = writer; if (!isList) { _writer = (MapOrListWriterImpl) writer.map(fieldName); } else { _writer = (MapOrListWriterImpl) writer.listoftmap(fieldName); } writeToListOrMap(reader, _writer, false, fieldName); atLeastOneWrite = true; break; case DOUBLE: double readDouble = reader.readDouble(); writeDouble(readDouble, writer, fieldName, isList); atLeastOneWrite = true; break; case JAVASCRIPT: final String readJavaScript = reader.readJavaScript(); writeString(readJavaScript, writer, fieldName, isList); atLeastOneWrite = true; break; case JAVASCRIPT_WITH_SCOPE: final String readJavaScriptWithScopeString = reader.readJavaScriptWithScope(); writeString(readJavaScriptWithScopeString, writer, fieldName, isList); atLeastOneWrite = true; break; case NULL: // just read and ignore. reader.readNull(); break; case OBJECT_ID: writeObjectId(reader, writer, fieldName, isList); atLeastOneWrite = true; break; case STRING: final String readString = reader.readString(); writeString(readString, writer, fieldName, isList); atLeastOneWrite = true; break; case SYMBOL: final String readSymbol = reader.readSymbol(); writeString(readSymbol, writer, fieldName, isList); atLeastOneWrite = true; break; case TIMESTAMP: int time = reader.readTimestamp().getTime(); writeTimeStamp(time, writer, fieldName, isList); atLeastOneWrite = true; break; default: // Didn't handled REGULAR_EXPRESSION and DB_POINTER types throw new DrillRuntimeException("UnSupported Bson type: " + currentBsonType); } } if (!isList) { reader.readEndDocument(); } else { reader.readEndArray(); } }