vvysotskyi commented on a change in pull request #1844: DRILL-7326: Support
repeated lists for CTAS parquet format
URL: https://github.com/apache/drill/pull/1844#discussion_r315671441
##########
File path:
exec/java-exec/src/main/codegen/templates/ParquetOutputRecordWriter.java
##########
@@ -268,10 +268,109 @@ public void writeField() throws IOException {
consumer.endField(fieldName, fieldId);
</#if>
}
+
+ <#if mode.prefix == "Repeated">
+ @Override
+ public void writeListField() {
+ if (reader.size() == 0) {
+ return;
+ }
+ consumer.startField("list", 0);
+ for (int i = 0; i < reader.size(); i++) {
+ consumer.startGroup();
+ consumer.startField("element", 0);
+
+ <#if minor.class == "TinyInt" ||
+ minor.class == "UInt1" ||
+ minor.class == "UInt2" ||
+ minor.class == "SmallInt" ||
+ minor.class == "Int" ||
+ minor.class == "Time" ||
+ minor.class == "Decimal9" ||
+ minor.class == "UInt4">
+ reader.read(i, holder);
+ consumer.addInteger(holder.value);
+ <#elseif minor.class == "Float4">
+ reader.read(i, holder);
+ consumer.addFloat(holder.value);
+ <#elseif minor.class == "BigInt" ||
+ minor.class == "Decimal18" ||
+ minor.class == "TimeStamp" ||
+ minor.class == "UInt8">
+ reader.read(i, holder);
+ consumer.addLong(holder.value);
+ <#elseif minor.class == "Date">
+ reader.read(i, holder);
+ consumer.addInteger((int) (holder.value /
DateTimeConstants.MILLIS_PER_DAY));
+ <#elseif minor.class == "Float8">
+ reader.read(i, holder);
+ consumer.addDouble(holder.value);
+ <#elseif minor.class == "Bit">
+ reader.read(i, holder);
+ consumer.addBoolean(holder.value == 1);
+ <#elseif minor.class == "Decimal28Sparse" ||
+ minor.class == "Decimal38Sparse">
+ <#if mode.prefix == "Repeated" >
+ <#else>
+ consumer.startField(fieldName, fieldId);
+ reader.read(holder);
+ byte[] bytes = DecimalUtility.getBigDecimalFromSparse(
+ holder.buffer, holder.start, ${minor.class}Holder.nDecimalDigits,
holder.scale).unscaledValue().toByteArray();
+ byte[] output = new
byte[ParquetTypeHelper.getLengthForMinorType(MinorType.${minor.class?upper_case})];
+ if (holder.getSign(holder.start, holder.buffer)) {
+ Arrays.fill(output, 0, output.length - bytes.length, (byte)0xFF);
+ } else {
+ Arrays.fill(output, 0, output.length - bytes.length, (byte)0x0);
+ }
+ System.arraycopy(bytes, 0, output, output.length - bytes.length,
bytes.length);
+ consumer.addBinary(Binary.fromByteArray(output));
+ consumer.endField(fieldName, fieldId);
+ </#if>
+ <#elseif minor.class?contains("Interval")>
+ consumer.startField(fieldName, fieldId);
+ reader.read(holder);
+ <#if minor.class == "IntervalDay">
+ Arrays.fill(output, 0, 4, (byte) 0);
+ IntervalUtility.intToLEByteArray(holder.days, output, 4);
+ IntervalUtility.intToLEByteArray(holder.milliseconds, output, 8);
+ <#elseif minor.class == "IntervalYear">
+ IntervalUtility.intToLEByteArray(holder.value, output, 0);
+ Arrays.fill(output, 4, 8, (byte) 0);
+ Arrays.fill(output, 8, 12, (byte) 0);
+ <#elseif minor.class == "Interval">
+ IntervalUtility.intToLEByteArray(holder.months, output, 0);
+ IntervalUtility.intToLEByteArray(holder.days, output, 4);
+ IntervalUtility.intToLEByteArray(holder.milliseconds, output, 8);
+ </#if>
+ consumer.addBinary(Binary.fromByteArray(output));
+ consumer.endField(fieldName, fieldId);
+
+ <#elseif
+ minor.class == "TimeTZ" ||
+ minor.class == "Decimal28Dense" ||
+ minor.class == "Decimal38Dense">
+ <#elseif minor.class == "VarChar" || minor.class == "Var16Char"
+ || minor.class == "VarBinary" || minor.class == "VarDecimal">
+ reader.read(i, holder);
+ <#if minor.class == "VarDecimal">
+ decimalValueWriter.writeValue(consumer, holder.buffer,
+ holder.start, holder.end, reader.getField().getPrecision());
+ <#else>
+
consumer.addBinary(Binary.fromByteBuffer(holder.buffer.nioBuffer(holder.start,
holder.end - holder.start)));
+ </#if>
+ </#if>
+
+ consumer.endField("element", 0);
Review comment:
It would be good also to replace strings here with constants if they will be
created.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services