@@ -406,10 +406,6 @@ func schemaFromColumns(columns []physical.ColumnExpression) (*arrow.Schema, erro
406406 return nil , fmt .Errorf ("invalid column expression type %T" , column )
407407 }
408408
409- md := arrow .MetadataFrom (map [string ]string {
410- types .MetadataKeyColumnType : columnExpr .Ref .Type .String (),
411- })
412-
413409 switch columnExpr .Ref .Type {
414410 case types .ColumnTypeLabel :
415411 // TODO(rfratto): Switch to dictionary encoding for labels.
@@ -424,9 +420,10 @@ func schemaFromColumns(columns []physical.ColumnExpression) (*arrow.Schema, erro
424420 //
425421 // We skipped dictionary encoding for now to get the initial prototype
426422 // working.
423+ ty , md := arrowTypeFromColumnRef (columnExpr .Ref )
427424 addField (arrow.Field {
428425 Name : columnExpr .Ref .Column ,
429- Type : arrow . BinaryTypes . String ,
426+ Type : ty ,
430427 Nullable : true ,
431428 Metadata : md ,
432429 })
@@ -436,15 +433,16 @@ func schemaFromColumns(columns []physical.ColumnExpression) (*arrow.Schema, erro
436433 // has unconstrained cardinality. Using dictionary encoding would require
437434 // tracking every encoded value in the record, which is likely to be too
438435 // expensive.
436+ ty , md := arrowTypeFromColumnRef (columnExpr .Ref )
439437 addField (arrow.Field {
440438 Name : columnExpr .Ref .Column ,
441- Type : arrow . BinaryTypes . String ,
439+ Type : ty ,
442440 Nullable : true ,
443441 Metadata : md ,
444442 })
445443
446444 case types .ColumnTypeBuiltin :
447- ty , md := builtinColumnType (columnExpr .Ref )
445+ ty , md := arrowTypeFromColumnRef (columnExpr .Ref )
448446 addField (arrow.Field {
449447 Name : columnExpr .Ref .Column ,
450448 Type : ty ,
@@ -472,36 +470,36 @@ func schemaFromColumns(columns []physical.ColumnExpression) (*arrow.Schema, erro
472470 Name : columnExpr .Ref .Column ,
473471 Type : arrow .BinaryTypes .String ,
474472 Nullable : true ,
475- Metadata : arrow . MetadataFrom ( map [ string ] string { types .MetadataKeyColumnType : types . ColumnTypeLabel . String ()} ),
473+ Metadata : datatype . ColumnMetadata ( types .ColumnTypeLabel , datatype . String ),
476474 })
477475 addField (arrow.Field {
478476 Name : columnExpr .Ref .Column ,
479477 Type : arrow .BinaryTypes .String ,
480478 Nullable : true ,
481- Metadata : arrow . MetadataFrom ( map [ string ] string { types .MetadataKeyColumnType : types . ColumnTypeMetadata . String ()} ),
479+ Metadata : datatype . ColumnMetadata ( types .ColumnTypeMetadata , datatype . String ),
482480 })
483481
484- case types .ColumnTypeParsed :
482+ case types .ColumnTypeParsed , types . ColumnTypeGenerated :
485483 return nil , fmt .Errorf ("parsed column type not supported: %s" , columnExpr .Ref .Type )
486484 }
487485 }
488486
489487 return arrow .NewSchema (fields , nil ), nil
490488}
491489
492- func builtinColumnType (ref types.ColumnRef ) (arrow.DataType , arrow.Metadata ) {
493- if ref .Type != types .ColumnTypeBuiltin {
494- panic ("builtinColumnType called with a non-builtin column" )
490+ func arrowTypeFromColumnRef (ref types.ColumnRef ) (arrow.DataType , arrow.Metadata ) {
491+ if ref .Type == types .ColumnTypeBuiltin {
492+ switch ref .Column {
493+ case types .ColumnNameBuiltinTimestamp :
494+ return arrow .FixedWidthTypes .Timestamp_ns , datatype .ColumnMetadataBuiltinTimestamp
495+ case types .ColumnNameBuiltinMessage :
496+ return arrow .BinaryTypes .String , datatype .ColumnMetadataBuiltinMessage
497+ default :
498+ panic (fmt .Sprintf ("unsupported builtin column type %s" , ref ))
499+ }
495500 }
496501
497- switch ref .Column {
498- case types .ColumnNameBuiltinTimestamp :
499- return arrow .FixedWidthTypes .Timestamp_ns , datatype .ColumnMetadataBuiltinTimestamp
500- case types .ColumnNameBuiltinMessage :
501- return arrow .BinaryTypes .String , datatype .ColumnMetadataBuiltinMessage
502- default :
503- panic (fmt .Sprintf ("unsupported builtin column type %s" , ref ))
504- }
502+ return arrow .BinaryTypes .String , datatype .ColumnMetadata (ref .Type , datatype .String )
505503}
506504
507505// appendToBuilder appends a the provided field from record into the given
0 commit comments