auphong2707/dl4se-code-review-dataset huggingface dataset:
Source:
public Page getNextPage() { PrestoSparkSerializedPage prestoSparkSerializedPage = null; synchronized (this) { while (prestoSparkSerializedPage == null) { if (currentIteratorIndex >= serializedPageIterators.size()) { return null; } Iterator<PrestoSparkSerializedPage> currentIterator = serializedPageIterators.get(currentIteratorIndex); START if (!currentIterator.hasNext()) { currentIteratorIndex++; continue; } prestoSparkSerializedPage = currentIterator.next(); END } } return pagesSerde.deserialize(toSerializedPage(prestoSparkSerializedPage)); } I would prefer this way ``` if (currentIterator.hasNext()) { prestoSparkSerializedPage = currentIterator.next(); } else { currentIteratorIndex++; } ```

Target:
public Page getNextPage() { PrestoSparkSerializedPage prestoSparkSerializedPage = null; synchronized (this) { while (prestoSparkSerializedPage == null) { if (currentIteratorIndex >= serializedPageIterators.size()) { return null; } Iterator<PrestoSparkSerializedPage> currentIterator = serializedPageIterators.get(currentIteratorIndex); if (currentIterator.hasNext()) { prestoSparkSerializedPage = currentIterator.next(); } else { currentIteratorIndex++; } } } return pagesSerde.deserialize(toSerializedPage(prestoSparkSerializedPage)); }
Source:
public static void combine(@AggregationState NullableDoubleState state, @AggregationState NullableDoubleState otherState) { if (state.isNull()) { state.setNull(false); state.setDouble(otherState.getDouble()); } START else { END state.setDouble(state.getDouble() + otherState.getDouble()); } } Is there a performance difference between this and original code?

Target:
public static void combine(@AggregationState NullableDoubleState state, @AggregationState NullableDoubleState otherState) { if (state.isNull()) { state.setNull(false); state.setDouble(otherState.getDouble()); return; } state.setDouble(state.getDouble() + otherState.getDouble()); }
Source:
private static Response responseWithHeaders(ResponseBuilder builder, ProxyResponse response) { START response.getHeaders().asMap().forEach((headerName, values) -> { END String name = headerName.toString(); if (isPrestoHeader(name) || name.equalsIgnoreCase(SET_COOKIE)) { values.forEach(value -> builder.header(name, value)); } }); return builder.build(); } Would `response.getHeaders().forEach((headerName, value)` work? Just remove `asMap()`.

Target:
private static Response responseWithHeaders(ResponseBuilder builder, ProxyResponse response) { response.getHeaders().forEach((headerName, value) -> { String name = headerName.toString(); if (isPrestoHeader(name) || name.equalsIgnoreCase(SET_COOKIE)) { builder.header(name, value); } }); return builder.build(); }
Source:
START private boolean isDateTimeConstantType(Type type) END { return type == DateType.DATE || type == TimestampType.TIMESTAMP || type == TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; } Can be private static

Target:
private static boolean isDateTimeConstantType(Type type) { return type == DateType.DATE || type == TimestampType.TIMESTAMP || type == TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; }
Source:
public FSDataInputStream openFile(Path path, HiveFileContext hiveFileContext) throws Exception { // URIStatus is the mechanism to pass the hiveFileContext to the source filesystem URIStatus uriStatus = mFileSystem.getStatus(getAlluxioPath(path)); AlluxioURIStatus alluxioURIStatus = new AlluxioURIStatus(uriStatus.getFileInfo(), hiveFileContext); FileInStream fileInStream = mFileSystem.openFile(alluxioURIStatus, OpenFilePOptions.getDefaultInstance()); START return new FSDataInputStream(new AlluxioCachingHdfsFileInputStream(fileInStream, fileSystem.openFile(path, hiveFileContext), cacheValidationEnabled)); END } We should avoid fileSystem.openFile in case validation is disabled.

Target:
public FSDataInputStream openFile(Path path, HiveFileContext hiveFileContext) throws Exception { // URIStatus is the mechanism to pass the hiveFileContext to the source filesystem URIStatus uriStatus = mFileSystem.getStatus(getAlluxioPath(path)); AlluxioURIStatus alluxioURIStatus = new AlluxioURIStatus(uriStatus.getFileInfo(), hiveFileContext); FileInStream fileInStream = mFileSystem.openFile(alluxioURIStatus, OpenFilePOptions.getDefaultInstance()); return new FSDataInputStream(new AlluxioCachingHdfsFileInputStream( fileInStream, (cacheValidationEnabled ? Optional.of(fileSystem.openFile(path, hiveFileContext)) : Optional.empty()), cacheValidationEnabled)); }
Source:
public static HivePartitioningHandle createHiveCompatiblePartitioningHandle( int bucketCount, List<HiveType> hiveTypes, OptionalInt maxCompatibleBucketCount) { return new HivePartitioningHandle( bucketCount, maxCompatibleBucketCount, START BucketFunctionType.HIVE_COMPATIBLE, END Optional.of(hiveTypes), Optional.empty()); } nit: static import

Target:
public static HivePartitioningHandle createHiveCompatiblePartitioningHandle( int bucketCount, List<HiveType> hiveTypes, OptionalInt maxCompatibleBucketCount) { return new HivePartitioningHandle( bucketCount, maxCompatibleBucketCount, HIVE_COMPATIBLE, Optional.of(hiveTypes), Optional.empty()); }
Source:
public static HivePartitioningHandle createPrestoNativePartitioningHandle( int bucketCount, List<Type> types, OptionalInt maxCompatibleBucketCount) { return new HivePartitioningHandle( bucketCount, maxCompatibleBucketCount, START BucketFunctionType.PRESTO_NATIVE, END Optional.empty(), Optional.of(types)); } nit: static import

Target:
public static HivePartitioningHandle createPrestoNativePartitioningHandle( int bucketCount, List<Type> types, OptionalInt maxCompatibleBucketCount) { return new HivePartitioningHandle( bucketCount, maxCompatibleBucketCount, PRESTO_NATIVE, Optional.empty(), Optional.of(types)); }
Source:
public boolean tryReserveMemory(String allocationTag, long delta, boolean enforceBroadcastMemoryLimit) { START if (enforceBroadcastMemoryLimit && !tryUpdateBroadcastMemoryFunction.test(delta)) { END return false; } return tryReserveMemoryFunction.test(allocationTag, delta); } put this after tryReserveMemoryFunctinon.test()... so that local memory limit errors will be thrown first

Target:
public boolean tryReserveMemory(String allocationTag, long delta, boolean enforceBroadcastMemoryLimit) { if (!tryReserveMemoryFunction.test(allocationTag, delta)) { return false; } return !enforceBroadcastMemoryLimit || tryUpdateBroadcastMemoryFunction.test(delta); }
Source:
public Builder addSetupQueryId(String queryId) { START checkState(!this.queryId.isPresent(), "queryId is already set"); END this.setupQueryIds.add(queryId); return this; } is this the right check?

Target:
public Builder addSetupQueryId(String queryId) { this.setupQueryIds.add(queryId); return this; }
Source:
public boolean equals(Object obj) { if (this == obj) { return true; } START if ((obj == null) || (getClass() != obj.getClass())) { END return false; } ErrorMatcher o = (ErrorMatcher) obj; return Objects.equals(errorCode, o.errorCode) && Objects.equals(queryStage, o.queryStage) && Objects.equals(errorMessagePattern, o.errorMessagePattern); } nit: The parentheses in `(obj == null) ` and `(getClass() != obj.getClass())` are not needed

Target:
public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } ErrorMatcher o = (ErrorMatcher) obj; return Objects.equals(errorCode, o.errorCode) && Objects.equals(queryStage, o.queryStage) && Objects.equals(errorMessagePattern, o.errorMessagePattern); }
Source:
public RunningSplitInfo(long startTime, String threadId, Thread thread, PrioritizedSplitRunner split) { this.startTime = startTime; this.threadId = threadId; this.thread = thread; START this.printed = false; END this.split = split; } move this above `this.printed = false;` to align with stack order

