|
2 | 2 |
|
3 | 3 | import org.apache.hadoop.hive.conf.HiveConf;
|
4 | 4 | import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver;
|
| 5 | +import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; |
5 | 6 |
|
6 | 7 | import com.sap.hadoop.ds.list.ByteBasedList;
|
7 | 8 | import com.sap.hadoop.windowing.Constants;
|
|
11 | 12 |
|
12 | 13 | /**
|
13 | 14 | * Based on Hive {@link GenericUDAFResolver}. Break up the responsibility of the
|
14 |
| - * old AsbtractTableFunction class into a Resolver and Evaluator. |
15 |
| - * |
16 |
| - * |
| 15 | + * old AbstractTableFunction class into a Resolver and Evaluator. |
| 16 | + * The Resolver is responsible for: |
| 17 | + * <ol> |
| 18 | + * <li> setting up the {@link tableFunctionEvaluator} |
| 19 | + * <li> Setting up the The raw and output ObjectInspectors of the Evaluator. |
| 20 | + * <li> The Evaluator also holds onto the {@link TableFunctionDef}. This provides information |
| 21 | + * about the arguments to the function, the shape of the Input partition and the Partitioning details. |
| 22 | + * </ol> |
| 23 | + * The Resolver for a function is obtained from the {@link FunctionRegistry}. The Resolver is initialized |
| 24 | + * by the following 4 step process: |
| 25 | + * <ol> |
| 26 | + * <li> The initialize method is called; which is passed the {@link QueryDef} and the {@link TableFunctionDef}. |
| 27 | + * <li> The resolver is then asked to setup the Raw ObjectInspector. This is only required if the Function reshapes |
| 28 | + * the raw input. |
| 29 | + * <li> Once the Resolver has had a chance to compute the shape of the Raw Input that is fed to the partitioning |
| 30 | + * machinery; the translator sets up the partitioning details on the tableFuncDef. |
| 31 | + * <li> finally the resolver is asked to setup the output ObjectInspector. |
| 32 | + * </ol> |
17 | 33 | */
|
18 | 34 | @SuppressWarnings("deprecation")
|
19 |
| -public abstract class TableFunctionResolver { |
20 |
| - protected boolean hasMapPhase; |
| 35 | +public abstract class TableFunctionResolver |
| 36 | +{ |
| 37 | + TableFunctionEvaluator evaluator; |
| 38 | + QueryDef qDef; |
21 | 39 |
|
22 |
| - public TableFunctionEvaluator initialize(QueryDef qDef, TableFuncDef tDef) |
23 |
| - throws WindowingException { |
| 40 | + /* |
| 41 | + * - called during translation. |
| 42 | + * - invokes createEvaluator which must be implemented by a subclass |
| 43 | + * - sets up the evaluator with references to the TableDef, PartitionClass, PartitonMemsize and |
| 44 | + * the transformsRawInput boolean. |
| 45 | + */ |
| 46 | + public void initialize(QueryDef qDef, TableFuncDef tDef) |
| 47 | + throws WindowingException |
| 48 | + { |
| 49 | + this.qDef = qDef; |
24 | 50 | HiveConf cfg = qDef.getTranslationInfo().getHiveCfg();
|
25 | 51 | String partitionClass = cfg.get(Constants.WINDOW_PARTITION_CLASS,
|
26 | 52 | Constants.DEFAULT_WINDOW_PARTITION_CLASS);
|
27 | 53 | int partitionMemSize = cfg.getInt(Constants.WINDOW_PARTITION_MEM_SIZE,
|
28 | 54 | ByteBasedList.MEDIUM_SIZE);
|
29 | 55 |
|
30 |
| - TableFunctionEvaluator tfEval = createEvaluator(qDef, tDef); |
31 |
| - tfEval.setResolver(this); |
32 |
| - tfEval.setQueryDef(qDef); |
33 |
| - tfEval.setTableDef(tDef); |
34 |
| - tfEval.setPartitionClass(partitionClass); |
35 |
| - tfEval.setPartitionMemSize(partitionMemSize); |
| 56 | + evaluator = createEvaluator(qDef, tDef); |
| 57 | + evaluator.setTransformsRawInput(transformsRawInput()); |
| 58 | + evaluator.setTableDef(tDef); |
| 59 | + evaluator.setQueryDef(qDef); |
| 60 | + evaluator.setPartitionClass(partitionClass); |
| 61 | + evaluator.setPartitionMemSize(partitionMemSize); |
36 | 62 |
|
37 |
| - return tfEval; |
| 63 | + } |
| 64 | + |
| 65 | + /* |
| 66 | + * called during deserialization of a QueryDef during runtime. |
| 67 | + */ |
| 68 | + public void initialize(QueryDef qDef, TableFuncDef tDef, TableFunctionEvaluator evaluator) |
| 69 | + throws WindowingException |
| 70 | + { |
| 71 | + this.evaluator = evaluator; |
| 72 | + this.qDef = qDef; |
| 73 | + evaluator.setTableDef(tDef); |
| 74 | + evaluator.setQueryDef(qDef); |
| 75 | + } |
| 76 | + |
| 77 | + public TableFunctionEvaluator getEvaluator() |
| 78 | + { |
| 79 | + return evaluator; |
38 | 80 | }
|
39 | 81 |
|
40 |
| - public boolean hasMapPhase() { |
41 |
| - return hasMapPhase; |
| 82 | + /* |
| 83 | + * - a subclass must provide this method. |
| 84 | + * - this method is invoked during translation and also when the Operator is initialized during runtime. |
| 85 | + * - a subclass must use this call to setup the shape of its output. |
| 86 | + * - subsequent to this call, a call to getOutputOI call on the {@link TableFunctionEvaluator} must return the OI |
| 87 | + * of the output of this function. |
| 88 | + */ |
| 89 | + public abstract void setupOutputOI() throws WindowingException; |
| 90 | + |
| 91 | + /* |
| 92 | + * - Called on functions that transform the raw input. |
| 93 | + * - this method is invoked during translation and also when the Operator is initialized during runtime. |
| 94 | + * - a subclass must use this call to setup the shape of the raw input, that is fed to the partitioning mechanics. |
| 95 | + * - subsequent to this call, a call to getRawInputOI call on the {@link TableFunctionEvaluator} must return the OI |
| 96 | + * of the output of this function. |
| 97 | + */ |
| 98 | + public void setupRawInputOI() throws WindowingException |
| 99 | + { |
| 100 | + if (!transformsRawInput()) |
| 101 | + { |
| 102 | + return; |
| 103 | + } |
| 104 | + throw new WindowingException( |
| 105 | + "Function has map phase, must extend setupMapOI"); |
| 106 | + } |
| 107 | + |
| 108 | + /* |
| 109 | + * callback method used by subclasses to set the RawInputOI on the Evaluator. |
| 110 | + */ |
| 111 | + protected void setRawInputOI(StructObjectInspector rawInputOI) |
| 112 | + { |
| 113 | + evaluator.setRawInputOI(rawInputOI); |
| 114 | + } |
| 115 | + |
| 116 | + /* |
| 117 | + * callback method used by subclasses to set the OutputOI on the Evaluator. |
| 118 | + */ |
| 119 | + protected void setOutputOI(StructObjectInspector outputOI) |
| 120 | + { |
| 121 | + evaluator.setOutputOI(outputOI); |
42 | 122 | }
|
43 | 123 |
|
44 |
| - protected void setHasMapPhase() throws WindowingException { |
45 |
| - hasMapPhase = false; |
| 124 | + public QueryDef getQueryDef() |
| 125 | + { |
| 126 | + return qDef; |
46 | 127 | }
|
47 | 128 |
|
| 129 | + /* |
| 130 | + * a subclass must indicate whether it will transform the raw input before it is fed through the |
| 131 | + * partitioning mechanics. |
| 132 | + */ |
| 133 | + public abstract boolean transformsRawInput(); |
| 134 | + |
| 135 | + /* |
| 136 | + * a subclass must provide the {@link TableFunctionEvaluator} instance. |
| 137 | + */ |
48 | 138 | protected abstract TableFunctionEvaluator createEvaluator(QueryDef qDef,
|
49 | 139 | TableFuncDef tDef);
|
50 |
| - |
51 | 140 | }
|
0 commit comments