kengtin commented on code in PR #7161: URL: https://github.com/apache/iceberg/pull/7161#discussion_r1199631556
########## flink/v1.16/flink/src/test/java/org/apache/iceberg/flink/sink/TestBucketPartitionerUtils.java: ########## @@ -0,0 +1,121 @@ +/* + * 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.sink; + +import java.util.List; +import java.util.UUID; +import org.apache.flink.table.data.util.DataFormatConverters; +import org.apache.flink.types.Row; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.flink.SimpleDataUtil; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.util.BucketUtil; + +final class TestBucketPartitionerUtils { + + enum TableSchemaType { + ONE_BUCKET, + IDENTITY_AND_BUCKET, + TWO_BUCKETS; + } + + private TestBucketPartitionerUtils() {} + + static final DataFormatConverters.RowConverter CONVERTER = + new DataFormatConverters.RowConverter(SimpleDataUtil.FLINK_SCHEMA.getFieldDataTypes()); + + static PartitionSpec getPartitionSpec(TableSchemaType tableSchemaType, int numBuckets) { + PartitionSpec partitionSpec = null; + + switch (tableSchemaType) { + case ONE_BUCKET: + partitionSpec = + PartitionSpec.builderFor(SimpleDataUtil.SCHEMA).bucket("data", numBuckets).build(); + break; + case IDENTITY_AND_BUCKET: + partitionSpec = + PartitionSpec.builderFor(SimpleDataUtil.SCHEMA) + .identity("id") + .bucket("data", numBuckets) + .build(); + break; + case TWO_BUCKETS: + partitionSpec = + PartitionSpec.builderFor(SimpleDataUtil.SCHEMA) + .bucket("id", numBuckets) + .bucket("data", numBuckets) + .build(); + break; + } + + Preconditions.checkNotNull( + partitionSpec, "Invalid tableSchemaType provided: " + tableSchemaType); + return partitionSpec; + } + + /** + * Utility method to generate rows whose values will "hash" to a range of bucketIds (from 0 to + * numBuckets - 1) + * + * @param numRowsPerBucket how many different rows should be generated per bucket + * @param numBuckets max number of buckets to consider + * @return the list of rows whose data "hashes" to the desired bucketId + */ + static List<Row> generateRowsForBucketIdRange(int numRowsPerBucket, int numBuckets) { Review Comment: I made this change, however while creating the `BoundedTestSource` I got an exception that `RowData` was not Serializable. At least I was able to use `RowData` across all tests and remove the `CONVERTER` from the general utils, but I had to keep it inside that function to provide `Row` during the source creation (`TestBucketPartitionerFlinkIcebergSink` line 116). Thoughts? -- 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]
