Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
450 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Limit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* 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.physical.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import org.apache.drill.common.expression.LogicalExpression; | ||
import org.apache.drill.exec.physical.OperatorCost; | ||
import org.apache.drill.exec.physical.base.AbstractSingle; | ||
import org.apache.drill.exec.physical.base.PhysicalOperator; | ||
import org.apache.drill.exec.physical.base.PhysicalVisitor; | ||
|
||
@JsonTypeName("limit") | ||
public class Limit extends AbstractSingle { | ||
private final Integer first; | ||
private final Integer last; | ||
|
||
@JsonCreator | ||
public Limit(@JsonProperty("child") PhysicalOperator child, @JsonProperty("first") Integer first, @JsonProperty("last") Integer last) { | ||
super(child); | ||
this.first = first; | ||
this.last = last; | ||
} | ||
|
||
public Integer getFirst() { | ||
return first; | ||
} | ||
|
||
public Integer getLast() { | ||
return last; | ||
} | ||
|
||
@Override | ||
protected PhysicalOperator getNewWithChild(PhysicalOperator child) { | ||
return new Limit(child, first, last); | ||
} | ||
|
||
@Override | ||
public OperatorCost getCost() { | ||
return new OperatorCost(0, 0, 0, 0.25f); | ||
} | ||
|
||
@Override | ||
public <T, X, E extends Throwable> T accept(PhysicalVisitor<T, X, E> physicalVisitor, X value) throws E { | ||
return physicalVisitor.visitLimit(this, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitBatchCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.apache.drill.exec.physical.impl.limit; | ||
|
||
import com.google.common.collect.Iterables; | ||
import org.apache.drill.common.exceptions.ExecutionSetupException; | ||
import org.apache.drill.exec.ops.FragmentContext; | ||
import org.apache.drill.exec.physical.config.Limit; | ||
import org.apache.drill.exec.physical.impl.BatchCreator; | ||
import org.apache.drill.exec.record.RecordBatch; | ||
|
||
import java.util.List; | ||
|
||
public class LimitBatchCreator implements BatchCreator<Limit> { | ||
@Override | ||
public RecordBatch getBatch(FragmentContext context, Limit config, List<RecordBatch> children) throws ExecutionSetupException { | ||
return new LimitRecordBatch(config, context, Iterables.getOnlyElement(children)); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitRecordBatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.apache.drill.exec.physical.impl.limit; | ||
|
||
import com.beust.jcommander.internal.Lists; | ||
import com.google.common.base.Objects; | ||
import org.apache.drill.exec.exception.SchemaChangeException; | ||
import org.apache.drill.exec.ops.FragmentContext; | ||
import org.apache.drill.exec.physical.config.Limit; | ||
import org.apache.drill.exec.record.*; | ||
import org.apache.drill.exec.record.selection.SelectionVector2; | ||
import org.apache.drill.exec.vector.ValueVector; | ||
|
||
import java.util.List; | ||
|
||
public class LimitRecordBatch extends AbstractSingleRecordBatch<Limit> { | ||
|
||
private SelectionVector2 outgoingSv; | ||
private SelectionVector2 incomingSv; | ||
|
||
public LimitRecordBatch(Limit popConfig, FragmentContext context, RecordBatch incoming) { | ||
super(popConfig, context, incoming); | ||
outgoingSv = new SelectionVector2(context.getAllocator()); | ||
} | ||
|
||
@Override | ||
protected void setupNewSchema() throws SchemaChangeException { | ||
container.clear(); | ||
|
||
List<TransferPair> transfers = Lists.newArrayList(); | ||
|
||
for(VectorWrapper<?> v : incoming){ | ||
TransferPair pair = v.getValueVector().getTransferPair(); | ||
container.add(pair.getTo()); | ||
transfers.add(pair); | ||
} | ||
|
||
BatchSchema.SelectionVectorMode svMode = incoming.getSchema().getSelectionVectorMode(); | ||
|
||
switch(svMode){ | ||
case NONE: | ||
break; | ||
case TWO_BYTE: | ||
this.incomingSv = incoming.getSelectionVector2(); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
container.buildSchema(BatchSchema.SelectionVectorMode.TWO_BYTE); | ||
|
||
|
||
for(TransferPair tp : transfers) { | ||
tp.transfer(); | ||
} | ||
} | ||
|
||
@Override | ||
public SelectionVector2 getSelectionVector2() { | ||
return outgoingSv; | ||
} | ||
|
||
@Override | ||
protected void doWork() { | ||
int recordCount = incoming.getRecordCount(); | ||
outgoingSv.allocateNew(recordCount); | ||
|
||
if(incomingSv != null) { | ||
limitWithSV(recordCount); | ||
} else { | ||
limitWithNoSV(recordCount); | ||
} | ||
} | ||
|
||
private void limitWithNoSV(int recordCount) { | ||
int svIndex = 0; | ||
int offset = Math.max(0, Objects.firstNonNull(popConfig.getFirst(), 0)); | ||
int fetch = Math.min(recordCount, Objects.firstNonNull(popConfig.getLast(), recordCount)); | ||
for(char i = (char) offset; i < fetch; i++) { | ||
outgoingSv.setIndex(svIndex, i); | ||
svIndex++; | ||
} | ||
outgoingSv.setRecordCount(svIndex); | ||
} | ||
|
||
private void limitWithSV(int recordCount) { | ||
int svIndex = 0; | ||
int offset = Math.max(0, Objects.firstNonNull(popConfig.getFirst(), 0)); | ||
int fetch = Math.min(recordCount, Objects.firstNonNull(popConfig.getLast(), recordCount)); | ||
for(int i = offset; i < fetch; i++) { | ||
char index = incomingSv.getIndex(i); | ||
outgoingSv.setIndex(svIndex, index); | ||
svIndex++; | ||
} | ||
|
||
outgoingSv.setRecordCount(svIndex); | ||
} | ||
|
||
@Override | ||
public int getRecordCount() { | ||
return outgoingSv.getCount(); | ||
} | ||
|
||
@Override | ||
protected void cleanup(){ | ||
super.cleanup(); | ||
outgoingSv.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.