drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gparai <...@git.apache.org>
Subject [GitHub] drill pull request #811: DRILL-5423: Refactor ScanBatch to allow unit testin...
Date Tue, 02 May 2017 21:03:06 GMT
Github user gparai commented on a diff in the pull request:

    https://github.com/apache/drill/pull/811#discussion_r114403519
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/ops/AbstractOperatorExecContext.java
---
    @@ -0,0 +1,94 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.drill.exec.ops;
    +
    +import org.apache.drill.exec.memory.BufferAllocator;
    +import org.apache.drill.exec.physical.base.PhysicalOperator;
    +import org.apache.drill.exec.testing.ExecutionControls;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +/**
    + * Implementation of {@link OperatorExecContext} that provides services
    + * needed by most run-time operators. Excludes services that need the
    + * entire Drillbit. Allows easy testing of operator code that uses this
    + * interface.
    + */
    +
    +public class AbstractOperatorExecContext implements OperatorExecContext {
    +
    +  protected final BufferAllocator allocator;
    +  protected final ExecutionControls executionControls;
    +  protected final PhysicalOperator popConfig;
    +  protected final BufferManager manager;
    +  protected OperatorStatReceiver statsWriter;
    +
    +  public AbstractOperatorExecContext(BufferAllocator allocator, PhysicalOperator popConfig,
    +                                     ExecutionControls executionControls,
    +                                     OperatorStatReceiver stats) {
    +    this.allocator = allocator;
    +    this.popConfig = popConfig;
    +    this.manager = new BufferManagerImpl(allocator);
    +    statsWriter = stats;
    +
    +    this.executionControls = executionControls;
    +  }
    +
    +  @Override
    +  public DrillBuf replace(DrillBuf old, int newSize) {
    +    return manager.replace(old, newSize);
    +  }
    +
    +  @Override
    +  public DrillBuf getManagedBuffer() {
    +    return manager.getManagedBuffer();
    +  }
    +
    +  @Override
    +  public DrillBuf getManagedBuffer(int size) {
    +    return manager.getManagedBuffer(size);
    +  }
    +
    +  @Override
    +  public ExecutionControls getExecutionControls() {
    +    return executionControls;
    +  }
    +
    +  @Override
    +  public BufferAllocator getAllocator() {
    +    if (allocator == null) {
    +      throw new UnsupportedOperationException("Operator context does not have an allocator");
    +    }
    +    return allocator;
    +  }
    +
    +  public void close() {
    +    try {
    +      manager.close();
    +    } finally {
    +      if (allocator != null) {
    +        allocator.close();
    +      }
    +    }
    +  }
    +
    +  @Override
    +  public OperatorStatReceiver getStatsWriter() {
    +    return statsWriter;
    --- End diff --
    
    This maybe called prior to initializing `statsWriter = stats` in `OperatorContextImpl`
constructor. Should we add an assert? 
    OR 
    Should we even pass `OperatorStatReceiver stats` in the `AbstractOperatorExecContext`
constructor - maybe only use a getter/setter for `statsWriter`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message