15 package com.cloudera.impala.service;
17 import java.util.ArrayList;
18 import java.util.List;
21 import org.apache.thrift.TDeserializer;
22 import org.apache.thrift.TException;
23 import org.apache.thrift.TSerializer;
24 import org.apache.thrift.protocol.TBinaryProtocol;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
33 import com.cloudera.impala.thrift.TCacheJarParams;
34 import com.cloudera.impala.thrift.TCacheJarResult;
35 import com.cloudera.impala.thrift.TCatalogObject;
36 import com.cloudera.impala.thrift.TCatalogObjectType;
37 import com.cloudera.impala.thrift.TCatalogServiceRequestHeader;
38 import com.cloudera.impala.thrift.TColumnValue;
39 import com.cloudera.impala.thrift.TExprBatch;
40 import com.cloudera.impala.thrift.TPrioritizeLoadRequest;
41 import com.cloudera.impala.thrift.TPrioritizeLoadResponse;
42 import com.cloudera.impala.thrift.TQueryCtx;
43 import com.cloudera.impala.thrift.TResultRow;
44 import com.cloudera.impala.thrift.TStatus;
45 import com.cloudera.impala.thrift.TStartupOptions;
46 import com.cloudera.impala.thrift.TSymbolLookupParams;
47 import com.cloudera.impala.thrift.TSymbolLookupResult;
48 import com.cloudera.impala.thrift.TTable;
50 import com.google.common.base.Preconditions;
61 private final static Logger
LOG = LoggerFactory.getLogger(FeSupport.class);
70 byte[] thriftQueryGlobals);
95 Preconditions.checkNotNull(hdfsLocation);
96 TCacheJarParams params =
new TCacheJarParams(hdfsLocation);
97 TSerializer serializer =
new TSerializer(
new TBinaryProtocol.Factory());
100 result =
CacheJar(serializer.serialize(params));
101 Preconditions.checkNotNull(result);
102 TDeserializer deserializer =
new TDeserializer(
new TBinaryProtocol.Factory());
103 TCacheJarResult thriftResult =
new TCacheJarResult();
104 deserializer.deserialize(thriftResult, result);
106 }
catch (TException e) {
109 "Couldn't cache jar at HDFS location " + hdfsLocation, e);
113 private static byte[]
CacheJar(byte[] thriftParams) {
116 }
catch (UnsatisfiedLinkError e) {
124 Preconditions.checkState(expr.isConstant());
125 TExprBatch exprBatch =
new TExprBatch();
126 exprBatch.addToExprs(expr.treeToThrift());
127 TSerializer serializer =
new TSerializer(
new TBinaryProtocol.Factory());
131 serializer.serialize(queryCtx));
132 Preconditions.checkNotNull(result);
133 TDeserializer deserializer =
new TDeserializer(
new TBinaryProtocol.Factory());
134 TResultRow val =
new TResultRow();
135 deserializer.deserialize(val, result);
136 Preconditions.checkState(val.getColValsSize() == 1);
137 return val.getColVals().
get(0);
138 }
catch (TException e) {
147 }
catch (UnsatisfiedLinkError e) {
153 public static TSymbolLookupResult
LookupSymbol(TSymbolLookupParams params)
155 TSerializer serializer =
new TSerializer(
new TBinaryProtocol.Factory());
157 byte[] resultBytes =
LookupSymbol(serializer.serialize(params));
158 Preconditions.checkNotNull(resultBytes);
159 TDeserializer deserializer =
new TDeserializer(
new TBinaryProtocol.Factory());
160 TSymbolLookupResult result =
new TSymbolLookupResult();
161 deserializer.deserialize(result, resultBytes);
163 }
catch (TException e) {
170 byte[] thriftQueryContext) {
173 }
catch (UnsatisfiedLinkError e) {
182 if (pred instanceof
BoolLiteral)
return ((BoolLiteral) pred).getValue();
184 Preconditions.checkState(pred.getType().isBoolean());
187 return val.isBool_val() && val.bool_val;
201 TSerializer serializer =
new TSerializer(
new TBinaryProtocol.Factory());
202 TExprBatch exprBatch =
new TExprBatch();
203 for (
Expr expr: exprs) {
205 Preconditions.checkState(expr.getType().isBoolean());
206 Preconditions.checkState(expr.isConstant());
207 exprBatch.addToExprs(expr.treeToThrift());
212 serializer.serialize(queryCtx));
213 Preconditions.checkNotNull(result);
214 TDeserializer deserializer =
new TDeserializer(
new TBinaryProtocol.Factory());
215 TResultRow val =
new TResultRow();
216 deserializer.deserialize(val, result);
218 }
catch (TException e) {
227 }
catch (UnsatisfiedLinkError e) {
235 Preconditions.checkNotNull(tableNames);
237 List<TCatalogObject> objectDescs =
new ArrayList<TCatalogObject>(tableNames.size());
239 TCatalogObject catalogObject =
new TCatalogObject();
240 catalogObject.setType(TCatalogObjectType.TABLE);
241 catalogObject.setTable(
new TTable(tableName.getDb(), tableName.getTbl()));
242 objectDescs.add(catalogObject);
245 TPrioritizeLoadRequest request =
new TPrioritizeLoadRequest ();
246 request.setHeader(
new TCatalogServiceRequestHeader());
247 request.setObject_descs(objectDescs);
249 TSerializer serializer =
new TSerializer(
new TBinaryProtocol.Factory());
252 Preconditions.checkNotNull(result);
253 TDeserializer deserializer =
new TDeserializer(
new TBinaryProtocol.Factory());
254 TPrioritizeLoadResponse response =
new TPrioritizeLoadResponse();
255 deserializer.deserialize(response, result);
256 return response.getStatus();
257 }
catch (TException e) {
266 Preconditions.checkNotNull(result);
267 TDeserializer deserializer =
new TDeserializer(
new TBinaryProtocol.Factory());
268 TStartupOptions options =
new TStartupOptions();
269 deserializer.deserialize(options, result);
271 }
catch (TException e) {
272 throw new InternalException(
"Error retrieving startup options: " + e.getMessage(),
283 LOG.info(
"Loading libfesupport.so");
284 NativeLibUtil.loadLibrary(
"libfesupport.so");
285 LOG.info(
"Loaded libfesupport.so");
static TSymbolLookupResult LookupSymbol(TSymbolLookupParams params)
static TCacheJarResult CacheJar(String hdfsLocation)
static native byte[] NativeCacheJar(byte[] thriftCacheJar)
static native byte[] NativeLookupSymbol(byte[] thriftSymbolLookup)
static byte[] CacheJar(byte[] thriftParams)
static native void NativeFeTestInit()
static TColumnValue EvalConstExpr(Expr expr, TQueryCtx queryCtx)
static native byte[] NativePrioritizeLoad(byte[] thriftReq)
static boolean EvalPredicate(Expr pred, TQueryCtx queryCtx)
static TStatus PrioritizeLoad(Set< TableName > tableNames)
static byte[] LookupSymbol(byte[] thriftParams)
static TResultRow EvalPredicateBatch(ArrayList< Expr > exprs, TQueryCtx queryCtx)
static byte[] EvalConstExprs(byte[] thriftExprBatch, byte[] thriftQueryContext)
static TStartupOptions GetStartupOptions()
static synchronized void loadLibrary()
static byte[] PrioritizeLoad(byte[] thriftReq)
static native byte[] NativeGetStartupOptions()
static native byte[] NativeEvalConstExprs(byte[] thriftExprBatch, byte[] thriftQueryGlobals)