Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support complex type such as map(string, array(map(string, float64))) #61

Closed
gangtao opened this issue Dec 5, 2023 · 5 comments · Fixed by #65
Closed

Support complex type such as map(string, array(map(string, float64))) #61

gangtao opened this issue Dec 5, 2023 · 5 comments · Fixed by #65
Assignees
Labels
enhancement New feature or request

Comments

@gangtao
Copy link
Collaborator

gangtao commented Dec 5, 2023

following query can be successfully running on proton but failed to run in neutron.

with t1 as (
SELECT 
  '1' as granularity, to_float64(_tp_time) as ts , product_id as symbol, cast((['ts', 'price'], [ts, price]), 'map(string, float64)') AS value
FROM 
  btc_usd_coinbase
),
t2 as (
  select symbol, granularity, group_array(value) AS value_array from t1 group by symbol, granularity order by symbol, granularity
),
t3 as (
  select symbol, group_array(granularity) as granularities, group_array(value_array) as values from t2 group by symbol
)
select symbol, cast((granularities, values), 'map(string, array(map(string, float64)))') from t3

neutron error is

proton: unsupported column type "map(string, array(map(string, float64)))".

I think it is because go-driver does not support this complex type as of now, which is required .

@gangtao gangtao added the enhancement New feature or request label Dec 5, 2023
@ye11ow
Copy link
Collaborator

ye11ow commented Dec 5, 2023

@leo-cai-timeplus
Copy link
Contributor

clickhouse support this

package main

import (
	"context"
	"fmt"
	"github.com/ClickHouse/clickhouse-go/v2"
	"log"
	"time"
)

func example() error {
	var (
		ctx       = context.Background()
		conn, err = clickhouse.Open(&clickhouse.Options{
			Addr: []string{"127.0.0.1:9000"},
			Auth: clickhouse.Auth{
				Database: "default",
				Username: "default",
				Password: "",
			},
			//Debug:           true,
			DialTimeout:     time.Second,
			MaxOpenConns:    10,
			MaxIdleConns:    5,
			ConnMaxLifetime: time.Hour,
		})
	)
	if err != nil {
		return err
	}
	if err := conn.Exec(ctx, "set allow_experimental_map_type = 1;"); err != nil {
		return err
	}
	if err := conn.Exec(ctx, `DROP TABLE IF EXISTS table_map;`); err != nil {
		return err
	}
	err = conn.Exec(ctx, `
		CREATE TABLE table_map (a Map(String, Array(Map(String, Float64)))) ENGINE = Memory;
	`)
	if err != nil {
		return err
	}

	batch, err := conn.PrepareBatch(ctx, "INSERT INTO table_map")
	if err != nil {
		return err
	}
	for i := 0; i < 100; i++ {
		err := batch.Append(
			map[string][]map[string]float64{
				"key1": {
					{"sub_key1": 10.9, "sub_key2": float64(i)},
					{"sub_key3": float64(i) + 0.1},
				},
			},
		)
		if err != nil {
			return err
		}
	}
	err = batch.Send()
	if err != nil {
		return err
	}
	rows, err := conn.Query(ctx, "SELECT * FROM table_map")
	for rows.Next() {
		a := &map[string][]map[string]float64{}
		err := rows.Scan(a)
		if err != nil {
			return err
		}
		fmt.Println(a)
	}
	if err != nil {
		return err
	}
	return err
}

func main() {
	start := time.Now()
	if err := example(); err != nil {
		log.Fatal(err)
	}
	fmt.Println(time.Since(start))
}

@ye11ow
Copy link
Collaborator

ye11ow commented Dec 12, 2023

Yeah, we were too behind the offical clickhouse go driver. It has been years since we rebased. This can be an issue

@leo-cai-timeplus leo-cai-timeplus linked a pull request Dec 18, 2023 that will close this issue
@leo-cai-timeplus leo-cai-timeplus self-assigned this Dec 18, 2023
@jovezhong
Copy link
Collaborator

(Jove Github Bot) added it to the current sprint.

@jovezhong
Copy link
Collaborator

(Jove Github Bot) moved this ticket out of the GitHub project(up to 1200 tickets for one project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants