diff --git a/main.go b/main.go index d8e9fdf..011c258 100644 --- a/main.go +++ b/main.go @@ -115,22 +115,44 @@ func NewConfig() *Config { // Satisfies the TableRecordHandler interface. type tablePrinter struct { - columnNames []string // A slice of strings to hold column names + headerValues []string // A slice of strings to hold column names } func (t *tablePrinter) HandleInit(ctx context.Context, metadata types.TableMetadata) error { // Store column names in order for _, col := range metadata.ColInfo { - t.columnNames = append(t.columnNames, col.Name) + t.headerValues = append(t.headerValues, col.Name) } return nil } func (t *tablePrinter) HandleRecord(ctx context.Context, r *types.Record) error { + if len(r.Data) != len(t.headerValues) { + return fmt.Errorf("%w: mismatch in header and data sizes", errdefs.ErrInvalidArgument) + } + recordMap := make(map[string]interface{}) for i, d := range r.Data { - recordMap[t.columnNames[i]] = d.String() + var value interface{} + + switch v := d.(type) { + case *types.BooleanValue: + value = v.Value() + case *types.Int64Value: + value = v.Value() + case types.Float64Value: + value = v.Value() + case *types.Time64NSValue: + value = v.Value() + case *types.UInt128Value: + value = v.Value() + default: + // Fallback to string representation if type is unknown + value = d.String() + } + + recordMap[t.headerValues[i]] = value } jsonRecord, err := json.Marshal(recordMap)