pvary commented on code in PR #15471: URL: https://github.com/apache/iceberg/pull/15471#discussion_r2871706447
########## flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java: ########## @@ -0,0 +1,316 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.flink.data; + +import org.apache.flink.table.data.ArrayData; +import org.apache.flink.table.data.DecimalData; +import org.apache.flink.table.data.MapData; +import org.apache.flink.table.data.RawValueData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.StringData; +import org.apache.flink.table.data.TimestampData; +import org.apache.flink.table.types.logical.RowType; +import org.apache.flink.types.RowKind; +import org.apache.flink.types.variant.Variant; + +public class VariantRowDataWrapper implements RowData { + + private final RowType rowType; + private RowKind rowKind; + private Variant variantData; + + public VariantRowDataWrapper(RowType rowType) { + this(rowType, RowKind.INSERT); + } + + public VariantRowDataWrapper(RowType rowType, RowKind rowKind) { + this.rowType = rowType; + this.rowKind = rowKind; + } + + public VariantRowDataWrapper wrap(Variant variant) { + this.variantData = variant; + return this; + } + + @Override + public int getArity() { + return rowType.getFieldCount(); + } + + @Override + public RowKind getRowKind() { + return rowKind; + } + + @Override + public void setRowKind(RowKind rowKind) { + this.rowKind = rowKind; + } + + @Override + public boolean isNullAt(int pos) { + String fieldName = getFieldNameByIndex(pos); + Variant value = variantData.getField(fieldName); + return value == null || value.isNull(); + } + + @Override + public boolean getBoolean(int pos) { + String fieldName = getFieldNameByIndex(pos); + return variantData.getField(fieldName).getBoolean(); + } + + @Override + public byte getByte(int pos) { + String fieldName = getFieldNameByIndex(pos); + return variantData.getField(fieldName).getByte(); + } + + @Override + public short getShort(int pos) { + String fieldName = getFieldNameByIndex(pos); + return variantData.getField(fieldName).getShort(); + } + + @Override + public int getInt(int pos) { + String fieldName = getFieldNameByIndex(pos); + return getIntValue(variantData.getField(fieldName)); + } + + @Override + public long getLong(int pos) { + String fieldName = getFieldNameByIndex(pos); + return getLongValue(variantData.getField(fieldName)); + } + + @Override + public float getFloat(int pos) { + String fieldName = getFieldNameByIndex(pos); + return variantData.getField(fieldName).getFloat(); + } + + @Override + public double getDouble(int pos) { + String fieldName = getFieldNameByIndex(pos); + return getDoubleValue(variantData.getField(fieldName)); + } + + @Override + public StringData getString(int pos) { + String fieldName = getFieldNameByIndex(pos); + return isNullAt(pos) + ? null + : StringData.fromString(variantData.getField(fieldName).getString()); + } + + @Override + public DecimalData getDecimal(int pos, int precision, int scale) { + String fieldName = getFieldNameByIndex(pos); + return isNullAt(pos) + ? null + : DecimalData.fromBigDecimal( + variantData.getField(fieldName).getDecimal(), precision, scale); + } + + @Override + public TimestampData getTimestamp(int pos, int precision) { + String fieldName = getFieldNameByIndex(pos); + return isNullAt(pos) ? null : getTimestamp(variantData.getField(fieldName)); + } + + @Override + public <T> RawValueData<T> getRawValue(int pos) { + throw new UnsupportedOperationException("RawValue in Variant column is not supported."); + } + + @Override + public byte[] getBinary(int pos) { + String fieldName = getFieldNameByIndex(pos); + return variantData.getField(fieldName).getBytes(); + } + + @Override + public ArrayData getArray(int pos) { + // ArrayType arrayType = (ArrayType) rowType.getTypeAt(pos); + // LogicalType elementType = arrayType.getElementType(); + // + // String fieldName = getFieldNameByIndex(pos); + // Variant arrayVariant = variantData.getField(fieldName); + // + // if (arrayVariant != null) { + // Preconditions.checkArgument(arrayVariant.getType().equals(Variant.Type.ARRAY), + // "Expected Array type, but got " + arrayVariant.getType()); + // int arraySize = arrayVariant.getArraySize(); + // Object[] elements = new Object[arraySize]; + // + // for (int i=0;i< arraySize;i++) { + // Variant element = arrayVariant.getElement(i); + // elements[i] = element == null ? null : getElementValue(elementType, element); + // } + // + // return new GenericArrayData(elements); + // } + // + // return null; Review Comment: Why are these removed? If we don't want to support these in the first round, we should remove the comments -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
