# A New Functional Approach to Complex Types in Apache Hive

DevFeed: [A New Functional Approach to Complex Types in Apache Hive](<https://devfeed.tech/articles/a-new-functional-approach-to-complex-types-in-apache-hive-27969.md>)

Original publisher: [Read original article](<https://tech.trivago.com/post/2019-01-30-functional-approach-complex-types-apache-hive/>)

Author: Jan Filipiak Software programmer; Constantly Surprised By How Stupid Computers Are Still Knows Where His Towel Is

Published: 2019-01-30T00:00:00Z

Content type: article

Language: en

Sources: [Trivago](<https://devfeed.tech/sources/trivago.md>)

Topics: [sql-database](<https://devfeed.tech/topics/sql-database.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Database](<https://devfeed.tech/topics/database.md>), [Hadoop](<https://devfeed.tech/topics/hadoop.md>), [Apache Spark](<https://devfeed.tech/topics/spark.md>), [Tez](<https://devfeed.tech/topics/tez.md>)

Tags: [aggregate](<https://devfeed.tech/tags/aggregate.md>), [analyze](<https://devfeed.tech/tags/analyze.md>), [apache-hive](<https://devfeed.tech/tags/apache-hive.md>), [api](<https://devfeed.tech/tags/api.md>), [arguments](<https://devfeed.tech/tags/arguments.md>), [array](<https://devfeed.tech/tags/array.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [collection](<https://devfeed.tech/tags/collection.md>), [collections](<https://devfeed.tech/tags/collections.md>), [complex](<https://devfeed.tech/tags/complex.md>), [data-science](<https://devfeed.tech/tags/data-science.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [data-types](<https://devfeed.tech/tags/data-types.md>), [hive](<https://devfeed.tech/tags/hive.md>), [languages](<https://devfeed.tech/tags/languages.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [query-languages](<https://devfeed.tech/tags/query-languages.md>)

## AI overview

Hive's lateral-view UDTFs can expand nested collections into rows, but recombining them with GROUP BY may add a MapReduce phase and network shuffle. The article describes a HiveQL approach using macros as lambdas, invoked by custom UDFs such as collection_map, collection_filter, and collection_reduce. Its example reduces deeply nested arrays, structs, and maps to word counts within one Hive operator, avoiding that shuffle while keeping the logic in HiveQL. Implementation required querying macro input types and converting values before invocation because Hive's converters match struct fields by ordinal position; macros also had to be serialized during driver initialization so worker tasks could use them. The excerpt says the UDFs were intended to work across a wide range of Hive versions, and that the cited macro-processing bug does not affect Hive versions below 2.0.

## Source excerpt

When faced with the challenge to store, retrieve and process small or large amounts of data, structured query languages are typically not far away. These languages serve as a nice abstraction be...