Target:
public RunningSplitInfo(long startTime, String threadId, Thread thread, PrioritizedSplitRunner split) { this.startTime = startTime; this.threadId = threadId; this.thread = thread; this.split = split; this.printed = false; }
Source:
protected void setup(Binder binder) { bindAuthenticationModule( config -> config.getDruidAuthenticationType() == DruidConfig.DruidAuthenticationType.NONE, noneAuthenticationModule()); bindAuthenticationModule( config -> config.getDruidAuthenticationType() == DruidConfig.DruidAuthenticationType.BASIC, basicAuthenticationModule()); bindAuthenticationModule( START config -> config.getDruidAuthenticationType() == DruidConfig.DruidAuthenticationType.KERBEROS, END kerberosbAuthenticationModule()); } static import DruidConfig.DruidAuthenticationType.KERBEROS

Target:
protected void setup(Binder binder) { bindAuthenticationModule( config -> config.getDruidAuthenticationType() == NONE, noneAuthenticationModule()); bindAuthenticationModule( config -> config.getDruidAuthenticationType() == BASIC, basicAuthenticationModule()); bindAuthenticationModule( config -> config.getDruidAuthenticationType() == KERBEROS, kerberosbAuthenticationModule()); }
Source:
public void testDefaults() { assertRecordedDefaults(recordDefaults(DruidConfig.class) .setDruidBrokerUrl(null) .setDruidCoordinatorUrl(null) .setDruidSchema("druid") .setComputePushdownEnabled(false) .setHadoopConfiguration("") START .setDruidAuthenticationType(DruidConfig.DruidAuthenticationType.NONE) END .setBasicAuthenticationUsername(null) .setBasicAuthenticationPassword(null)); } static import DruidConfig.DruidAuthenticationType.NONE?

Target:
public void testDefaults() { assertRecordedDefaults(recordDefaults(DruidConfig.class) .setDruidBrokerUrl(null) .setDruidCoordinatorUrl(null) .setDruidSchema("druid") .setComputePushdownEnabled(false) .setHadoopConfiguration("") .setDruidAuthenticationType(NONE) .setBasicAuthenticationUsername(null) .setBasicAuthenticationPassword(null)); }
Source:
public ConnectorPartitioningHandle getPartitioningHandleForExchange(ConnectorSession session, int partitionCount, List<Type> partitionTypes) { return new HivePartitioningHandle( partitionCount, partitionTypes.stream() .map(type -> toHiveType( typeTranslator, translateHiveUnsupportedTypeForTemporaryTable(type, typeManager), getDefaultHiveTypeForTemporaryTable(getTemporaryTableStorageFormat(session)))) .collect(toImmutableList()), START OptionalInt.empty()); END } Let this thing fail for now. Ideally the `HivePartitioningHandle ` shouldn't contain the hive types if the partition handle is for materialized exchange.

Target:
public ConnectorPartitioningHandle getPartitioningHandleForExchange(ConnectorSession session, int partitionCount, List<Type> partitionTypes) { return new HivePartitioningHandle( partitionCount, partitionTypes.stream() .map(type -> toHiveType( typeTranslator, translateHiveUnsupportedTypeForTemporaryTable(type, typeManager))) .collect(toImmutableList()), OptionalInt.empty()); }
Source:
public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CacheQuotaRequirement that = (CacheQuotaRequirement) o; START return cacheQuotaScope == that.cacheQuotaScope && Objects.equals(quota, that.quota); END } Use `Objects.equals` for `cacheQuotaScope`

Target:
public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CacheQuotaRequirement that = (CacheQuotaRequirement) o; return Objects.equals(cacheQuotaScope, that.cacheQuotaScope) && Objects.equals(quota, that.quota); }
Source:
public void start() { if (started.compareAndSet(false, true)) { refreshExecutor.scheduleWithFixedDelay(() -> { try { refreshAndStartQueries(); } catch (Throwable t) { log.error(t, "Error while executing refreshAndStartQueries"); throw t; } START END lastSchedulingCycleRunTimeMs.getAndSet(System.currentTimeMillis()); }, 1, 1, TimeUnit.MILLISECONDS); } } Let's suppress this Exception per the docs: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleWithFixedDelay-java.lang.Runnable-long-long-java.util.concurrent.TimeUnit- Logging should be sufficient.

Target:
public void start() { if (started.compareAndSet(false, true)) { refreshExecutor.scheduleWithFixedDelay(() -> { try { refreshAndStartQueries(); lastSchedulingCycleRunTimeMs.getAndSet(currentTimeMillis()); } catch (Throwable t) { log.error(t, "Error while executing refreshAndStartQueries"); throw t; } }, 1, 1, MILLISECONDS); } }
Source:
public void testDefaults() { assertRecordedDefaults(recordDefaults(DruidConfig.class) .setDruidBrokerUrl(null) .setDruidCoordinatorUrl(null) .setDruidSchema("druid") .setComputePushdownEnabled(false) START .setHadoopConfiguration((String) null)); END } get it. could the following work? `setHadoopConfiguration("") `

