@@ -397,7 +397,12 @@ label_2
397397 })
398398}
399399
400- func TestEvaluateUnwrapExpression (t * testing.T ) {
400+ func TestEvaluateUnaryCastExpression (t * testing.T ) {
401+ colMsg := semconv .ColumnIdentMessage
402+ colStatusCode := semconv .NewIdentifier ("status_code" , types .ColumnTypeMetadata , types .Loki .String )
403+ colTimeout := semconv .NewIdentifier ("timeout" , types .ColumnTypeParsed , types .Loki .String )
404+ colMixedValues := semconv .NewIdentifier ("mixed_values" , types .ColumnTypeMetadata , types .Loki .String )
405+
401406 t .Run ("unknown column" , func (t * testing.T ) {
402407 alloc := memory .NewCheckedAllocator (memory .DefaultAllocator )
403408 defer alloc .AssertSize (t , 0 ) // Assert empty on test exit
@@ -409,13 +414,14 @@ func TestEvaluateUnwrapExpression(t *testing.T) {
409414 Type : types .ColumnTypeAmbiguous ,
410415 },
411416 },
412- Op : types .UnaryOpUnwrap ,
417+ Op : types .UnaryOpCastFloat ,
413418 }
414419
415420 n := len (words )
416421 rec := batch (n , time .Now ())
417422 colVec , err := e .eval (expr , rec )
418423 require .NoError (t , err )
424+ defer colVec .Release ()
419425
420426 id := colVec .Type ().ArrowType ().ID ()
421427 require .Equal (t , arrow .STRUCT , id )
@@ -442,37 +448,41 @@ func TestEvaluateUnwrapExpression(t *testing.T) {
442448 }
443449 })
444450
445- t .Run ("unwrap column generates a value" , func (t * testing.T ) {
451+ t .Run ("cast column generates a value" , func (t * testing.T ) {
446452 expr := & physical.UnaryExpr {
447453 Left : & physical.ColumnExpr {
448454 Ref : types.ColumnRef {
449455 Column : "status_code" ,
450456 Type : types .ColumnTypeAmbiguous ,
451457 },
452458 },
453- Op : types .UnaryOpUnwrap ,
459+ Op : types .UnaryOpCastBytes ,
454460 }
455461
456462 alloc := memory .NewCheckedAllocator (memory .DefaultAllocator )
457463 defer alloc .AssertSize (t , 0 ) // Assert empty on test exit
458464 e := newExpressionEvaluator (alloc )
459465
460- schema := arrow .NewSchema ([]arrow.Field {
461- {Name : types .ColumnNameBuiltinMessage , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeBuiltin , types .Loki .String )},
462- {Name : "status_code" , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeMetadata , types .Loki .String )},
463- {Name : "timeout" , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeParsed , types .Loki .String )},
464- }, nil )
466+ schema := arrow .NewSchema (
467+ []arrow.Field {
468+ semconv .FieldFromIdent (colMsg , false ),
469+ semconv .FieldFromIdent (colStatusCode , true ),
470+ semconv .FieldFromIdent (colTimeout , true ),
471+ },
472+ nil ,
473+ )
465474 rows := arrowtest.Rows {
466- {"message" : "timeout set" , "status_code" : "200" , "timeout" : "2m" },
467- {"message" : "short timeout" , "status_code" : "204" , "timeout" : "10s" },
468- {"message" : "long timeout" , "status_code" : "404" , "timeout" : "1h" },
475+ {"utf8.builtin. message" : "timeout set" , "utf8.metadata. status_code" : "200" , "utf8.parsed. timeout" : "2m" },
476+ {"utf8.builtin. message" : "short timeout" , "utf8.metadata. status_code" : "204" , "utf8.parsed. timeout" : "10s" },
477+ {"utf8.builtin. message" : "long timeout" , "utf8.metadata. status_code" : "404" , "utf8.parsed. timeout" : "1h" },
469478 }
470479
471480 record := rows .Record (alloc , schema )
472481 defer record .Release ()
473482
474483 colVec , err := e .eval (expr , record )
475484 require .NoError (t , err )
485+ defer colVec .Release ()
476486 id := colVec .Type ().ArrowType ().ID ()
477487 require .Equal (t , arrow .STRUCT , id )
478488
@@ -490,37 +500,41 @@ func TestEvaluateUnwrapExpression(t *testing.T) {
490500 require .Equal (t , 404.0 , value .Value (2 ))
491501 })
492502
493- t .Run ("unwrap column generates a value from a parsed column" , func (t * testing.T ) {
503+ t .Run ("cast column generates a value from a parsed column" , func (t * testing.T ) {
494504 expr := & physical.UnaryExpr {
495505 Left : & physical.ColumnExpr {
496506 Ref : types.ColumnRef {
497507 Column : "timeout" ,
498508 Type : types .ColumnTypeAmbiguous ,
499509 },
500510 },
501- Op : types .UnaryOpUnwrapDuration ,
511+ Op : types .UnaryOpCastDuration ,
502512 }
503513
504514 alloc := memory .NewCheckedAllocator (memory .DefaultAllocator )
505515 defer alloc .AssertSize (t , 0 ) // Assert empty on test exit
506516 e := newExpressionEvaluator (alloc )
507517
508- schema := arrow .NewSchema ([]arrow.Field {
509- {Name : types .ColumnNameBuiltinMessage , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeBuiltin , types .Loki .String )},
510- {Name : "status_code" , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeMetadata , types .Loki .String )},
511- {Name : "timeout" , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeParsed , types .Loki .String )},
512- }, nil )
518+ schema := arrow .NewSchema (
519+ []arrow.Field {
520+ semconv .FieldFromIdent (colMsg , false ),
521+ semconv .FieldFromIdent (colStatusCode , true ),
522+ semconv .FieldFromIdent (colTimeout , true ),
523+ },
524+ nil ,
525+ )
513526 rows := arrowtest.Rows {
514- {"message" : "timeout set" , "status_code" : "200" , "timeout" : "2m" },
515- {"message" : "short timeout" , "status_code" : "204" , "timeout" : "10s" },
516- {"message" : "long timeout" , "status_code" : "404" , "timeout" : "1h" },
527+ {"utf8.builtin. message" : "timeout set" , "utf8.metadata. status_code" : "200" , "utf8.parsed. timeout" : "2m" },
528+ {"utf8.builtin. message" : "short timeout" , "utf8.metadata. status_code" : "204" , "utf8.parsed. timeout" : "10s" },
529+ {"utf8.builtin. message" : "long timeout" , "utf8.metadata. status_code" : "404" , "utf8.parsed. timeout" : "1h" },
517530 }
518531
519532 record := rows .Record (alloc , schema )
520533 defer record .Release ()
521534
522535 colVec , err := e .eval (expr , record )
523536 require .NoError (t , err )
537+ defer colVec .Release ()
524538 id := colVec .Type ().ArrowType ().ID ()
525539 require .Equal (t , arrow .STRUCT , id )
526540
@@ -537,38 +551,42 @@ func TestEvaluateUnwrapExpression(t *testing.T) {
537551 require .Equal (t , 3600.0 , value .Value (2 ))
538552 })
539553
540- t .Run ("unwrap tracks errors" , func (t * testing.T ) {
554+ t .Run ("cast operation tracks errors" , func (t * testing.T ) {
541555 colExpr := & physical.UnaryExpr {
542556 Left : & physical.ColumnExpr {
543557 Ref : types.ColumnRef {
544558 Column : "mixed_values" ,
545559 Type : types .ColumnTypeAmbiguous ,
546560 },
547561 },
548- Op : types .UnaryOpUnwrap ,
562+ Op : types .UnaryOpCastFloat ,
549563 }
550564
551565 alloc := memory .NewCheckedAllocator (memory .DefaultAllocator )
552566 defer alloc .AssertSize (t , 0 ) // Assert empty on test exit
553567 e := newExpressionEvaluator (alloc )
554568
555- schema := arrow .NewSchema ([]arrow.Field {
556- {Name : types .ColumnNameBuiltinMessage , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeBuiltin , types .Loki .String )},
557- {Name : "mixed_values" , Type : arrow .BinaryTypes .String , Metadata : types .ColumnMetadata (types .ColumnTypeMetadata , types .Loki .String )},
558- }, nil )
569+ schema := arrow .NewSchema (
570+ []arrow.Field {
571+ semconv .FieldFromIdent (colMsg , false ),
572+ semconv .FieldFromIdent (colMixedValues , true ),
573+ },
574+ nil ,
575+ )
559576 rows := arrowtest.Rows {
560- {"message" : "valid numeric" , "mixed_values" : "42.5" },
561- {"message" : "invalid numeric" , "mixed_values" : "not_a_number" },
562- {"message" : "valid bytes" , "mixed_values" : "1KB" },
563- {"message" : "invalid bytes" , "mixed_values" : "invalid_bytes" },
564- {"message" : "empty string" , "mixed_values" : "" },
577+ {"utf8.builtin. message" : "valid numeric" , "utf8.metadata. mixed_values" : "42.5" },
578+ {"utf8.builtin. message" : "invalid numeric" , "utf8.metadata. mixed_values" : "not_a_number" },
579+ {"utf8.builtin. message" : "valid bytes" , "utf8.metadata. mixed_values" : "1KB" },
580+ {"utf8.builtin. message" : "invalid bytes" , "utf8.metadata. mixed_values" : "invalid_bytes" },
581+ {"utf8.builtin. message" : "empty string" , "utf8.metadata. mixed_values" : "" },
565582 }
566583
567584 record := rows .Record (alloc , schema )
568585 defer record .Release ()
569586
570587 colVec , err := e .eval (colExpr , record )
571588 require .NoError (t , err )
589+ defer colVec .Release ()
572590 id := colVec .Type ().ArrowType ().ID ()
573591 require .Equal (t , arrow .STRUCT , id )
574592
0 commit comments