Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style: Replace Arrays.asList with Collections.singletonList #9213

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -122,9 +123,9 @@ public void roundTripSerde() {
"amz-sdk-request",
Arrays.asList("attempt=1", "max=4"),
"Content-Length",
Arrays.asList("191"),
Collections.singletonList("191"),
"Content-Type",
Arrays.asList("application/json"),
Collections.singletonList("application/json"),
"User-Agent",
Arrays.asList("aws-sdk-java/2.20.18", "Linux/5.4.0-126")))
.build();
Expand Down Expand Up @@ -158,9 +159,9 @@ public void roundTripSerdeWithProperties() {
"amz-sdk-request",
Arrays.asList("attempt=1", "max=4"),
"Content-Length",
Arrays.asList("191"),
Collections.singletonList("191"),
"Content-Type",
Arrays.asList("application/json"),
Collections.singletonList("application/json"),
"User-Agent",
Arrays.asList("aws-sdk-java/2.20.18", "Linux/5.4.0-126")))
.properties(ImmutableMap.of("k1", "v1"))
Expand Down Expand Up @@ -198,9 +199,9 @@ public void roundTripWithBody() {
"amz-sdk-request",
Arrays.asList("attempt=1", "max=4"),
"Content-Length",
Arrays.asList("191"),
Collections.singletonList("191"),
"Content-Type",
Arrays.asList("application/json"),
Collections.singletonList("application/json"),
"User-Agent",
Arrays.asList("aws-sdk-java/2.20.18", "Linux/5.4.0-126")))
.properties(ImmutableMap.of("k1", "v1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -70,9 +71,9 @@ public void roundTripSerde() {
"amz-sdk-request",
Arrays.asList("attempt=1", "max=4"),
"Content-Length",
Arrays.asList("191"),
Collections.singletonList("191"),
"Content-Type",
Arrays.asList("application/json"),
Collections.singletonList("application/json"),
"User-Agent",
Arrays.asList("aws-sdk-java/2.20.18", "Linux/5.4.0-126")))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import static org.apache.iceberg.TableProperties.MANIFEST_TARGET_SIZE_BYTES_DEFAULT;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -247,7 +247,7 @@ private void performRewrite(List<ManifestFile> currentManifests) {
rewrittenManifests.add(manifest);
try (ManifestReader<DataFile> reader =
ManifestFiles.read(manifest, ops.io(), ops.current().specsById())
.select(Arrays.asList("*"))) {
.select(Collections.singletonList("*"))) {
reader
.liveEntries()
.forEach(
Expand Down
12 changes: 6 additions & 6 deletions core/src/test/java/org/apache/iceberg/ScanTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.iceberg.expressions.Expression;
Expand Down Expand Up @@ -56,7 +56,7 @@ public ScanTestBase(int formatVersion) {

@Test
public void testTableScanHonorsSelect() {
ScanT scan = newScan().select(Arrays.asList("id"));
ScanT scan = newScan().select(Collections.singletonList("id"));

Schema expectedSchema = new Schema(required(1, "id", Types.IntegerType.get()));

Expand All @@ -69,20 +69,20 @@ public void testTableScanHonorsSelect() {
@Test
public void testTableBothProjectAndSelect() {
Assertions.assertThatThrownBy(
() -> newScan().select(Arrays.asList("id")).project(SCHEMA.select("data")))
() -> newScan().select(Collections.singletonList("id")).project(SCHEMA.select("data")))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Cannot set projection schema when columns are selected");
Assertions.assertThatThrownBy(
() -> newScan().project(SCHEMA.select("data")).select(Arrays.asList("id")))
() -> newScan().project(SCHEMA.select("data")).select(Collections.singletonList("id")))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Cannot select columns when projection schema is set");
}

@Test
public void testTableScanHonorsSelectWithoutCaseSensitivity() {
ScanT scan1 = newScan().caseSensitive(false).select(Arrays.asList("ID"));
ScanT scan1 = newScan().caseSensitive(false).select(Collections.singletonList("ID"));
// order of refinements shouldn't matter
ScanT scan2 = newScan().select(Arrays.asList("ID")).caseSensitive(false);
ScanT scan2 = newScan().select(Collections.singletonList("ID")).caseSensitive(false);

Schema expectedSchema = new Schema(required(1, "id", Types.IntegerType.get()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Stream;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.types.Comparators;
Expand Down Expand Up @@ -270,7 +271,7 @@ private static DeleteFile deleteFileWithAllOptional(PartitionSpec spec) {
metrics,
new int[] {3},
1,
Arrays.asList(128L),
Collections.singletonList(128L),
ByteBuffer.wrap(new byte[16]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.iceberg.flink.source.enumerator;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -173,7 +172,7 @@ public void testThrottlingDiscovery() throws Exception {
enumerator.handleSourceEvent(2, new SplitRequestEvent());

// add splits[0] to the planner for next discovery
splitPlanner.addSplits(Arrays.asList(splits.get(0)));
splitPlanner.addSplits(Collections.singletonList(splits.get(0)));
enumeratorContext.triggerAllActions();

// because discovered split was assigned to reader, pending splits should be empty
Expand All @@ -185,7 +184,7 @@ public void testThrottlingDiscovery() throws Exception {
// add the remaining 9 splits (one for every snapshot)
// run discovery cycles while reader-2 still processing the splits[0]
for (int i = 1; i < 10; ++i) {
splitPlanner.addSplits(Arrays.asList(splits.get(i)));
splitPlanner.addSplits(Collections.singletonList(splits.get(i)));
enumeratorContext.triggerAllActions();
}

Expand All @@ -196,7 +195,8 @@ public void testThrottlingDiscovery() throws Exception {
splits.subList(0, 1), enumeratorContext.getSplitAssignments().get(2).getAssignedSplits());

// now reader-2 finished splits[0]
enumerator.handleSourceEvent(2, new SplitRequestEvent(Arrays.asList(splits.get(0).splitId())));
enumerator.handleSourceEvent(
2, new SplitRequestEvent(Collections.singletonList(splits.get(0).splitId())));
enumeratorContext.triggerAllActions();
// still have 3 pending splits. After assigned splits[1] to reader-2, one more split was
// discovered and added.
Expand All @@ -217,7 +217,8 @@ public void testThrottlingDiscovery() throws Exception {
splits.subList(0, 2), enumeratorContext.getSplitAssignments().get(2).getAssignedSplits());

// now reader-2 finished splits[1]
enumerator.handleSourceEvent(2, new SplitRequestEvent(Arrays.asList(splits.get(1).splitId())));
enumerator.handleSourceEvent(
2, new SplitRequestEvent(Collections.singletonList(splits.get(1).splitId())));
enumeratorContext.triggerAllActions();
// still have 3 pending splits. After assigned new splits[2] to reader-2, one more split was
// discovered and added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void testOneSplitFetcher(
ReaderUtil.createCombinedScanTask(
recordBatchList, TEMPORARY_FOLDER, FileFormat.PARQUET, appenderFactory);
IcebergSourceSplit split = IcebergSourceSplit.fromCombinedScanTask(task);
reader.addSplits(Arrays.asList(split));
reader.addSplits(Collections.singletonList(split));

while (readerOutput.getEmittedRecords().size() < expectedCount) {
reader.pollNext(readerOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void testOneSplitFetcher(
ReaderUtil.createCombinedScanTask(
recordBatchList, TEMPORARY_FOLDER, FileFormat.PARQUET, appenderFactory);
IcebergSourceSplit split = IcebergSourceSplit.fromCombinedScanTask(task);
reader.addSplits(Arrays.asList(split));
reader.addSplits(Collections.singletonList(split));

while (readerOutput.getEmittedRecords().size() < expectedCount) {
reader.pollNext(readerOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void testOneSplitFetcher(
ReaderUtil.createCombinedScanTask(
recordBatchList, TEMPORARY_FOLDER, FileFormat.PARQUET, appenderFactory);
IcebergSourceSplit split = IcebergSourceSplit.fromCombinedScanTask(task);
reader.addSplits(Arrays.asList(split));
reader.addSplits(Collections.singletonList(split));

while (readerOutput.getEmittedRecords().size() < expectedCount) {
reader.pollNext(readerOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
Expand Down Expand Up @@ -147,7 +148,9 @@ public void testSchemaConvertToIcebergSchemaForEveryPrimitiveType() {
public void testNotSupportedTypes() {
for (FieldSchema notSupportedField : getNotSupportedFieldSchemas()) {
assertThatThrownBy(
() -> HiveSchemaUtil.convert(Lists.newArrayList(Arrays.asList(notSupportedField))))
() ->
HiveSchemaUtil.convert(
Lists.newArrayList(Collections.singletonList(notSupportedField))))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("Unsupported Hive type");
}
Expand Down Expand Up @@ -197,7 +200,7 @@ public void testConversionWithoutLastComment() {
Arrays.asList(
TypeInfoUtils.getTypeInfoFromTypeString(serdeConstants.BIGINT_TYPE_NAME),
TypeInfoUtils.getTypeInfoFromTypeString(serdeConstants.STRING_TYPE_NAME)),
Arrays.asList("customer comment"));
Collections.singletonList("customer comment"));

assertThat(schema.asStruct()).isEqualTo(expected.asStruct());
}
Expand Down