-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
As part of this task, it is necessary to implement the auto_resolve_expression setting. If it is enabled, then you need to generate an expression from system.columns.
Example:
package database
import (
"context"
"fmt"
"strings"
)
type Column struct {
Name string
Type ColumnType
AggregateFunction string
IsSortingKey bool
IsPrimaryKey bool
}
type ColumnType int
const (
ColumnDefaultType ColumnType = iota + 1
AggregateFunctionType
)
func (db *Database) Columns(ctx context.Context, database, table string) ([]Column, error) {
var columns []Column
rows, err := db.cluster.Query(ctx,
`SELECT
name, type, is_in_sorting_key, is_in_primary_key
FROM
system.columns
WHERE
database = $1 AND table = $2`, database, table)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var column Column
var typeString string
if err = rows.Scan(&column.Name, &typeString, &column.IsSortingKey, &column.IsPrimaryKey); err != nil {
return nil, err
}
column.Type = parseType(typeString)
if column.Type == AggregateFunctionType {
column.AggregateFunction = parseAggregateFunction(typeString)
}
columns = append(columns, column)
}
if len(columns) == 0 {
return nil, fmt.Errorf("columns not found")
}
return columns, nil
}
func parseType(s string) ColumnType {
if strings.HasPrefix(s, "AggregateFunction") {
return AggregateFunctionType
}
return ColumnDefaultType
}
func parseAggregateFunction(s string) string {
args := strings.TrimSuffix(strings.TrimPrefix(s, "AggregateFunction("), ")")
splittedArgs := strings.Split(args, ",")
return splittedArgs[0]
}Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request