/**
* Copyright (C) 2009-2013 FoundationDB, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.foundationdb.qp.operator;
import com.foundationdb.qp.row.Row;
import com.foundationdb.qp.rowtype.RowType;
import com.foundationdb.server.explain.CompoundExplainer;
import com.foundationdb.server.explain.ExplainContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class TimeOperator extends Operator
{
// Object interface
@Override
public String toString()
{
return getClass().getSimpleName();
}
// Operator interface
@Override
protected Cursor cursor(QueryContext context, QueryBindingsCursor bindingsCursor)
{
return new Execution(context, bindingsCursor);
}
@Override
public void findDerivedTypes(Set<RowType> derivedTypes)
{
inputOperator.findDerivedTypes(derivedTypes);
}
@Override
public List<Operator> getInputOperators()
{
List<Operator> result = new ArrayList<>(1);
result.add(inputOperator);
return result;
}
@Override
public String describePlan()
{
return describePlan(inputOperator);
}
// TimeOperator interface
public long elapsedNsec()
{
return elapsedNsec;
}
public TimeOperator(Operator inputOperator)
{
this.inputOperator = inputOperator;
}
// Object state
private final Operator inputOperator;
private long elapsedNsec = 0;
@Override
public CompoundExplainer getExplainer(ExplainContext context) {
throw new UnsupportedOperationException("Not supported yet.");
}
// Inner classes
private class Execution extends ChainedCursor
{
// Cursor interface
@Override
public void open()
{
super.open();
long start = System.nanoTime();
input.open();
long stop = System.nanoTime();
elapsedNsec += stop - start;
}
@Override
public Row next()
{
long start = System.nanoTime();
Row next = input.next();
long stop = System.nanoTime();
elapsedNsec += stop - start;
return next;
}
@Override
public void close()
{
try {
long start = System.nanoTime();
input.close();
long stop = System.nanoTime();
elapsedNsec += stop - start;
} finally {
super.close();
}
}
// Execution interface
Execution(QueryContext context, QueryBindingsCursor bindingsCursor)
{
super(context, inputOperator.cursor(context, bindingsCursor));
}
}
}