auphong2707/dl4se-code-review-dataset huggingface dataset:
Source:
private boolean canRemoveExchange(MajorFragmentStat parentFrag, MajorFragmentStat childFrag) { START return (childFrag.isSingular() && parentFrag.isSingular() && END (!childFrag.isDistributionStrict() || !parentFrag.isDistributionStrict())) || parentFrag.isRightSideOfLateral(); } For better readability, Since the lateral check is independent of the others, can you split it into a separate statement ?

Target:
private boolean canRemoveExchange(MajorFragmentStat parentFrag, MajorFragmentStat childFrag) { if (childFrag.isSingular() && parentFrag.isSingular() && (!childFrag.isDistributionStrict() || !parentFrag.isDistributionStrict())) { return true; } if (parentFrag.isRightSideOfLateral()) { return true; } return false; }
Source:
public void mergeScanSpec(String functionName, KafkaPartitionScanSpec scanSpec) { switch (functionName) { case "booleanAnd": //Reduce the scan range if(startOffset < scanSpec.startOffset) { startOffset = scanSpec.startOffset; } if(endOffset > scanSpec.endOffset) { endOffset = scanSpec.endOffset; } break; case "booleanOr": //Increase the scan range if(scanSpec.startOffset < startOffset) { startOffset = scanSpec.startOffset; } if(scanSpec.endOffset > endOffset) { endOffset = scanSpec.endOffset; } START break; END default: assert(false); } } Here we no need to fail for default. In other plugin's default, it will create empty ScanSpec.

Target:
public void mergeScanSpec(String functionName, KafkaPartitionScanSpec scanSpec) { switch (functionName) { case "booleanAnd": //Reduce the scan range if(startOffset < scanSpec.startOffset) { startOffset = scanSpec.startOffset; } if(endOffset > scanSpec.endOffset) { endOffset = scanSpec.endOffset; } break; case "booleanOr": //Increase the scan range if(scanSpec.startOffset < startOffset) { startOffset = scanSpec.startOffset; } if(scanSpec.endOffset > endOffset) { endOffset = scanSpec.endOffset; } break; } }
Source:
public Set<String> getTableNames() { if (tables == null) { try { START tables = Sets.newHashSet(mClient.getTableNames(this.name, schemaConfig.getIgnoreAuthErrors())); END } catch (final TException e) { logger.warn("Failure while attempting to access HiveDatabase '{}'.", this.name, e.getCause()); tables = new HashSet<>(); // empty set. } } return tables; } new `HashSet<>(...)`?

Target:
public Set<String> getTableNames() { if (tables == null) { try { tables = Sets.newHashSet(mClient.getTableNames(this.name, schemaConfig.getIgnoreAuthErrors())); } catch (final TException e) { logger.warn("Failure while attempting to access HiveDatabase '{}'.", this.name, e.getCause()); tables = Sets.newHashSet(); // empty set. } } return tables; }
Source:
START AbstractFieldReader() { END super(); } You can remove `super()`.

Target:
AbstractFieldReader() { }
Source:
START private NullReader() { END super(); type = Types.NULL; } Please remove `super()` here and below.

Target:
private NullReader() { type = Types.NULL; }
Source:
START public void allocateVectors(VectorContainer container) { END // Allocate memory for the vectors. // This will iteratively allocate memory for all nested columns underneath. for (VectorWrapper w : container) { RecordBatchSizer.ColumnSize colSize = getColumnSize(w.getField().getName()); colSize.allocateVector(w.getValueVector(), outputRowCount); } } Cleaner implementation: Just call the following method, with outputRowCount as the second parameter.

Target:
public void allocateVectors(VectorContainer container) { allocateVectors(container, outputRowCount); }
Source:
@Override public final void setup(FragmentContext context, RecordBatch incoming, RecordBatch outgoing, List<TransferPair> transfers, LateralContract lateral) throws SchemaChangeException { this.svMode = incoming.getSchema().getSelectionVectorMode(); START switch (svMode) { END case FOUR_BYTE: throw new UnsupportedOperationException("Unnest does not support selection vector inputs."); case TWO_BYTE: throw new UnsupportedOperationException("Unnest does not support selection vector inputs."); } this.transfers = ImmutableList.copyOf(transfers); this.lateral = lateral; } Could be simplified to if(svMode != SelectionVectorMode.NONE)

Target:
public final void setup(FragmentContext context, RecordBatch incoming, RecordBatch outgoing, List<TransferPair> transfers, LateralContract lateral) throws SchemaChangeException { this.svMode = incoming.getSchema().getSelectionVectorMode(); if (svMode == NONE) { this.transfers = ImmutableList.copyOf(transfers); this.lateral = lateral; } else { throw new UnsupportedOperationException("Unnest does not support selection vector inputs."); } }
Source:
public void testFilterPushDownForExternalTable() throws Exception { String query = "select * from hive.kv_native_ext where key = 1"; int actualRowCount = testSql(query); assertEquals("Expected and actual row count should match", 1, actualRowCount); testPlanMatchingPatterns(query, START new String[]{"HiveDrillNativeParquetScan", "numFiles=1"}, new String[]{}); END } I have added method without `excludedPatterns`, when it is not necessary. But it is not merged for now. Is it better to pass null, than to create empty String?

Target:
public void testFilterPushDownForExternalTable() throws Exception { String query = "select * from hive.kv_native_ext where key = 1"; int actualRowCount = testSql(query); assertEquals("Expected and actual row count should match", 1, actualRowCount); testPlanMatchingPatterns(query, new String[]{"HiveDrillNativeParquetScan", "numFiles=1"}, null); }
Source:
public void flushOutgoingBatches(boolean isLastBatch, boolean schemaChanged) throws IOException, InterruptedException { for (OutgoingRecordBatch batch : outgoingBatches) { if (Thread.interrupted()) { START throw new InterruptedException(); END } logger.debug("Attempting to flush all outgoing batches"); if (isLastBatch) { batch.setIsLast(); } batch.flush(schemaChanged); if (schemaChanged) { batch.resetBatch(); batch.initializeBatch(); } } } Since we are checking for interrupts here already could we remove `Thread.currentThread().isInterrupted()` in the flush(boolean schemaChanged) method?

Target:
public void flushOutgoingBatches(boolean isLastBatch, boolean schemaChanged) throws IOException { for (OutgoingRecordBatch batch : outgoingBatches) { logger.debug("Attempting to flush all outgoing batches"); if (isLastBatch) { batch.setIsLast(); } batch.flush(schemaChanged); if (schemaChanged) { batch.resetBatch(); batch.initializeBatch(); } } }
Source:
public boolean isRunning() { START if (embeddedJetty == null || embeddedJetty.getConnectors().length != 1) { END return false; } return true; } Method code can be simplified to one line.

Target:
public boolean isRunning() { return (embeddedJetty != null && embeddedJetty.getConnectors().length == 1); }
Source:
private int getSpillCycleMetricIndex(CoreOperatorType operatorType) { START String metricName = null; END switch (operatorType) { case EXTERNAL_SORT: metricName = "SPILL_COUNT"; break; case HASH_AGGREGATE: case HASH_JOIN: metricName = "SPILL_CYCLE"; break; default: return NO_SPILL_METRIC_INDEX; } int metricIndex = 0; //Default String[] metricNames = OperatorMetricRegistry.getMetricNames(operatorType.getNumber()); for (String name : metricNames) { if (name.equalsIgnoreCase(metricName)) { return metricIndex; } metricIndex++; } //Backward compatibility with rendering older profiles. Ideally we should never touch this if an expected metric is not there return NO_SPILL_METRIC_INDEX; } Initializing with null is redundant.

Target:
private int getSpillCycleMetricIndex(CoreOperatorType operatorType) { String metricName; switch (operatorType) { case EXTERNAL_SORT: metricName = "SPILL_COUNT"; break; case HASH_AGGREGATE: case HASH_JOIN: metricName = "SPILL_CYCLE"; break; default: return NO_SPILL_METRIC_INDEX; } int metricIndex = 0; //Default String[] metricNames = OperatorMetricRegistry.getMetricNames(operatorType.getNumber()); for (String name : metricNames) { if (name.equalsIgnoreCase(metricName)) { return metricIndex; } metricIndex++; } //Backward compatibility with rendering older profiles. Ideally we should never touch this if an expected metric is not there return NO_SPILL_METRIC_INDEX; }
Source:
public void sortOneKeyAscending() throws Throwable { ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher) START .configProperty(CodeCompiler.ENABLE_SAVE_CODE_FOR_DEBUG_TOPN, true); END try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { TestBuilder testBuilder = new TestBuilder(new ClusterFixture.FixtureTestServices(client)); testBuilder.ordered() .physicalPlanFromFile("topN/one_key_sort.json") .baselineColumns("blue") .go(); } } I think this line should be also removed since `ENABLE_SAVE_CODE_FOR_DEBUG_TOPN` should be disabled for tests.

Target:
public void sortOneKeyAscending() throws Throwable { ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { TestBuilder testBuilder = new TestBuilder(new ClusterFixture.FixtureTestServices(client)); testBuilder.ordered() .physicalPlanFromFile("topN/one_key_sort.json") .baselineColumns("blue") .go(); } }
Source:
START private BitRpcUtility() throws Exception { END throw new UnsupportedOperationException("BitRpcUtility is a utility class and should not be instantiated."); } Exception is not required, just make the constructor private.

Target:
private BitRpcUtility() { }
Source:
protected void log(final String name, final PhysicalPlan plan, final Logger logger) throws JsonProcessingException { if (logger.isDebugEnabled()) { START PropertyFilter theFilter = new SimpleBeanPropertyFilter.SerializeExceptFilter(Sets.newHashSet("password")); END String planText = plan.unparse(context.getLpPersistence().getMapper() .writer(new SimpleFilterProvider().addFilter("passwordFilter", theFilter))); logger.debug(name + " : \n" + planText); } } Please rename to `filter`.

Target:
protected void log(final String name, final PhysicalPlan plan, final Logger logger) throws JsonProcessingException { if (logger.isDebugEnabled()) { PropertyFilter filter = new SimpleBeanPropertyFilter.SerializeExceptFilter(Sets.newHashSet("password")); String planText = plan.unparse(context.getLpPersistence().getMapper() .writer(new SimpleFilterProvider().addFilter("passwordFilter", filter))); logger.debug(name + " : \n" + planText); } }
Source:
public void close() throws Exception { START in.close(); END } `in` is not set until `setup()` time. If something goes wrong, Drill might call `close()` before calling `setup()`. For safety, maybe check if `in` is not null.

Target:
public void close() throws Exception { if (in != null) { in.close(); in = null; } }
Source:
private ProjectedColumnInfo makeColumn(final String colName, final Column column) { START TypeProtos.MajorType majorType = Types.optional(column.getMinorType()); END MaterializedField field = MaterializedField.create(colName, majorType); ValueVector vector = getValueVector(column.getMinorType(), majorType, field, output); return new ProjectedColumnInfo(vector, column, colName); } Can pcapng files omit fields? Or, if the user asks for `dst_ip`, say, will that field exist in every row? If the value exists in every row, you'll get slightly better performance using a `required` type for that column. Doing so omits the nullable bit for each column. Note that, for the `DummyImpl`, you do need the type to be `optional`. This might mean that the `MajorType` should be defined in the `Column` class so you can have some be required, others optional.

Target:
private ProjectedColumnInfo makeColumn(final String colName, final Column column) { MaterializedField field = MaterializedField.create(colName, column.getMinorType()); ValueVector vector = getValueVector(field, output); return new ProjectedColumnInfo(vector, column, colName); }
Source:
public int getPayloadByteCount(int valueCount) { if (valueCount == 0) { return 0; } int count = 0; int entryCount = offsets.getAccessor().get(valueCount); START count += offsets.getPayloadByteCount(valueCount); END for (final ValueVector v : getChildren()) { count += v.getPayloadByteCount(entryCount); } return count; } ``` int count = offsets.get... ```

Target:
public int getPayloadByteCount(int valueCount) { if (valueCount == 0) { return 0; } int entryCount = offsets.getAccessor().get(valueCount); int count = offsets.getPayloadByteCount(valueCount); for (final ValueVector v : getChildren()) { count += v.getPayloadByteCount(entryCount); } return count; }
Source:
public FragmentContext getContext() { // Backward compatibility with the full server context. Awkward for testing FragmentContext fragmentContext = fragmentContext(); START if (fragmentContext instanceof FragmentContext) { END return (FragmentContext) fragmentContext; } else { return null; } } not clear what we are doing here. why can't we just return fragmentContext ?

Target:
public FragmentContext getContext() { return fragmentContext(); }
Source:
public ColumnDefn(String name, int index) { START this.name = name; END this.index = index; this.format = ""; } ``` this(name, index, ""); ``` Should a missing format be null or empty?

Target:
public ColumnDefn(String name, int index) { this(name, index, null); }
Source:
public abstract void define(OutputMutator outputMutator) throws SchemaChangeException; public abstract void load(int rowIndex, String value); @Override //For testing public String toString() { START return "Name: " + name + ", Index: " + index; END } Format?

Target:
public abstract void define(OutputMutator outputMutator) throws SchemaChangeException; public abstract void load(int rowIndex, String value); public String getName() { return this.name; }
Source:
START public <T, X, E extends Throwable> T accept(PhysicalVisitor<T, X, E> physicalVisitor, X value) throws E { END return physicalVisitor.visitExchange(this, value); } Is this change still required?

Target:
public final <T, X, E extends Throwable> T accept(PhysicalVisitor<T, X, E> physicalVisitor, X value) throws E { return physicalVisitor.visitExchange(this, value); }
Source:
private static boolean isMuxEnabled(OptionManager options) { START if (options.getOption(PlannerSettings.MUX_EXCHANGE.getOptionName()).bool_val || END options.getOption(PlannerSettings.DEMUX_EXCHANGE.getOptionName()).bool_val || options.getOption(PlannerSettings.ORDERED_MUX_EXCHANGE.getOptionName()).bool_val) { return true; } return false; } use `return` instead of `if`

Target:
private static boolean isMuxEnabled(OptionManager options) { return (options.getOption(PlannerSettings.MUX_EXCHANGE.getOptionName()).bool_val || options.getOption(PlannerSettings.DEMUX_EXCHANGE.getOptionName()).bool_val || options.getOption(PlannerSettings.ORDERED_MUX_EXCHANGE.getOptionName()).bool_val); }
Source:
public void close() throws Exception { logger.debug("Partition sender stopping."); super.close(); ok = false; START synchronized (this) { END if (partitioner != null) { updateAggregateStats(); partitioner.clear(); } } if (closeIncoming) { ((CloseableRecordBatch) incoming).close(); } } 1. Should partitioner be volatile? Will this be enough without synchronization? 2. Should we check if partitioner is not null before synchronization as well (DCL)?

Target:
public void close() throws Exception { logger.debug("Partition sender stopping."); super.close(); if (partitioner != null) { updateAggregateStats(); partitioner.clear(); } if (closeIncoming) { ((CloseableRecordBatch) incoming).close(); } }
Source:
public MockPartitionSenderRootExec(FragmentContext context, RecordBatch incoming, HashPartitionSender operator) throws OutOfMemoryException { START super(context, incoming, operator, false); END } Is the change still necessary?

Target:
public MockPartitionSenderRootExec(FragmentContext context, RecordBatch incoming, HashPartitionSender operator) throws OutOfMemoryException { super(context, incoming, operator); }
Source:
public void admit() { // No queueing by default START foreman.moveToState(UserBitShared.QueryResult.QueryState.STARTING, null); END } Would REALLY prefer that the resource manager not depend on the Foreman; makes unit testing impossible. The Foreman should depend on this class, but not the other way around.

Target:
public void admit() { // No queueing by default }
Source:
public UserIdentity login(final String username, final Object credentials) { UserIdentity identity = null; try { identity = loggedInUgi.doAs(new PrivilegedExceptionAction<UserIdentity>() { @Override public UserIdentity run() { return spnegoLogin(username, credentials); } }); } catch (Exception e) { START logger.error("Failed to login using SPNEGO"); END } return identity; } Please log exception as well to have full stack trace.

Target:
public UserIdentity login(final String username, final Object credentials) { UserIdentity identity = null; try { identity = loggedInUgi.doAs(new PrivilegedExceptionAction<UserIdentity>() { @Override public UserIdentity run() { return spnegoLogin(credentials); } }); } catch (Exception e) { logger.error("Failed to login using SPNEGO", e); } return identity; }
Source:
public FileSystemSchemaFactory(FileSystemPlugin plugin, String schemaName, List<WorkspaceSchemaFactory> factories) { START super(); END this.plugin = plugin; this.schemaName = schemaName; this.factories = factories; } Omit; Java does this by default.

Target:
public FileSystemSchemaFactory(FileSystemPlugin plugin, String schemaName, List<WorkspaceSchemaFactory> factories) { this.plugin = plugin; this.schemaName = schemaName; this.factories = factories; }
Source:
public void testQueryGoodStorageWithDefaultSchema() throws Exception { String use_dfs = "use dfs.tmp"; client.queryBuilder().sql(use_dfs).run(); String sql = "SELECT id_i, name_s10 FROM `mock_good`.`employees_5`"; START client.queryBuilder().sql(sql).printCsv(); END } Do we actually want to print csv here? I suggest we produce no output here.

Target:
public void testQueryGoodStorageWithDefaultSchema() throws Exception { String use_dfs = "use dfs.tmp"; client.queryBuilder().sql(use_dfs).run(); String sql = "SELECT id_i, name_s10 FROM `mock_good`.`employees_5`"; client.queryBuilder().sql(sql).run(); }
Source:
public boolean supportsRead() { START return Boolean.TRUE; END } `true` is plenty good here.

Target:
public boolean supportsRead() { return true; }
Source:
public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } KafkaStoragePluginConfig other = (KafkaStoragePluginConfig) obj; if (kafkaConsumerProps == null) { if (other.kafkaConsumerProps != null) { return false; } } else if (!kafkaConsumerProps.equals(other.kafkaConsumerProps)) { START return false; END } return true; } Just a minor point, but: ``` if (kafkaConsumerProps == null && other.kafkaConsumerProps == null) { return true; } if (kafkaConsumerProps == null || other.kafkaConsumerProps == null) { return false; } return kafkaConsumerProps.equals(other.kafkaConsumerProps); ```

Target:
public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } KafkaStoragePluginConfig other = (KafkaStoragePluginConfig) obj; if (kafkaConsumerProps == null && other.kafkaConsumerProps == null) { return true; } if (kafkaConsumerProps == null || other.kafkaConsumerProps == null) { return false; } return kafkaConsumerProps.equals(other.kafkaConsumerProps); }
Source:
public void testInvalidSetQueryTimeout() throws SQLException { PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL); //Setting negative value int valueToSet = -10; if (0L == valueToSet) { valueToSet--; } try { stmt.setQueryTimeout(valueToSet); } catch ( final Exception e) { // TODO: handle exception assertThat( e.getMessage(), containsString( "illegal timeout value") ); //Converting this to match expected Exception START throw new InvalidParameterSqlException(e.getMessage()); END } } there's no point I guess? you already verified the exception...

Target:
public void testInvalidSetQueryTimeout() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL)) { //Setting negative value int valueToSet = -10; try { stmt.setQueryTimeout(valueToSet); } catch ( final SQLException e) { assertThat( e.getMessage(), containsString( "illegal timeout value") ); } } }
Source:
public void testDefaultGetQueryTimeout() throws SQLException { Statement stmt = connection.createStatement(); int timeoutValue = stmt.getQueryTimeout(); START assert( 0 == timeoutValue ); END } I personally prefer the old construct using hamcrest. This `assert` is actually less useful for two reasons: - there's no error message (hamcrest prints a nice error message based on the arguments) - if the assert fails, you don't know `timeoutValue`'s value

Target:
public void testDefaultGetQueryTimeout() throws SQLException { try(Statement stmt = connection.createStatement()) { int timeoutValue = stmt.getQueryTimeout(); assertEquals( 0 , timeoutValue ); } }
Source:
public void close() throws Exception { in.close(); START fs.close(); END } Since you did not open fs, I guess it's not your responsibility to close it.

Target:
public void close() throws Exception { in.close(); }
Source:
public void close() { if (closed) { logger.debug("Attempted to close Operator context for {}, but context is already closed", popConfig != null ? getName() : null); return; } logger.debug("Closing context for {}", popConfig != null ? getName() : null); START closed = true; END super.close(); } `closed = true` should happen after the call to `super.close()` since base class close can throw exception.

Target:
public void close() { if (closed) { logger.debug("Attempted to close Operator context for {}, but context is already closed", popConfig != null ? getName() : null); return; } logger.debug("Closing context for {}", popConfig != null ? getName() : null); try { super.close(); } finally { closed = true; } }
Source:
private int getEstimatedRecordSize(MockColumn[] types) { int x = 0; START for (int i = 0; i < (types == null ? 0 : types.length); i++) { END x += TypeHelper.getSize(types[i].getMajorType()); } return x; } Nit: maybe use: ``` if (types == null) { return 0; } // Original code here.. ```

Target:
private int getEstimatedRecordSize(MockColumn[] types) { if (types == null) { return 0; } int x = 0; for (int i = 0; i < types.length; i++) { x += TypeHelper.getSize(types[i].getMajorType()); } return x; }
Source:
public SSLConfig build() throws DrillException { if (config == null) { throw new DrillConfigurationException( "Cannot create SSL configuration from null Drill configuration."); } SSLConfig sslConfig; if (mode == SSLFactory.Mode.SERVER) { sslConfig = new SSLConfigServer(config, hadoopConfig); } else { sslConfig = new SSLConfigClient(config, hadoopConfig); } if(initializeSSLContext){ sslConfig.initContext(); } if(validateKeyStore){ sslConfig.validateKeyStore(); START } END return sslConfig; } _validateKeyStore_ should happen before _initContext_.

Target:
public SSLConfig build() throws DrillException { if (mode == SSLFactory.Mode.SERVER && config == null) { throw new DrillConfigurationException( "Cannot create SSL configuration from null Drill configuration."); } SSLConfig sslConfig; if (mode == SSLFactory.Mode.SERVER) { sslConfig = new SSLConfigServer(config, hadoopConfig); } else { sslConfig = new SSLConfigClient(properties); } if(validateKeyStore){ sslConfig.validateKeyStore(); } if(initializeSSLContext){ sslConfig.initContext(); } return sslConfig; }
Source:
private String getHadoopConfigParam(String name) { Preconditions.checkArgument(this.hadoopConfig != null); START String value = ""; END value = hadoopConfig.get(name, ""); value = value.trim(); return value; } Can be removed and initialized on the next line.

Target:
private String getHadoopConfigParam(String name) { Preconditions.checkArgument(this.hadoopConfig != null); String value = hadoopConfig.get(name, ""); value = value.trim(); return value; }
Source:
public void visitAbstractPlan(PhysicalPlan plan) { boolean replanMemory = ! plan.getProperties().hasResourcePlan; START if (! replanMemory || plan == null) { END return; } MemoryAllocationUtilities.setupBufferedOpsMemoryAllocations(plan, queryContext); } You are reading plan and then checking for null later. change it like this. if (!plan || !plan.getProperties().hasResourcePlan) { return; }

Target:
public void visitAbstractPlan(PhysicalPlan plan) { if (plan == null || plan.getProperties().hasResourcePlan) { return; } MemoryAllocationUtilities.setupBufferedOpsMemoryAllocations(plan, queryContext); }
Source:
public String toString( ) { String msg = "Embedded queue lease for " + QueryIdHelper.getQueryId(queryId); if (released) { START msg += " (released)"; END } return msg; } `StringBuilder`?

Target:
public String toString( ) { return new StringBuilder() .append("Embedded queue lease for ") .append(QueryIdHelper.getQueryId(queryId)) .append(released ? " (released)" : "") .toString(); }
Source:
public void waitForGracePeriod() { ExtendedLatch exitLatch = null; START exitLatch = new ExtendedLatch(); END exitLatch.awaitUninterruptibly(gracePeriod); } ``` ExtendedLatch exitLatch = new ExtendedLatch(); ```

Target:
public void waitForGracePeriod() { ExtendedLatch exitLatch = new ExtendedLatch(); exitLatch.awaitUninterruptibly(gracePeriod); }
Source:
public void closeDrillbit(final String drillbitName) throws Exception { Exception ex = null; for (Drillbit bit : drillbits()) { START if(bit.equals(bits.get(drillbitName))) { END bit.close(); } } if(ex != null) { throw ex; } } Space after `if`, here and below.

Target:
public void closeDrillbit(final String drillbitName) throws Exception { Exception ex = null; for (Drillbit bit : drillbits()) { if (bit.equals(bits.get(drillbitName))) { try { bit.close(); } catch (Exception e) { ex = ex == null ? e :ex; } } } if (ex != null) { throw ex; } }
Source:
public void testTimeHoursMinutesSecondsFormat() { START Locale.setDefault(Locale.US); END int hours = 11; int minutes = 50; String seconds = "05"; DateTime date = parseDateFromPostgres(hours + ":" + minutes + ":" + seconds + " am", "hh12:mi:ss am"); Assert.assertTrue(date.getHourOfDay() == hours && date.getMinuteOfHour() == minutes && date.getSecondOfMinute() == Integer.parseInt(seconds)); } Not sure that this change is necessary.

Target:
public void testTimeHoursMinutesSecondsFormat() { int hours = 11; int minutes = 50; String seconds = "05"; DateTime date = parseDateFromPostgres(hours + ":" + minutes + ":" + seconds + " am", "hh12:mi:ss am"); Assert.assertTrue(date.getHourOfDay() == hours && date.getMinuteOfHour() == minutes && date.getSecondOfMinute() == Integer.parseInt(seconds)); }
Source:
public static boolean isScalarSubquery(RelNode root) { RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance(); RelNode currentRel = root; while (currentRel != null) { if (currentRel instanceof RelSubset) { currentRel = ((RelSubset) currentRel).getBest(); continue; } Double rowCount = relMetadataQuery.getMaxRowCount(currentRel); START if (rowCount != null && rowCount.equals(1.0)) { END return true; } else { return false; } } return false; } For scalar, the value could be <= 1.0 (0 also qualifies).

Target:
public static boolean isScalarSubquery(RelNode root) { RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance(); RelNode currentRel = root; while (currentRel != null) { if (currentRel instanceof RelSubset) { currentRel = ((RelSubset) currentRel).getBest(); continue; } Double rowCount = relMetadataQuery.getMaxRowCount(currentRel); if (rowCount != null && rowCount <= 1.0) { return true; } else { return false; } } return false; }
Source:
protected static void copyMetaDataCacheToTempWithReplacements(String srcFileOnClassPath, String destFolderInTmp, String metaFileName, String customStringReplacement) throws IOException { String metadataFileContents = getFile(srcFileOnClassPath); Path rootMeta = new Path(dfsTestTmpSchemaLocation, destFolderInTmp); Path newMetaCache = new Path(rootMeta, metaFileName); FSDataOutputStream outSteam = fs.create(newMetaCache); START if (customStringReplacement!=null) { END metadataFileContents = metadataFileContents.replace("CUSTOM_STRING_REPLACEMENT", customStringReplacement); } outSteam.writeBytes(metadataFileContents.replace("REPLACED_IN_TEST", dfsTestTmpSchemaLocation)); outSteam.close(); } `if (customStringReplacement!=null) {` -> `if (customStringReplacement != null) {`

Target:
protected static void copyMetaDataCacheToTempWithReplacements(String srcFileOnClassPath, String destFolderInTmp, String metaFileName, String customStringReplacement) throws IOException { String metadataFileContents = getFile(srcFileOnClassPath); Path rootMeta = new Path(dfsTestTmpSchemaLocation, destFolderInTmp); Path newMetaCache = new Path(rootMeta, metaFileName); try (FSDataOutputStream outSteam = fs.create(newMetaCache)) { if (customStringReplacement != null) { metadataFileContents = metadataFileContents.replace("CUSTOM_STRING_REPLACEMENT", customStringReplacement); } outSteam.writeBytes(metadataFileContents.replace("REPLACED_IN_TEST", dfsTestTmpSchemaLocation)); } }
Source:
public SystemOptionManager(LogicalPlanPersistence lpPersistence, final PersistentStoreProvider provider) { this.provider = provider; START this.config = PersistentStoreConfig.newJacksonBuilder(lpPersistence.getMapper(), OptionValue.class) END .name("sys.options") .build(); } A really handy trick to avoid code duplication is this: ``` public SystemOptionManager(LogicalPlanPersistence lpPersistence, final PersistentStoreProvider provider) { this(lpPersistence, provider, null); } ``` Then, the bulk of the constructor code appears only once: in the three-arg version.

Target:
public SystemOptionManager(LogicalPlanPersistence lpPersistence, final PersistentStoreProvider provider) { this(lpPersistence,provider,null); }
Source:
public void populateDefaultValues() { // populate the options from the config final Map<String, OptionValidator> tmp = new HashMap<>(); for (OptionValidator validator: VALIDATORS.values()) { try { validator.loadDefault(bootConfig); } catch (ConfigException.Missing e) { START throw new IllegalStateException("Config Option is missing"+e+ validator.getOptionName()); END } } } `...missing " + validator.getOptionName()` The exception adds no real value here. Or: `new IllegalStateException(..., e);`

Target:
public void populateDefaultValues() { // populate the options from the config final Map<String, OptionValidator> tmp = new HashMap<>(); for (OptionValidator validator: VALIDATORS.values()) { try { validator.loadDefault(bootConfig); } catch (ConfigException.Missing e) { throw new IllegalStateException("Config Option is missing"+ validator.getOptionName()); } } }
Source:
public int computeMaxWidth(double cpuLoadAverage, long maxWidth) { // if maxwidth is already set return it if (maxWidth != 0) { return (int) maxWidth; } // else compute the value and return else { int maxWidthPerNode; int availProc = Runtime.getRuntime().availableProcessors(); START maxWidthPerNode = (int) Math.max(1, Math.min(availProc, Math.round(availProc * cpuLoadAverage))); END return maxWidthPerNode; } } `int maxWidthPerNode = ...` or even just `return (int) ...`

Target:
public int computeMaxWidth(double cpuLoadAverage, long maxWidth) { // if maxwidth is already set return it if (maxWidth != 0) { return (int) maxWidth; } // else compute the value and return else { int availProc = Runtime.getRuntime().availableProcessors(); long maxWidthPerNode = Math.max(1, Math.min(availProc, Math.round(availProc * cpuLoadAverage))); return (int) maxWidthPerNode; } }
Source:
public void testJDKClassCompiler() throws Exception { logger.debug("Testing JDKClassCompiler"); START sessionOptions.setOption(OptionValue.createString(OptionType.SESSION, ClassCompilerSelector.JAVA_COMPILER_OPTION, ClassCompilerSelector.CompilerPolicy.JDK.name(), OptionScope.SESSION)); END for (int i = 0; i < ITERATION_COUNT; i++) { compilationInnerClass(false); // Traditional byte-code manipulation compilationInnerClass(true); // Plain-old Java } } Hmmm... We should not need every caller that sets a session option to say that it is setting a session option. Instead, the implementation of `setOption` for the session option manager class should fill in the `OptionScope.SESSION` value.

Target:
public void testJDKClassCompiler() throws Exception { logger.debug("Testing JDKClassCompiler"); OptionType type = OptionType.SESSION; sessionOptions.setOption(OptionValue.createString(type, ClassCompilerSelector.JAVA_COMPILER_OPTION, ClassCompilerSelector.CompilerPolicy.JDK.name(), OptionScope.SESSION)); for (int i = 0; i < ITERATION_COUNT; i++) { compilationInnerClass(false); // Traditional byte-code manipulation compilationInnerClass(true); // Plain-old Java } }
Source:
public SchemaBuilder(BatchSchema baseSchema) { for (MaterializedField field : baseSchema) { START columns.add(field); END } } just call `add` method of `SchemaBuilder` instead of `columns.add(field)`

Target:
public SchemaBuilder(BatchSchema baseSchema) { for (MaterializedField field : baseSchema) { add(field); } }
Source:
private void flush() throws IOException { if (recordCount > 0) { parquetFileWriter.startBlock(recordCount); consumer.flush(); store.flush(); pageStore.flushToFileWriter(parquetFileWriter); recordCount = 0; parquetFileWriter.endBlock(); // we are writing one single block per file parquetFileWriter.end(extraMetaData); parquetFileWriter = null; } store.close(); START pageStore.close(); END store = null; pageStore = null; index++; } This is existing code; but seems that the above code should be in a try block, with close in the finally, to ensure that the close occurs even if a write or other error occurs.

Target:
private void flush() throws IOException { try { if (recordCount > 0) { parquetFileWriter.startBlock(recordCount); consumer.flush(); store.flush(); pageStore.flushToFileWriter(parquetFileWriter); recordCount = 0; parquetFileWriter.endBlock(); // we are writing one single block per file parquetFileWriter.end(extraMetaData); parquetFileWriter = null; } } finally { store.close(); pageStore.close(); store = null; pageStore = null; index++; } }
Source:
protected boolean hasCapacity(int index, int fieldLength) { START if (fieldLength < 0) { END throw new IllegalArgumentException("length: " + fieldLength + " (expected: >= 0)"); } return (! (index < 0 || index > capacity() - fieldLength)); } change this to an assertion as per our discussion?

Target:
protected boolean hasCapacity(int index, int fieldLength) { assert fieldLength >= 0; return (! (index < 0 || index > capacity() - fieldLength)); }
Source:
public boolean setBytesBounded(int index, byte[] src, int srcIndex, int length) { if (! hasCapacity(index, length)) { return false; } START if (length != 0) { END PlatformDependent.copyMemory(src, srcIndex, addr(index), length); } return true; } Remove length check

Target:
public boolean setBytesBounded(int index, byte[] src, int srcIndex, int length) { if (! hasCapacity(index, length)) { return false; } PlatformDependent.copyMemory(src, srcIndex, addr(index), length); return true; }
Source:
public PcapRecordReader(final String inputPath, final List<SchemaPath> projectedColumns) { try { START this.in = new FileInputStream(inputPath); END this.decoder = getPacketDecoder(); validBytes = in.read(buffer); } catch (IOException e) { throw new RuntimeException("File " + inputPath + " not Found"); } setColumns(projectedColumns); } As noted above, by opening the file here, if you are scanning 1000 files, you'll have 1000 open file handles at the start of the fragment. Better to postpone opening files until setup.

Target:
public PcapRecordReader(final String inputPath, final List<SchemaPath> projectedColumns) { this.inputPath = inputPath; this.projectedColumns = projectedColumns; }
Source:
private ValueVector getValueVector(final MinorType minorType, final MajorType majorType, final MaterializedField field) { try { final Class<? extends ValueVector> clazz = TypeHelper.getValueVectorClass( minorType, majorType.getMode()); ValueVector vector = output.addField(field, clazz); vector.allocateNew(); return vector; } catch (SchemaChangeException sce) { START throw new NullPointerException("The addition of this field is incompatible with this OutputMutator's capabilities"); END } } `NullPointerException` --> `IllegalStateException` This is not really a null pointer, but it is an illegal state...

Target:
private ValueVector getValueVector(final MinorType minorType, final MajorType majorType, final MaterializedField field) { try { final Class<? extends ValueVector> clazz = TypeHelper.getValueVectorClass( minorType, majorType.getMode()); ValueVector vector = output.addField(field, clazz); vector.allocateNew(); return vector; } catch (SchemaChangeException sce) { throw new IllegalStateException("The addition of this field is incompatible with this OutputMutator's capabilities"); } }
Source:
public QueryType getType() { START QueryType type = QueryType.SQL; END switch (queryType) { case "SQL": type = QueryType.SQL; break; case "LOGICAL": type = QueryType.LOGICAL; break; case "PHYSICAL": type = QueryType.PHYSICAL; break; } return type; } `return QueryType.valueOf(queryType);`

Target:
public QueryType getType() { return QueryType.valueOf(queryType); }
Source:
START public int extraMemoryNeededForResize() { END if (tableSize == MAXIMUM_CAPACITY) { return 0; } // will not resize int newSize = roundUpToPowerOf2(2 * tableSize); if (newSize > MAXIMUM_CAPACITY) { newSize = MAXIMUM_CAPACITY; } return newSize * 4 /* sizeof(int) */; } Should this return a long ?

Target:
public long extraMemoryNeededForResize() { if (tableSize == MAXIMUM_CAPACITY) { return 0; } // will not resize int newSize = roundUpToPowerOf2(2 * tableSize); if (newSize > MAXIMUM_CAPACITY) { newSize = MAXIMUM_CAPACITY; } return newSize * 4 /* sizeof(int) */; }
Source:
private void reinitPartition(int part) throws SchemaChangeException, ClassTransformationException, IOException { assert htables[part] != null; htables[part].reset(); if ( batchHolders[part] != null) { for (BatchHolder bh : batchHolders[part]) { bh.clear(); } batchHolders[part].clear(); } batchHolders[part] = new ArrayList<BatchHolder>(); // First BatchHolder is created when the first put request is received. START } END Suppose numPendingOutput is small (e.g 100 rows) but there are several such batches, we would end up calling allocateOutgoing() multiple times for small amounts...shouldn't we try to combine these into smaller number of outgoing batches ?

Target:
private void reinitPartition(int part) /* throws SchemaChangeException /*, IOException */ { assert htables[part] != null; htables[part].reset(); if ( batchHolders[part] != null) { for (BatchHolder bh : batchHolders[part]) { bh.clear(); } batchHolders[part].clear(); } batchHolders[part] = new ArrayList<BatchHolder>(); // First BatchHolder is created when the first put request is received. }
Source:
private void runPreparedStatement(final PreparedStatementHandle preparedStatementHandle) throws ExecutionSetupException { final ServerPreparedStatementState serverState; try { serverState = ServerPreparedStatementState.PARSER.parseFrom(preparedStatementHandle.getServerInfo()); } catch (final InvalidProtocolBufferException ex) { throw UserException.parseError(ex) .message("Failed to parse the prepared statement handle. " + "Make sure the handle is same as one returned from create prepared statement call.") .build(logger); } final String sql = serverState.getSqlQuery(); logger.info("Prepared statement query for QueryId : {}", queryId, sql); runSQL(sql); // keep a query text of the preparedStatement for the queryManager START queryText = sql; END } Temporary variable can be removed.

Target:
private void runPreparedStatement(final PreparedStatementHandle preparedStatementHandle) throws ExecutionSetupException { final ServerPreparedStatementState serverState; try { serverState = ServerPreparedStatementState.PARSER.parseFrom(preparedStatementHandle.getServerInfo()); } catch (final InvalidProtocolBufferException ex) { throw UserException.parseError(ex) .message("Failed to parse the prepared statement handle. " + "Make sure the handle is same as one returned from create prepared statement call.") .build(logger); } queryText = serverState.getSqlQuery(); logger.info("Prepared statement query for QueryId : {}", queryId, queryText); runSQL(queryText); }
Source:
public static int getChildCount(PhysicalOperator popConfig) { Iterator<PhysicalOperator> iter = popConfig.iterator(); START int i = 0; END while (iter.hasNext()) { iter.next(); i++; } if (i == 0) { i = 1; } return i; } Refactor i -> count

Target:
public static int getChildCount(PhysicalOperator popConfig) { Iterator<PhysicalOperator> iter = popConfig.iterator(); int count = 0; while (iter.hasNext()) { iter.next(); count++; } if (count == 0) { count = 1; } return count; }
Source:
public void close() { metrics.updateWriteBytes(spilledRuns.getWriteBytes()); RuntimeException ex = null; try { spilledRuns.close(); } catch (RuntimeException e) { ex = e; } try { bufferedBatches.close(); } catch (RuntimeException e) { START ex = e; END } if (ex != null) { throw ex; } } Being nit-picky: This may erase the previous spilledRuns runtime exception ....

Target:
public void close() { metrics.updateWriteBytes(spilledRuns.getWriteBytes()); RuntimeException ex = null; try { spilledRuns.close(); } catch (RuntimeException e) { ex = e; } try { bufferedBatches.close(); } catch (RuntimeException e) { ex = ex == null ? e : ex; } if (ex != null) { throw ex; } }
Source:
public T get(String key) { START Integer index = getIndex(key); END if (index == -1) { return null; } return get(index); } `int` rather than `Integer`

Target:
public T get(String key) { int index = getIndex(key); if (index == -1) { return null; } return get(index); }
Source:
START String getConnection() { END return connection; } I have noticed that there is an error during plugin configuration serialization, this happens because method accessor is not public.

Target:
public String getConnection() { return connection; }
Source:
public OpenTSDBStoragePlugin(OpenTSDBStoragePluginConfig configuration, DrillbitContext context, String name) throws IOException { this.context = context; this.schemaFactory = new OpenTSDBSchemaFactory(this, name); this.engineConfig = configuration; START this.db = new ServiceImpl("http://" + configuration.getConnection()); END } Can it be `https`? May be user should be responsible of setting this in config?

Target:
public OpenTSDBStoragePlugin(OpenTSDBStoragePluginConfig configuration, DrillbitContext context, String name) throws IOException { this.context = context; this.schemaFactory = new OpenTSDBSchemaFactory(this, name); this.engineConfig = configuration; this.db = new ServiceImpl(configuration.getConnection()); }
Source:
private void recordNewState(final QueryState newState) { state = newState; if (queryContext.getOptions().getOption(ExecConstants.ZK_QUERY_STATE_UPDATE)) { queryManager.updateEphemeralState(newState); START } END } How does this affect query operation for long-running queries? How does it impact the query profile? If updates are enabled, do we still do an update at query completion to finalize the profile? If not, should writing of the profile be automatically disabled if status updates are disabled? Do we do any timeout on updates? Will we notice that the query has not been updated and, say, kill the query due to timeouts?

Target:
private void recordNewState(final QueryState newState) { state = newState; queryManager.updateEphemeralState(newState); }
Source:
ClusterFixture(FixtureBuilder builder) { String zkConnect = configureZk(builder); try { START createConfig(builder, zkConnect); END startDrillbits(builder); applyOptions(builder); } catch (Exception e) { // Translate exceptions to unchecked to avoid cluttering // tests. Failures will simply fail the test itself. throw new IllegalStateException( "Cluster fixture setup failed", e ); } // Some operations need an allocator. allocator = RootAllocatorFactory.newRoot(config); } In createConfig we are calling `getServiceSetWithFullCache(config, allocator)`. But we are creating `allocator` later on. We should assign allocator before calling above method. But allocator creation also takes in config so probably we have to do inside `createConfig` method. On a side note I don't see `getServiceSetWithFullCache(config, allocator)` using allocator or config anyway. Not sure why we are passing in first place.

Target:
ClusterFixture(FixtureBuilder builder) { configureZk(builder); try { createConfig(builder); allocator = RootAllocatorFactory.newRoot(config); startDrillbits(builder); applyOptions(builder); } catch (Exception e) { // Translate exceptions to unchecked to avoid cluttering // tests. Failures will simply fail the test itself. throw new IllegalStateException( "Cluster fixture setup failed", e ); } }
Source:
private long determineSizesSerial(long recordsToReadInThisPass) throws IOException { int recordsReadInCurrentPass = 0; top: do { for (VarLengthColumn<?> columnReader : columns) { // Return status is "done reading", meaning stop if true. START if (columnReader.determineSize(recordsReadInCurrentPass, 0 /* unused */ )) { END break top; } } for (VarLengthColumn<?> columnReader : columns) { columnReader.updateReadyToReadPosition(); columnReader.currDefLevel = -1; } recordsReadInCurrentPass++; } while (recordsReadInCurrentPass < recordsToReadInThisPass); return recordsReadInCurrentPass; } why not remove the unused parameter ?

Target:
private long determineSizesSerial(long recordsToReadInThisPass) throws IOException { int recordsReadInCurrentPass = 0; top: do { for (VarLengthColumn<?> columnReader : columns) { // Return status is "done reading", meaning stop if true. if (columnReader.determineSize(recordsReadInCurrentPass)) { break top; } } for (VarLengthColumn<?> columnReader : columns) { columnReader.updateReadyToReadPosition(); columnReader.currDefLevel = -1; } recordsReadInCurrentPass++; } while (recordsReadInCurrentPass < recordsToReadInThisPass); return recordsReadInCurrentPass; }
Source:
public FragmentContext getContext() { START return incoming.getContext(); END } OK, so we hold onto the incoming batch just to get the FragmentContext. If so, please pass the FragmentContext into the constructor of this class rather than passing in the (irrelevant) incoming batch.

Target:
public FragmentContext getContext() { return context; }
Source:
public ContextInformation(final UserCredentials userCredentials, final QueryContextInformation queryContextInfo) { this.queryUser = userCredentials.getUserName(); this.currentDefaultSchema = queryContextInfo.getDefaultSchemaName(); this.queryStartTime = queryContextInfo.getQueryStartTime(); this.rootFragmentTimeZone = queryContextInfo.getTimeZone(); this.sessionId = queryContextInfo.getSessionId(); START this.hllAccuracy = queryContextInfo.getHllAccuracy(); END } The query context is very general and is probably not the place to store specific options such as the hllAccuracy. The operator and/or factory can get the value directly from the option manager. Actually, any stats options should be set on the operator definition itself (`StatisticsAggregate`, etc.) so that all fragments use the same value: the one selected when creating the plan. This behavior would mimic how we set memory for sort operators, etc.

Target:
public ContextInformation(final UserCredentials userCredentials, final QueryContextInformation queryContextInfo) { this.queryUser = userCredentials.getUserName(); this.currentDefaultSchema = queryContextInfo.getDefaultSchemaName(); this.queryStartTime = queryContextInfo.getQueryStartTime(); this.rootFragmentTimeZone = queryContextInfo.getTimeZone(); this.sessionId = queryContextInfo.getSessionId(); }
Source:
START public MSorter createNewMSorter(VectorAccessible batch) { END if (mSorter == null) { mSorter = createNewMSorter(popConfig.getOrderings(), batch, MAIN_MAPPING, LEFT_MAPPING, RIGHT_MAPPING); } return mSorter; } Maybe change the method name to getMSorter() ? As internally it does not always create a new MSorter.

Target:
public MSorter createNewMSorter(VectorAccessible batch) { return createNewMSorter(popConfig.getOrderings(), batch, MAIN_MAPPING, LEFT_MAPPING, RIGHT_MAPPING); }
Source:
public ColumnDef( MockColumn mockCol, int rep ) { this( mockCol ); START name = name += Integer.toString(rep); END } Below should also work. no need to reassign. `name += Integer.toString(rep);`

Target:
public ColumnDef(MockColumn mockCol, int rep) { this(mockCol); name += Integer.toString(rep); }