MCPcopy Create free account
hub / github.com/PostHog/duckgres / appendValue

Function appendValue

server/flightclient/flight_executor_arrow_test.go:1806–1857  ·  view source on GitHub ↗

appendValue is a test-only reimplementation of the subset of duckdbservice.AppendValue logic needed for MAP round-trip tests. It lives here because server cannot import duckdbservice. Keep in sync with duckdbservice.AppendValue when MAP handling changes.

(builder array.Builder, val interface{})

Source from the content-addressed store, hash-verified

1804 defer src.Release()
1805
1806 rb2 := array.NewRecordBuilder(alloc, schema)
1807 defer rb2.Release()
1808 val := extractArrowValue(src.Column(0), 0)
1809 appendValue(rb2.Field(0), val)
1810
1811 dst := rb2.NewRecordBatch()
1812 defer dst.Release()
1813
1814 col := dst.Column(0).(*array.Map)
1815 if col.IsNull(0) {
1816 t.Fatal("rebuilt MAP(VARCHAR,STRUCT) is null")
1817 }
1818 rebuilt := extractArrowValue(col, 0).(arrowmap.OrderedMapValue)
1819 point, ok := rebuilt.Values[0].(map[string]interface{})
1820 if !ok {
1821 t.Fatalf("point value is %T, want map[string]interface{}", rebuilt.Values[0])
1822 }
1823 if point["x"] != int32(10) || point["y"] != int32(20) {
1824 t.Errorf("point = %v, want {x:10, y:20}", point)
1825 }
1826}
1827
1828func TestExtractThenAppend_ListOfMap(t *testing.T) {
1829 // LIST(MAP(VARCHAR, INT)) — list elements are maps.
1830 alloc := memory.NewGoAllocator()
1831 mt := arrow.MapOf(arrow.BinaryTypes.String, arrow.PrimitiveTypes.Int32)
1832 schema := arrow.NewSchema([]arrow.Field{
1833 {Name: "list", Type: arrow.ListOf(mt), Nullable: true},
1834 }, nil)
1835
1836 rb := array.NewRecordBuilder(alloc, schema)
1837 defer rb.Release()
1838 lb := rb.Field(0).(*array.ListBuilder)
1839 mmb := lb.ValueBuilder().(*array.MapBuilder)
1840 lb.Append(true)
1841 mmb.Append(true)
1842 mmb.KeyBuilder().(*array.StringBuilder).Append("a")
1843 mmb.ItemBuilder().(*array.Int32Builder).Append(1)
1844 mmb.Append(true)
1845 mmb.KeyBuilder().(*array.StringBuilder).Append("b")
1846 mmb.ItemBuilder().(*array.Int32Builder).Append(2)
1847
1848 src := rb.NewRecordBatch()
1849 defer src.Release()
1850
1851 rb2 := array.NewRecordBuilder(alloc, schema)
1852 defer rb2.Release()
1853 val := extractArrowValue(src.Column(0), 0)
1854 appendValue(rb2.Field(0), val)
1855
1856 dst := rb2.NewRecordBatch()
1857 defer dst.Release()
1858
1859 lcol := dst.Column(0).(*array.List)
1860 if lcol.IsNull(0) {

Calls

no outgoing calls

Tested by

no test coverage detected