@@ -158,6 +158,11 @@ private[hive] case class HiveGenericUdf(funcWrapper: HiveFunctionWrapper, childr
158
158
override def foldable =
159
159
isUDFDeterministic && returnInspector.isInstanceOf [ConstantObjectInspector ]
160
160
161
+ @ transient
162
+ protected def constantReturnValue = unwrap(
163
+ returnInspector.asInstanceOf [ConstantObjectInspector ].getWritableConstantValue(),
164
+ returnInspector)
165
+
161
166
@ transient
162
167
protected lazy val deferedObjects =
163
168
argumentInspectors.map(new DeferredObjectAdapter (_)).toArray[DeferredObject ]
@@ -166,6 +171,8 @@ private[hive] case class HiveGenericUdf(funcWrapper: HiveFunctionWrapper, childr
166
171
167
172
override def eval (input : Row ): Any = {
168
173
returnInspector // Make sure initialized.
174
+ if (foldable) return constantReturnValue
175
+
169
176
var i = 0
170
177
while (i < children.length) {
171
178
val idx = i
@@ -193,12 +200,13 @@ private[hive] case class HiveGenericUdaf(
193
200
194
201
@ transient
195
202
protected lazy val objectInspector = {
196
- resolver.getEvaluator(children.map(_.dataType.toTypeInfo).toArray)
203
+ val parameterInfo = new SimpleGenericUDAFParameterInfo (inspectors.toArray, false , false )
204
+ resolver.getEvaluator(parameterInfo)
197
205
.init(GenericUDAFEvaluator .Mode .COMPLETE , inspectors.toArray)
198
206
}
199
207
200
208
@ transient
201
- protected lazy val inspectors = children.map(_.dataType).map( toInspector)
209
+ protected lazy val inspectors = children.map(toInspector)
202
210
203
211
def dataType : DataType = inspectorToDataType(objectInspector)
204
212
@@ -223,12 +231,13 @@ private[hive] case class HiveUdaf(
223
231
224
232
@ transient
225
233
protected lazy val objectInspector = {
226
- resolver.getEvaluator(children.map(_.dataType.toTypeInfo).toArray)
234
+ val parameterInfo = new SimpleGenericUDAFParameterInfo (inspectors.toArray, false , false )
235
+ resolver.getEvaluator(parameterInfo)
227
236
.init(GenericUDAFEvaluator .Mode .COMPLETE , inspectors.toArray)
228
237
}
229
238
230
239
@ transient
231
- protected lazy val inspectors = children.map(_.dataType).map( toInspector)
240
+ protected lazy val inspectors = children.map(toInspector)
232
241
233
242
def dataType : DataType = inspectorToDataType(objectInspector)
234
243
@@ -261,7 +270,7 @@ private[hive] case class HiveGenericUdtf(
261
270
protected lazy val function : GenericUDTF = funcWrapper.createFunction()
262
271
263
272
@ transient
264
- protected lazy val inputInspectors = children.map(_.dataType).map( toInspector)
273
+ protected lazy val inputInspectors = children.map(toInspector)
265
274
266
275
@ transient
267
276
protected lazy val outputInspector = function.initialize(inputInspectors.toArray)
@@ -334,10 +343,13 @@ private[hive] case class HiveUdafFunction(
334
343
} else {
335
344
funcWrapper.createFunction[AbstractGenericUDAFResolver ]()
336
345
}
337
-
338
- private val inspectors = exprs.map(_.dataType).map(toInspector).toArray
339
-
340
- private val function = resolver.getEvaluator(exprs.map(_.dataType.toTypeInfo).toArray)
346
+
347
+ private val inspectors = exprs.map(toInspector).toArray
348
+
349
+ private val function = {
350
+ val parameterInfo = new SimpleGenericUDAFParameterInfo (inspectors, false , false )
351
+ resolver.getEvaluator(parameterInfo)
352
+ }
341
353
342
354
private val returnInspector = function.init(GenericUDAFEvaluator .Mode .COMPLETE , inspectors)
343
355
@@ -350,9 +362,12 @@ private[hive] case class HiveUdafFunction(
350
362
@ transient
351
363
val inputProjection = new InterpretedProjection (exprs)
352
364
365
+ @ transient
366
+ protected lazy val cached = new Array [AnyRef ](exprs.length)
367
+
353
368
def update (input : Row ): Unit = {
354
369
val inputs = inputProjection(input).asInstanceOf [Seq [AnyRef ]].toArray
355
- function.iterate(buffer, inputs)
370
+ function.iterate(buffer, wrap( inputs, inspectors, cached) )
356
371
}
357
372
}
358
373
0 commit comments