Target:
public void testDefaults() { assertRecordedDefaults(recordDefaults(DruidConfig.class) .setDruidBrokerUrl(null) .setDruidCoordinatorUrl(null) .setDruidSchema("druid") .setComputePushdownEnabled(false) .setHadoopConfiguration("")); }
Source:
private OrcCorruptionException propagate(Throwable throwable, String message) { propagateIfPossible(throwable, InvalidFunctionArgumentException.class); START propagateIfPossible(throwable, NotSupportedException.class); END propagateIfPossible(throwable, GenericInternalException.class); return new OrcCorruptionException(throwable, orcDataSourceId, message); } But checking the callsites, I think we need to catch NotSupportedException for getNextPage method in both OrcBatchPageSource and OrcSelectivePageSource. We also need to catch InvalidFunctionArgumentException for OrcBatchPageSource.getNextPage

Target:
private OrcCorruptionException propagate(Throwable throwable, String message) { return new OrcCorruptionException(throwable, orcDataSourceId, message); }
Source:
private KeyProvider toKeyProvider(DwrfProto.Encryption.KeyProvider keyProvider) { START switch (keyProvider) { END case CRYPTO_SERVICE: return KeyProvider.CRYPTO_SERVICE; default: // TODO: should we throw an exception instead? return KeyProvider.UNKNOWN; } } UNKNOWN is basically a stub for anything. For example, during test, we write a file using some fake key provider, and set it to unknown. As long as the reader uses the same key provider, it is able to read the file without making the fake provider an actual provider in the proto

Target:
private static KeyProvider toKeyProvider(DwrfProto.Encryption.KeyProvider keyProvider) { switch (keyProvider) { case CRYPTO_SERVICE: return KeyProvider.CRYPTO_SERVICE; default: return KeyProvider.UNKNOWN; } }
Source:
START private List<EncryptionGroup> toEncryptionGroups(List<DwrfProto.EncryptionGroup> encryptionGroups) END { ImmutableList.Builder<EncryptionGroup> encryptionGroupBuilder = ImmutableList.builder(); for (DwrfProto.EncryptionGroup dwrfEncryptionGroup : encryptionGroups) { encryptionGroupBuilder.add(new EncryptionGroup( dwrfEncryptionGroup.getNodesList(), dwrfEncryptionGroup.hasKeyMetadata() ? Optional.of(byteStringToSlice(dwrfEncryptionGroup.getKeyMetadata())) : Optional.empty(), byteStringToSlice(dwrfEncryptionGroup.getStatistics()))); } return encryptionGroupBuilder.build(); } this method can be static

Target:
private static List<EncryptionGroup> toEncryptionGroups(List<DwrfProto.EncryptionGroup> encryptionGroups) { ImmutableList.Builder<EncryptionGroup> encryptionGroupBuilder = ImmutableList.builder(); for (DwrfProto.EncryptionGroup dwrfEncryptionGroup : encryptionGroups) { encryptionGroupBuilder.add(new EncryptionGroup( dwrfEncryptionGroup.getNodesList(), dwrfEncryptionGroup.hasKeyMetadata() ? Optional.of(byteStringToSlice(dwrfEncryptionGroup.getKeyMetadata())) : Optional.empty(), byteStringToSlice(dwrfEncryptionGroup.getStatistics()))); } return encryptionGroupBuilder.build(); }
Source:
public static <T> Class<? extends T> defineClass(ClassDefinition classDefinition, Class<T> superType, Map<Long, MethodHandle> callSiteBindings, ClassLoader parentClassLoader) { START try { END return defineClass(classDefinition, superType, new DynamicClassLoader(parentClassLoader, callSiteBindings)); } catch (ByteCodeTooLargeException byteCodeTooLargeException) { throw new PrestoException(GENERATED_BYTECODE_TOO_LARGE, ERROR_LARGE_BYTECODE); } } This is not needed if you already handles the exception in the other method?

Target:
public static <T> Class<? extends T> defineClass(ClassDefinition classDefinition, Class<T> superType, Map<Long, MethodHandle> callSiteBindings, ClassLoader parentClassLoader) { return defineClass(classDefinition, superType, new DynamicClassLoader(parentClassLoader, callSiteBindings)); }
Source:
private void testWithAllStorageFormats(BiConsumer<Session, HiveStorageFormat> test) { for (HiveStorageFormat storageFormat : HiveStorageFormat.values()) { Session session = getSession(); if (storageFormat == PAGEFILE) { session = Session.builder(getSession()) START .setCatalogSessionProperty(catalog, "compression_codec", "SNAPPY") END .build(); } test.accept(session, storageFormat); } } Why do we have to reset it here? Is it because the standard, GZIP compression is not supported? How hard is it to simply support it?

Target:
private void testWithAllStorageFormats(BiConsumer<Session, HiveStorageFormat> test) { for (HiveStorageFormat storageFormat : HiveStorageFormat.values()) { test.accept(getSession(), storageFormat); } }
Source:
private Request prepareMetadataQuery(String query) { HttpUriBuilder uriBuilder = uriBuilderFrom(druidBroker).replacePath(SQL_ENDPOINT); return setContentTypeHeaders(preparePost()) .setUri(uriBuilder.build()) START .setBodyGenerator(createStaticBodyGenerator(createRequestBody(query, DruidResultFormat.OBJECT, false))) END .build(); } static import OBJECT, ARRAY_LINES ... ?

Target:
private Request prepareMetadataQuery(String query) { HttpUriBuilder uriBuilder = uriBuilderFrom(druidBroker).replacePath(SQL_ENDPOINT); return setContentTypeHeaders(preparePost()) .setUri(uriBuilder.build()) .setBodyGenerator(createStaticBodyGenerator(createRequestBody(query, OBJECT, false))) .build(); }
Source:
public List<URIStatus> listStatus(AlluxioURI path, ListStatusPOptions options) throws IOException { START List<URIStatus> statuses = Arrays.stream(fileSystem.listStatus(toPath(path))).map(this::toUriStatus).collect(Collectors.toList()); END return statuses; } directly return

Target:
public List<URIStatus> listStatus(AlluxioURI path, ListStatusPOptions options) throws IOException { return Arrays.stream(fileSystem.listStatus(toPath(path))).map(this::toUriStatus).collect(Collectors.toList()); }
Source:
public List<BlockLocationInfo> getBlockLocations(AlluxioURI alluxioURI) throws IOException { START Path path = toPath(alluxioURI); END BlockLocation[] fileBlockLocations = fileSystem.getFileBlockLocations(path, 0, path.toString().length()); Arrays.stream(fileBlockLocations).map(this::toBlockLocationInfo).collect(Collectors.toList()); throw new UnsupportedOperationException("GetBlockLocations is not supported."); } why throw after some operations?

Target:
public List<BlockLocationInfo> getBlockLocations(AlluxioURI alluxioURI) { throw new UnsupportedOperationException("GetBlockLocations is not supported."); }
Source:
public FileInStream openFile(AlluxioURI alluxioURI, OpenFilePOptions options) throws IOException { FSDataInputStream inputStream = fileSystem.open(toPath(alluxioURI)); START return new AlluxioCachingInputStream(inputStream); END } Will this be a problem given we always force to use `FSDataInputStream openFile(Path path, HiveFileContext hiveFileContext)` to open files?

Target:
public FileInStream openFile(AlluxioURI alluxioURI, OpenFilePOptions options) throws IOException { return new AlluxioCachingInputStream(fileSystem.open(toPath(alluxioURI))); }
Source:
public FileStatus getFileStatus(Path path) throws IOException { if (files.containsKey(path)) { return generateURIStatus(path, files.get(path).length); START } END else { throw new FileNotFoundException(path.toString()); } } remove `else`

Target:
public FileStatus getFileStatus(Path path) { if (files.containsKey(path)) { return generateURIStatus(path, files.get(path).length); } return null; }
Source:
private static byte[] createRequestBody(String query, String resultFormat, boolean queryHeader) { START if (!queryHeader) { END return format("{\"query\":\"%s\",\"resultFormat" + "\":\"%s\",\"header\": false }\n", query, resultFormat).getBytes(); } else { return format("{\"query\":\"%s\"}\n", query).getBytes(); } } change the order: if (queryHeader) { return ... } return ...

Target:
private static byte[] createRequestBody(String query, String resultFormat, boolean queryHeader) { if (queryHeader) { return format("{\"query\":\"%s\"}\n", query).getBytes(); } else { return format("{\"query\":\"%s\",\"resultFormat" + "\":\"%s\",\"header\": false }\n", query, resultFormat).getBytes(); } }
Source:
private HiveCompressionCodec getHiveCompressionCodec(ConnectorSession session, boolean isTemporaryTable, HiveStorageFormat storageFormat) { if (isTemporaryTable) { return getTemporaryTableCompressionCodec(session); } START if (storageFormat.equals(ORC) || storageFormat.equals(DWRF)) { END return getOrcCompressionCodec(session); } return getCompressionCodec(session); } - For the purpose of checking compatibility between `StorageFormat` and `HiveCompressionCodec`, you can use `HiveCompressionCodec::isSupportedStorageFormat` - For the purpose of getting ORC specific compression method, you can use `HiveCompressionCodec::orcCompressionKind` - I didn't quite understand why existing `hive.compression-codec` is not good enough.

Target:
private HiveCompressionCodec getHiveCompressionCodec(ConnectorSession session, boolean isTemporaryTable, HiveStorageFormat storageFormat) { if (isTemporaryTable) { return getTemporaryTableCompressionCodec(session); } if (storageFormat == ORC || storageFormat == DWRF) { return getOrcCompressionCodec(session); } return getCompressionCodec(session); }
Source:
public PageFileFooterOutput(List<Long> stripeOffsets) { this.stripeOffsets = ImmutableList.copyOf(requireNonNull(stripeOffsets, "stripeOffsets is null")); START checkArgument(!stripeOffsets.isEmpty(), "stripeOffsets should at least contain offset 0"); END } nit: lets move it before the assignment

Target:
public PageFileFooterOutput(List<Long> stripeOffsets) { this.stripeOffsets = ImmutableList.copyOf(requireNonNull(stripeOffsets, "stripeOffsets is null")); }
Source:
public PageWriter(DataSink dataSink, DataSize pageFileStripeMaxSize) { this.dataSink = requireNonNull(dataSink, "pageDataSink is null"); this.maxBufferedBytes = requireNonNull(pageFileStripeMaxSize, "pageFileStripeMaxSize is null").toBytes(); bufferedPages = new ArrayList<>(); START stripeOffsets = new ArrayList<>(ImmutableList.of(0L)); END } What if there's no stripes? It feels like this should be initialized as empty.

Target:
public PageWriter(DataSink dataSink, DataSize pageFileStripeMaxSize) { this.dataSink = requireNonNull(dataSink, "pageDataSink is null"); this.maxBufferedBytes = requireNonNull(pageFileStripeMaxSize, "pageFileStripeMaxSize is null").toBytes(); bufferedPages = new ArrayList<>(); stripeOffsets = new ArrayList<>(); }
Source:
public boolean hasNext() { START return readBytes < readLength && input.isReadable(); END } Instead of keeping track of `readBytes` you can use `ByteStreams#limit`

Target:
public boolean hasNext() { return input.position() < readLength && input.isReadable(); }
Source:
PageFilePageReader( START long readStart, END long readLength, FSDataInputStream inputStream, PagesSerde pagesSerde) throws IOException { this.pagesSerde = requireNonNull(pagesSerde, "pagesSerde is null"); this.readLength = readLength; requireNonNull(inputStream, "inputStream is null"); inputStream.seek(readStart); this.input = new InputStreamSliceInput(inputStream); } How about passing an already positioned and limited input stream? (doing `inputStream.seek(readStart);` and `ByteStreams#limit` outside)? If you do that then most likely you won't even need this class.

Target:
public PageFilePageReader( long readStart, long readLength, FSDataInputStream inputStream, PagesSerde pagesSerde) throws IOException { this.pagesSerde = requireNonNull(pagesSerde, "pagesSerde is null"); this.readLength = readLength; requireNonNull(inputStream, "inputStream is null"); inputStream.seek(readStart); this.input = new InputStreamSliceInput(inputStream); }
Source:
public void close() { if (closed) { return; } closed = true; START block = null; END Throwable innerException = null; for (Closer closer : closers) { try { closer.close(); } catch (Throwable t) { if (innerException == null) { innerException = t; } else if (innerException != t) { // Self-suppression not permitted innerException.addSuppressed(t); } } } if (innerException != null) { // Convert to unchecked exception throw new RuntimeException(innerException); } } This change is problematic. The lease doesn't own the block and the same block can be used to create multiple leases.

Target:
public void close() { if (closed) { return; } closed = true; Throwable innerException = null; for (Closer closer : closers) { try { closer.close(); } catch (Throwable t) { if (innerException == null) { innerException = t; } else if (innerException != t) { // Self-suppression not permitted innerException.addSuppressed(t); } } } if (innerException != null) { // Convert to unchecked exception throw new RuntimeException(innerException); } }
Source:
public HiveOrcAggregatedMemoryContext() { START this.delegate = newSimpleAggregatedMemoryContext(); END } `this(this.delegate = newSimpleAggregatedMemoryContext());`

Target:
public HiveOrcAggregatedMemoryContext() { this(newSimpleAggregatedMemoryContext()); }
Source:
public void write(SerializedPage page) throws IOException { retainedBytes += page.getRetainedSizeInBytes(); PageDataOutput pageDataOutput = new PageDataOutput(page); long writtenSize = pageDataOutput.size(); START if (maxBufferedBytes - bufferedBytes < writtenSize) { END dataSink.write(bufferedPages); bufferedPages.clear(); bufferedBytes = 0; retainedBytes = 0; } else { bufferedPages.add(new PageDataOutput(page)); bufferedBytes += writtenSize; } } Given that this bug wasn't caught by test I would suggest improving the test (or adding a unit test) to cover this case.

Target:
public void write(SerializedPage page) throws IOException { PageDataOutput pageDataOutput = new PageDataOutput(page); long writtenSize = pageDataOutput.size(); if (maxBufferedBytes - bufferedBytes < writtenSize) { dataSink.write(bufferedPages); bufferedPages.clear(); bufferedBytes = 0; retainedBytes = 0; } bufferedPages.add(pageDataOutput); bufferedBytes += writtenSize; retainedBytes += page.getRetainedSizeInBytes(); }
Source:
public CachedTableChecker(List<String> cachedTables) { START this.cacheAllTables = cachedTables.contains("*"); END if (cacheAllTables) { checkArgument(cachedTables.size() == 1, "Only '*' is expected when caching all tables"); this.cachedTableNames = ImmutableSet.of(); } else { this.cachedTableNames = cachedTables.stream() .map(CachingDirectoryLister::parseTableName) .collect(toImmutableSet()); } } s/this.cacheAllTables/cacheAllTables/g I think we prefer not to use this to reference variables

Target:
public CachedTableChecker(List<String> cachedTables) { cacheAllTables = cachedTables.contains("*"); if (cacheAllTables) { checkArgument(cachedTables.size() == 1, "Only '*' is expected when caching all tables"); this.cachedTableNames = ImmutableSet.of(); } else { this.cachedTableNames = cachedTables.stream() .map(CachingDirectoryLister::parseTableName) .collect(toImmutableSet()); } }
Source:
public static Slice stSphericalAsText(@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) Slice input) { if (input == null) { START return utf8Slice("POINT EMPTY"); END } return utf8Slice(wktFromJtsGeometry(deserialize(input))); } If the input is null, the output should be null. ScalarFunctions do this automatically, unless you use the `@SqlNullable` annotation.

Target:
public static Slice stSphericalAsText(@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) Slice input) { return utf8Slice(wktFromJtsGeometry(deserialize(input))); }
Source:
public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, block.getSliceLength(position)); START if (slice == Slices.EMPTY_SLICE) { return null; } END return deserialize(slice).asText(); } Remove this by returning null above.

Target:
public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } Slice slice = block.getSlice(position, 0, block.getSliceLength(position)); return deserialize(slice).asText(); }
Source:
public void serializeTo(SliceOutput output) { writeLengthPrefixedString(output, NAME); output.writeInt(bufferedPositionCount); serializeNullsTo(output); if (valuesBufferIndex > 0) { try { output.appendBytes(valuesBuffer, 0, valuesBufferIndex); } catch (Exception e) { START e.printStackTrace(); END } } } @yingsu00 debugging leftovers?

Target:
public void serializeTo(SliceOutput output) { writeLengthPrefixedString(output, NAME); output.writeInt(bufferedPositionCount); serializeNullsTo(output); if (valuesBufferIndex > 0) { output.appendBytes(valuesBuffer, 0, valuesBufferIndex); } }
Source:
START public String getClientInfo() END { return clientInfo.orElse(null); } just return `Optional<String>` that way the implementation can decide what to do if the value is not present.

Target:
public Optional<String> getClientInfo() { return clientInfo; }
Source:
public void addInput(Page page) { requireNonNull(page, "page is null"); if (page.getPositionCount() == 0) { return; } page = pagePreprocessor.apply(page); pagePartitioner.partitionPage(page); START System.out.println(pagePartitioner.getRetainedSizeInBytes()); END // TODO: PartitionedOutputOperator reports incorrect output data size #11770 operatorContext.recordOutput(page.getSizeInBytes(), page.getPositionCount()); systemMemoryContext.setBytes(pagePartitioner.getRetainedSizeInBytes()); } Debugging? Remove.

Target:
public void addInput(Page page) { requireNonNull(page, "page is null"); if (page.getPositionCount() == 0) { return; } page = pagePreprocessor.apply(page); pagePartitioner.partitionPage(page); // TODO: PartitionedOutputOperator reports incorrect output data size #11770 operatorContext.recordOutput(page.getSizeInBytes(), page.getPositionCount()); systemMemoryContext.setBytes(pagePartitioner.getRetainedSizeInBytes()); }
Source:
public FunctionImplementationType getFunctionImplementationType() { START switch (routineCharacteristics.getLanguage()) { case SQL: return FunctionImplementationType.SQL; case JAVA: return FunctionImplementationType.THRIFT; END default: throw new UnsupportedOperationException(format("Unsupported language %s", routineCharacteristics.getLanguage())); } } Using a static map would be easier?

Target:
public FunctionImplementationType getFunctionImplementationType() { if (routineCharacteristics.getLanguage().equals(SQL)) { return FunctionImplementationType.SQL; } return FunctionImplementationType.THRIFT; }
Source:
public void setTaskLimitExceeded(boolean exceeded) { START this.taskLimitExceeded.set(exceeded); END } nit: drop "this."

Target:
public void setTaskLimitExceeded(boolean exceeded) { taskLimitExceeded.set(exceeded); }
Source:
START public Optional<HostAddress> getAddress() END { return address; } remove

Target:
public HostAddress getAddress() { return address.isPresent() ? address.get() : null; }
Source:
public DruidQueryGeneratorContext withOutputColumns(List<VariableReferenceExpression> outputColumns) { START LinkedHashMap<VariableReferenceExpression, Selection> newSelections = new LinkedHashMap<>(); END outputColumns.forEach(o -> newSelections.put(o, requireNonNull(selections.get(o), "Cannot find the selection " + o + " in the original context " + this))); return new DruidQueryGeneratorContext(newSelections, from, filter); } Can we replace all these to map?

Target:
public DruidQueryGeneratorContext withOutputColumns(List<VariableReferenceExpression> outputColumns) { Map<VariableReferenceExpression, Selection> newSelections = new LinkedHashMap<>(); outputColumns.forEach(o -> newSelections.put(o, requireNonNull(selections.get(o), "Cannot find the selection " + o + " in the original context " + this))); return new DruidQueryGeneratorContext(newSelections, from, filter); }
Source:
public TestTpchTaskUpdateSizeLimitIntegrationTest() { START this(() -> createQueryRunner(ImmutableMap.of("experimental.internal-communication.max-task-update-size", "100B"))); END } `super(() -> createQueryRunner(ImmutableMap.of("experimental.internal-communication.max-task-update-size", "100B")));`

Target:
public TestTpchTaskUpdateSizeLimitIntegrationTest() { super(() -> createQueryRunner(ImmutableMap.of("experimental.internal-communication.max-task-update-size", "100B"))); }
Source:
MissingFieldStreamReader(Type type) { START requireNonNull(type, "type is required"); END this.outputType = type; } combine with assignment `this.outputType = requireNonNull(type, "type is required");`

Target:
MissingFieldStreamReader(Type type) { this.outputType = requireNonNull(type, "type is required"); }
Source:
public Optional<List<InternalNode>> getBucketToNode() { START if (bucketToNodeInfo.size() == 0) { END return Optional.empty(); } return Optional.of(bucketToNodeInfo.values().stream().map(InternalNodeInfo::getInternalNode).collect(Collectors.toList())); } `bucketToNodeInfo.isEmpty()`

Target:
public Optional<List<InternalNode>> getBucketToNode() { if (bucketToNodeInfo.isEmpty()) { return Optional.empty(); } return Optional.of(bucketToNodeInfo.values().stream().map(InternalNodeInfo::getInternalNode).collect(Collectors.toList())); }
Source:
public static Block ipSubnetRange(@SqlType(StandardTypes.IPPREFIX) Slice value) { START validateIpPrefixAndGetBytes(value); END BlockBuilder blockBuilder = IPADDRESS.createBlockBuilder(null, 2); IPADDRESS.writeSlice(blockBuilder, ipSubnetMin(value)); IPADDRESS.writeSlice(blockBuilder, ipSubnetMax(value)); return blockBuilder.build(); } The `value` is validated 3 times in this function.

Target:
public static Block ipSubnetRange(@SqlType(StandardTypes.IPPREFIX) Slice value) { BlockBuilder blockBuilder = IPADDRESS.createBlockBuilder(null, 2); IPADDRESS.writeSlice(blockBuilder, ipSubnetMin(value)); IPADDRESS.writeSlice(blockBuilder, ipSubnetMax(value)); return blockBuilder.build(); }
Source:
public static Slice ipSubnetMin(@SqlType(StandardTypes.IPPREFIX) Slice value) { START validateIpPrefixAndGetBytes(value); END return castFromIpPrefixToIpAddress(value); } The input has to be a valid ipprefix so you don't need to validate it.

Target:
public static Slice ipSubnetMin(@SqlType(StandardTypes.IPPREFIX) Slice value) { return castFromIpPrefixToIpAddress(value); }
Source:
public void testIpSubnetMin() { assertFunction("IP_SUBNET_MIN(IPPREFIX '1.2.3.4/24')", IPADDRESS, "1.2.3.0"); assertFunction("IP_SUBNET_MIN(IPPREFIX '1.2.3.4/32')", IPADDRESS, "1.2.3.4"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/64')", IPADDRESS, "64:ff9b::"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/127')", IPADDRESS, "64:ff9b::16"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/128')", IPADDRESS, "64:ff9b::17"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/0')", IPADDRESS, "::"); START assertInvalidCast("IP_SUBNET_MIN(IPPREFIX '64::ff9b::10/48')", "Cannot cast value to IPPREFIX: 64::ff9b::10/48"); assertInvalidCast("IP_SUBNET_MIN(IPPREFIX '123.456.789.012/24')", "Cannot cast value to IPPREFIX: 123.456.789.012/24"); END } Those 2 test cases do not belong to this test method. Unlike the `IP_PREFIX`, which can take `VARCHAR` as the input, those 2 test cases are not testing the behavior of `IP_SUBNET_MIN`, but the behavior of casting `VARCHAR` to `IPPREFIX`.

Target:
public void testIpSubnetMin() { assertFunction("IP_SUBNET_MIN(IPPREFIX '1.2.3.4/24')", IPADDRESS, "1.2.3.0"); assertFunction("IP_SUBNET_MIN(IPPREFIX '1.2.3.4/32')", IPADDRESS, "1.2.3.4"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/64')", IPADDRESS, "64:ff9b::"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/127')", IPADDRESS, "64:ff9b::16"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/128')", IPADDRESS, "64:ff9b::17"); assertFunction("IP_SUBNET_MIN(IPPREFIX '64:ff9b::17/0')", IPADDRESS, "::"); }
Source:
public void testIpSubnetMax() { assertFunction("IP_SUBNET_MAX(IPPREFIX '1.2.3.128/26')", IPADDRESS, "1.2.3.191"); assertFunction("IP_SUBNET_MAX(IPPREFIX '192.168.128.4/32')", IPADDRESS, "192.168.128.4"); assertFunction("IP_SUBNET_MAX(IPPREFIX '10.1.16.3/9')", IPADDRESS, "10.127.255.255"); assertFunction("IP_SUBNET_MAX(IPPREFIX '2001:db8::16/127')", IPADDRESS, "2001:db8::17"); assertFunction("IP_SUBNET_MAX(IPPREFIX '2001:db8::16/128')", IPADDRESS, "2001:db8::16"); assertFunction("IP_SUBNET_MAX(IPPREFIX '64:ff9b::17/64')", IPADDRESS, "64:ff9b::ffff:ffff:ffff:ffff"); assertFunction("IP_SUBNET_MAX(IPPREFIX '64:ff9b::17/72')", IPADDRESS, "64:ff9b::ff:ffff:ffff:ffff"); assertFunction("IP_SUBNET_MAX(IPPREFIX '64:ff9b::17/0')", IPADDRESS, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); START assertInvalidCast("IP_SUBNET_MAX(IPPREFIX '64::ff9b::10/24')", "Cannot cast value to IPPREFIX: 64::ff9b::10/24"); assertInvalidCast("IP_SUBNET_MAX(IPPREFIX '123.456.789.012/-1')", "Cannot cast value to IPPREFIX: 123.456.789.012/-1"); END } Same here, remove.

Target:
public void testIpSubnetMax() { assertFunction("IP_SUBNET_MAX(IPPREFIX '1.2.3.128/26')", IPADDRESS, "1.2.3.191"); assertFunction("IP_SUBNET_MAX(IPPREFIX '192.168.128.4/32')", IPADDRESS, "192.168.128.4"); assertFunction("IP_SUBNET_MAX(IPPREFIX '10.1.16.3/9')", IPADDRESS, "10.127.255.255"); assertFunction("IP_SUBNET_MAX(IPPREFIX '2001:db8::16/127')", IPADDRESS, "2001:db8::17"); assertFunction("IP_SUBNET_MAX(IPPREFIX '2001:db8::16/128')", IPADDRESS, "2001:db8::16"); assertFunction("IP_SUBNET_MAX(IPPREFIX '64:ff9b::17/64')", IPADDRESS, "64:ff9b::ffff:ffff:ffff:ffff"); assertFunction("IP_SUBNET_MAX(IPPREFIX '64:ff9b::17/72')", IPADDRESS, "64:ff9b::ff:ffff:ffff:ffff"); assertFunction("IP_SUBNET_MAX(IPPREFIX '64:ff9b::17/0')", IPADDRESS, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); }
Source:
public Block readBlock(Type type, int batchSize) START throws IOException END { checkArgument(type == DOUBLE); BlockBuilder builder = type.createBlockBuilder(null, batchSize); for (int i = 0; i < batchSize; ++i) { type.writeDouble(builder, valueSelector.getDouble()); } return builder.build(); } not needed; same for other readers

Target:
public Block readBlock(Type type, int batchSize) { checkArgument(type == DOUBLE); BlockBuilder builder = type.createBlockBuilder(null, batchSize); for (int i = 0; i < batchSize; i++) { type.writeDouble(builder, valueSelector.getDouble()); } return builder.build(); }
Source:
public int getOffset() { int offset = row; START ++row; END return offset; } it's weird to increment `row` inside `getOffset`. How about having this class inheriting `Offset` rather than `ReadableOffset`?

Target:
public int getOffset() { // have to update row in getOffset, as BaseColumn requires ReadableOffset in makeColumnValuesSelector int offset = row; row++; return offset; }
Source:
private static int chunkedRead(InflaterInputStream inflaterInputStream, byte[] buffer, int offset, int length) throws IOException { int position = offset; int bytesRead = 0; START while (((position - offset) < length) && bytesRead != -1) { END bytesRead = inflaterInputStream.read(buffer, position, offset + length - position); if (bytesRead > 0) { position += bytesRead; } } return position - offset; } nit: ``` while (position - offset < length && bytesRead != -1) { ```

Target:
private static int chunkedRead(InflaterInputStream inflaterInputStream, byte[] buffer, int offset, int length) throws IOException { int position = offset; int bytesRead = 0; while (position - offset < length && bytesRead != -1) { bytesRead = inflaterInputStream.read(buffer, position, offset + length - position); if (bytesRead > 0) { position += bytesRead; } } return position - offset; }
Source:
public ZipIndexFileSource(DataInputSource dataInputSource) { this.dataInputSource = requireNonNull(dataInputSource, "dataInputSource is null"); START this.zipData = readCentralDirectory(); END } put this on stack

Target:
public ZipIndexFileSource(DataInputSource dataInputSource) { this.dataInputSource = requireNonNull(dataInputSource, "dataInputSource is null"); zipData = readCentralDirectory(); }
Source:
START private boolean isEntireColumn(Subfield subfield) END { return subfield.getPath().isEmpty(); } static, same for other helpers

Target:
private static boolean isEntireColumn(Subfield subfield) { return subfield.getPath().isEmpty(); }
Source:
public Optional<ReadMapping> toPrestoType(ConnectorSession session, JdbcTypeHandle typeHandle) { START if (typeHandle.getJdbcType() == microsoft.sql.Types.DATETIMEOFFSET) { END return Optional.of(dateTimeOffsetReadMapping()); } return super.toPrestoType(session, typeHandle); } Static import `DATETIMEOFFSET`

Target:
public Optional<ReadMapping> toPrestoType(ConnectorSession session, JdbcTypeHandle typeHandle) { if (typeHandle.getJdbcType() == DATETIMEOFFSET) { return Optional.of(dateTimeOffsetReadMapping()); } return super.toPrestoType(session, typeHandle); }
Source:
START public FunctionImplementationType getFunctionImplementationType() END { return SQL; } This should be a function derived from `RoutineCharacteristics.language`. Actually is it better to expose language rather than implementation type?

Target:
public FunctionImplementationType getFunctionImplementationType() { return FunctionImplementationType.SQL; }
Source:
START private List<InternalNode> convertToInternalNode(NodeMap nodeMap, List<HostAddress> preferredNodes) END { List<InternalNode> internalNodes = new ArrayList<>(); preferredNodes.stream().forEach(node -> internalNodes.addAll(nodeMap.getNodesByHostAndPort().get(node))); return ImmutableList.copyOf(internalNodes); } static

Target:
private static List<InternalNode> convertToInternalNode(NodeMap nodeMap, List<HostAddress> preferredNodes) { List<InternalNode> internalNodes = new ArrayList<>(); preferredNodes.forEach(node -> internalNodes.addAll(nodeMap.getNodesByHostAndPort().get(node))); return ImmutableList.copyOf(internalNodes); }
Source:
public void testEmptyNodeSelectionStrategyConfig() { ConnectorSession connectorSession = new TestingConnectorSession( new HiveSessionProperties( new HiveClientConfig(), new OrcFileWriterConfig(), new ParquetFileWriterConfig()).getSessionProperties()); START assertEquals(getNodeSelectionStrategy(connectorSession), NodeSelectionStrategy.NO_PREFERENCE); END } static import?

Target:
public void testEmptyNodeSelectionStrategyConfig() { ConnectorSession connectorSession = new TestingConnectorSession( new HiveSessionProperties( new HiveClientConfig(), new OrcFileWriterConfig(), new ParquetFileWriterConfig()).getSessionProperties()); assertEquals(getNodeSelectionStrategy(connectorSession), NO_PREFERENCE); }
Source:
public NodeSelectionStrategy getNodeSelectionStrategy() { START return NodeSelectionStrategy.HARD_AFFINITY; END } static import

Target:
public NodeSelectionStrategy getNodeSelectionStrategy() { return HARD_AFFINITY; }
Source:
public void testDefaults() { assertRecordedDefaults(ConfigAssertions.recordDefaults(DbResourceGroupConfig.class) .setConfigDbUrl(null) .setMaxRefreshInterval(new Duration(1, HOURS)) START .setReloadRefreshInterval(new Duration(1, SECONDS)) END .setExactMatchSelectorEnabled(false)); } Would this compile?

Target:
public void testDefaults() { assertRecordedDefaults(ConfigAssertions.recordDefaults(DbResourceGroupConfig.class) .setConfigDbUrl(null) .setMaxRefreshInterval(new Duration(1, HOURS)) .setExactMatchSelectorEnabled(false)); }
Source:
START protected BytesRange(byte[] lower, boolean lowerExclusive, byte[] upper, boolean upperExclusive, boolean nullAllowed) END { super(true, nullAllowed); this.lower = lower; this.upper = upper; this.lowerExclusive = lowerExclusive; this.upperExclusive = upperExclusive; this.singleValue = !lowerExclusive && !upperExclusive && Arrays.equals(upper, lower); } keep this private

Target:
private BytesRange(byte[] lower, boolean lowerExclusive, byte[] upper, boolean upperExclusive, boolean nullAllowed) { super(true, nullAllowed); this.lower = lower; this.upper = upper; this.lowerExclusive = lowerExclusive; this.upperExclusive = upperExclusive; this.singleValue = !lowerExclusive && !upperExclusive && Arrays.equals(upper, lower); }
Source:
public RaptorCachingHdfsConfiguration( @ForCachingFileSystem RaptorHdfsConfiguration hiveHdfsConfiguration, CacheConfig cacheConfig, CacheManager cacheManager) { this.hiveHdfsConfiguration = requireNonNull(hiveHdfsConfiguration, "hiveHdfsConfiguration is null"); this.cacheManager = requireNonNull(cacheManager, "CacheManager is null"); START cacheConfig = requireNonNull(cacheConfig, "cacheConfig is null"); END this.cacheValidationEnabled = cacheConfig.isValidationEnabled(); } nit: `this.cacheValidationEnabled = requireNonNull(cacheConfig, "cacheConfig is null").isValidationEnabled();`

Target:
public RaptorCachingHdfsConfiguration( @ForCachingFileSystem RaptorHdfsConfiguration hiveHdfsConfiguration, CacheConfig cacheConfig, CacheManager cacheManager) { this.hiveHdfsConfiguration = requireNonNull(hiveHdfsConfiguration, "hiveHdfsConfiguration is null"); this.cacheManager = requireNonNull(cacheManager, "CacheManager is null"); this.cacheValidationEnabled = requireNonNull(cacheConfig, "cacheConfig is null").isValidationEnabled(); }
Source:
private PlanBuilder planBuilderFor(PlanBuilder builder, Scope scope, Iterable<? extends Expression> expressionsToRemap) { PlanBuilder newBuilder = planBuilderFor(builder, scope); START for (Expression expression : expressionsToRemap) { END // We can't deduplicate expressions here because even if two expressions are equal, // the TranslationMap maps sql names to symbols, and any lambda expressions will be // resolved differently since the lambdaDeclarationToVariableMap is identity based. newBuilder.getTranslations().put(expression, builder.translate(expression)); } return newBuilder; } Maybe just do ``` stream(expressionsToRemap) .forEach(expression -> newBuilder.getTranslations().put(expression, builder.translate(expression))); ``` I don't have strong opinions. Just that overall the codebase seems to prefer stream API when logic is simple.

Target:
private PlanBuilder planBuilderFor(PlanBuilder builder, Scope scope, Iterable<? extends Expression> expressionsToRemap) { PlanBuilder newBuilder = planBuilderFor(builder, scope); // We can't deduplicate expressions here because even if two expressions are equal, // the TranslationMap maps sql names to symbols, and any lambda expressions will be // resolved differently since the lambdaDeclarationToVariableMap is identity based. stream(expressionsToRemap) .forEach(expression -> newBuilder.getTranslations().put(expression, builder.translate(expression))); return newBuilder; }
Source:
public TestHiveDistributedQueries() { super(() -> createQueryRunner( getTables(), START ImmutableMap.of("internal-communication.task-communication-protocol", "THRIFT"), END ImmutableMap.of(), Optional.empty())); } I think the convention these days is to "fork" `TestHiveDistributedQueries`, such as `TestHiveDistributedQueriesWithOptimizedRepartitioning`, `TestHivePushdownDistributedQueries`, `TestHiveDistributedQueriesWithExchangeMaterialization`. I do agree in this case it doesn't seem that necessary (since HTTP has been covered by other tests)... but following the convention doesn't seem to hurt :)

Target:
public TestHiveDistributedQueries() { super(() -> createQueryRunner(getTables())); }
Source:
public void acknowledgeResultsAsync(long nextToken) { executor.execute(() -> { try { START thriftClient.acknowledgeResults(taskId, outputBufferId, nextToken); END } catch (Exception exception) { log.debug(exception, "Acknowledge request failed: %s/%s/%s", taskId, outputBufferId, nextToken); } }); } Instead of popping this into an executor, can we instead just make the Thrift interface async? We don't need to handle the future if we don't care about the result.

Target:
public void acknowledgeResultsAsync(long nextToken) { // no need to handle the future thriftClient.acknowledgeResults(taskId, outputBufferId, nextToken); }