Provides conversion from athena outputs to strongly-typed data models.

logo

Provides conversion from athena outputs to strongly defined data models.

Build and test Coverage Status

Getting started

Given the following data struct you define:

type MyModel struct {
    ID                        int       `athenaconv:"id"`
    Name                      string    `athenaconv:"name"`
    SourceComputersCount      int64     `athenaconv:"source_computers_count"`
    SourceComputerExternalIDs []string  `athenaconv:"source_computer_ids"`
    SourceComputerNames       []string  `athenaconv:"source_computer_names"`
    TestTimestamp             time.Time `athenaconv:"test_timestamp"`
    TestDate                  time.Time `athenaconv:"test_date"`
    TestBool                  bool      `athenaconv:"test_bool"`
}

And the following sql:

select
    id,
    name,
    count(source_id) as source_computers_count,
    array_agg(source_id) as source_computer_ids,
    array_agg(source_name) as source_computer_names,
    timestamp '2012-10-31 08:11:22' as test_timestamp,
    date '2021-12-31' as test_date,
    true as test_bool
from my_glue_catalog_table
group by id, name

You can convert your athena.GetQueryResultOutput object to strongly-typed struct MyModel by doing this:

mapper, err := athenaconv.NewMapperFor(reflect.TypeOf(MyModel{}))
if err != nil {
    handleError(err)
}

var mapped []interface{}
mapped, err = mapper.FromAthenaResultSetV2(ctx, queryResultOutput.ResultSet)
if err != nil {
    handleError(err)
}
for _, mappedItem := range mapped {
    mappedItemModel := mappedItem.(*MyModel)
    fmt.Printf("%+v\n", *mappedItemModel)
}

Supported data types

See conversion.go in this repo and supported data types in athena for more details.

Athena data type Go data type Comments
varchar string
boolean bool
integer int/int32
bigint int64
timestamp time.Time
date time.Time
array []string Individual items within array should not contain comma
other data types string Other data types currently unsupported, default to string (no conversion)

Supported AWS SDK version

Roadmap / items to review

  • Add more data type support in conversion.go
  • Review usage of logging (best practice for logging in golang packages)
Owner
Ken Timothy
Senior software engineer at Flexera - AWS solution architect certified, kubernetes, docker, micro-services, dotnet core c# & golang
Ken Timothy
Similar Resources

A tree like tool help you to explore data structures in your redis server

 A tree like tool help you to explore data structures in your redis server

Redis-view is a tree like tool help you explore data structures in your redis server

Mar 17, 2022

Bitset data structure

Your basic bit Set data structure for positive numbers A bit array, or bit set, is an efficient set data structure. It consists of an array that compa

Dec 29, 2022

Probabilistic set data structure

Probabilistic set data structure

Your basic Bloom filter Golang probabilistic set data structure A Bloom filter is a fast and space-efficient probabilistic data structure used to test

Dec 15, 2022

Probabilistic data structures for processing continuous, unbounded streams.

Boom Filters Boom Filters are probabilistic data structures for processing continuous, unbounded streams. This includes Stable Bloom Filters, Scalable

Dec 30, 2022

Data structure and algorithm library for go, designed to provide functions similar to C++ STL

GoSTL English | 简体中文 Introduction GoSTL is a data structure and algorithm library for go, designed to provide functions similar to C++ STL, but more p

Dec 26, 2022

Gota: DataFrames and data wrangling in Go (Golang)

Gota: DataFrames, Series and Data Wrangling for Go This is an implementation of DataFrames, Series and data wrangling methods for the Go programming l

Jan 6, 2023

A simple Set data structure implementation in Go (Golang) using LinkedHashMap.

Set Set is a simple Set data structure implementation in Go (Golang) using LinkedHashMap. This library allow you to get a set of int64 or string witho

Sep 26, 2022

Data structure and relevant algorithms for extremely fast prefix/fuzzy string searching.

Trie Data structure and relevant algorithms for extremely fast prefix/fuzzy string searching. Usage Create a Trie with: t := trie.New() Add Keys with:

Dec 27, 2022
Comments
  • Added examples and tests, bug fixes

    Added examples and tests, bug fixes

    Changes:

    • Fixed mapper returning reflectValue.Elem() - should be reflectValue.Interface() so it can be casted back to original model type.
    • Added client_with_channels example
    • Added mapper tests
    • Added validation to ensure modelType is a reflect.TypeOf(struct) so client gets early feedback when the modelType passed is invalid
  • Decimal and double types are not supported

    Decimal and double types are not supported

    Could you generate update to accept decimal and double type fields? https://github.com/kent-id/athenaconv/blob/1a6fa6972f7e646adb1869d32c476944193f8788/conversion.go#L21

  • Added support to write to chan + code cleanup

    Added support to write to chan + code cleanup

    Changes:

    • Changed contract for dataMapper to accept dest instead of modelType. This makes it easier for consumer code to simply pass a channel of address of the destination slice without having to pass reflect.TypeOf(MyModel{}).
    • Refactored examples and athena_client_v2.go to use the new contract, supporting both slice/chan.
    • Other minor fixes/refactoring
Zero allocation Nullable structures in one library with handy conversion functions, marshallers and unmarshallers

nan - No Allocations Nevermore Package nan - Zero allocation Nullable structures in one library with handy conversion functions, marshallers and unmar

Dec 20, 2022
Null Types, Safe primitive type conversion and fetching value from complex structures.

Typ Typ is a library providing a powerful interface to impressive user experience with conversion and fetching data from built-in types in Golang Feat

Sep 26, 2022
Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types.

Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types. Read th

Dec 27, 2022
BTree provides a simple, ordered, in-memory data structure for Go programs.

BTree implementation for Go This package provides an in-memory B-Tree implementation for Go, useful as an ordered, mutable data structure. The API is

Dec 30, 2022
succinct provides several static succinct data types

succinct provides several static succinct data types Succinct Set Synopsis Performance Implementation License Succinct Set

Jan 5, 2023
Graphoscope: a solution to access multiple independent data sources from a common UI and show data relations as a graph
Graphoscope: a solution to access multiple independent data sources from a common UI and show data relations as a graph

Graphoscope A solution to access multiple independent data sources from a common UI and show data relations as a graph: Contains a list of by default

May 26, 2022
Package ring provides a high performance and thread safe Go implementation of a bloom filter.

ring - high performance bloom filter Package ring provides a high performance and thread safe Go implementation of a bloom filter. Usage Please see th

Nov 20, 2022
go.fifo provides a simple fifo thread-safe queue for the Go programming language

go.fifo Description go.fifo provides a simple FIFO thread-safe queue. *fifo.Queue supports pushing an item at the end with Add(), and popping an item

Aug 29, 2022
SliceX provides functional operations on Go slices using Go 1.18 type parameters.

SliceX provides functional operations on Go slices using Go 1.18 type parameters.

Nov 6, 2021
Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

iter Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transformi

Dec 16, 2022