Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DataSink.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.planner;
16 
17 import java.util.List;
18 
23 import com.cloudera.impala.thrift.TDataSink;
24 import com.cloudera.impala.thrift.TExplainLevel;
25 import com.google.common.base.Preconditions;
26 
34 public abstract class DataSink {
35 
36  // estimated per-host memory requirement for sink;
37  // set in computeCosts(); invalid: -1
38  protected long perHostMemCost_ = -1;
39 
40  // Fragment that this DataSink belongs to. Set by the PlanFragment enclosing this sink.
42 
47  public abstract String getExplainString(String prefix, String detailPrefix,
48  TExplainLevel explainLevel);
49 
50  protected abstract TDataSink toThrift();
51 
52  public void setFragment(PlanFragment fragment) { fragment_ = fragment; }
53  public PlanFragment getFragment() { return fragment_; }
54  public long getPerHostMemCost() { return perHostMemCost_; }
55 
59  public static DataSink createDataSink(Table table, List<Expr> partitionKeyExprs,
60  boolean overwrite) {
61  if (table instanceof HdfsTable) {
62  return new HdfsTableSink(table, partitionKeyExprs, overwrite);
63  } else if (table instanceof HBaseTable) {
64  // Partition clause doesn't make sense for an HBase table.
65  Preconditions.checkState(partitionKeyExprs.isEmpty());
66  // HBase doesn't have a way to perform INSERT OVERWRITE
67  Preconditions.checkState(overwrite == false);
68  // Create the HBaseTableSink and return it.
69  return new HBaseTableSink(table);
70  } else {
71  throw new UnsupportedOperationException(
72  "Cannot create data sink into table of type: " + table.getClass().getName());
73  }
74  }
75 
79  public void computeCosts() {
80  perHostMemCost_ = 0;
81  }
82 }
abstract String getExplainString(String prefix, String detailPrefix, TExplainLevel explainLevel)
void setFragment(PlanFragment fragment)
Definition: DataSink.java:52
static DataSink createDataSink(Table table, List< Expr > partitionKeyExprs, boolean overwrite)
Definition: DataSink.java:59