Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/1793#discussion_r56256616 --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/plan/nodes/dataset/DataSetAggregate.scala --- @@ -96,24 +93,32 @@ class DataSetAggregate( val mappedInput = inputDS.map(aggregateResult._1).name(s"prepare $aggString") val groupReduceFunction = aggregateResult._2 - if (groupingKeys.length > 0) { + val result = { + if (groupingKeys.length > 0) { + val inFields = inputType.getFieldNames.asScala.toList + val groupByString = s"groupBy: (${grouping.map(inFields(_)).mkString(", ")})" - val inFields = inputType.getFieldNames.asScala.toList - val groupByString = s"groupBy: (${grouping.map( inFields(_) ).mkString(", ")})" - - mappedInput.asInstanceOf[DataSet[Row]] - .groupBy(groupingKeys: _*) - .reduceGroup(groupReduceFunction) - .returns(rowTypeInfo) + mappedInput.asInstanceOf[DataSet[Row]] + .groupBy(groupingKeys: _*) + .reduceGroup(groupReduceFunction) + .returns(rowTypeInfo) .name(groupByString + ", " + aggString) - .asInstanceOf[DataSet[Any]] + .asInstanceOf[DataSet[Any]] + } + else { + // global aggregation + mappedInput.asInstanceOf[DataSet[Row]] + .reduceGroup(groupReduceFunction) + .returns(rowTypeInfo) + .asInstanceOf[DataSet[Any]] + } } - else { - // global aggregation - mappedInput.asInstanceOf[DataSet[Row]] - .reduceGroup(groupReduceFunction) - .returns(rowTypeInfo) - .asInstanceOf[DataSet[Any]] + + // if the expected type is not a Row, inject a mapper to convert to the expected type + expectedType match { + case Some(typeInfo) if typeInfo.getTypeClass != classOf[Row] => + result.map(typeConversion(config, rowTypeInfo, expectedType.get)) --- End diff -- Add a name for the operator.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---