/*
* 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.kylin.query.enumerator;
import org.apache.calcite.DataContext;
import org.apache.calcite.linq4j.AbstractEnumerable;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.kylin.query.relnode.OLAPContext;
/**
*/
public class OLAPQuery extends AbstractEnumerable<Object[]> implements Enumerable<Object[]> {
public enum EnumeratorTypeEnum {
OLAP, //finish query with Cube or II, or a combination of both
LOOKUP_TABLE, //using a snapshot of lookup table
HIVE //using hive
}
private final DataContext optiqContext;
private final EnumeratorTypeEnum type;
private final int contextId;
public OLAPQuery(DataContext optiqContext, EnumeratorTypeEnum type, int ctxId) {
this.optiqContext = optiqContext;
this.type = type;
this.contextId = ctxId;
}
public OLAPQuery(EnumeratorTypeEnum type, int ctxSeq) {
this(null, type, ctxSeq);
}
public Enumerator<Object[]> enumerator() {
OLAPContext olapContext = OLAPContext.getThreadLocalContextById(contextId);
switch (type) {
case OLAP:
return new OLAPEnumerator(olapContext, optiqContext);
case LOOKUP_TABLE:
return new LookupTableEnumerator(olapContext);
case HIVE:
return new HiveEnumerator(olapContext);
default:
throw new IllegalArgumentException("Wrong type " + type + "!");
}
}
}