From 771b3e358a03c412947573a15fe7af1e1eb3751a Mon Sep 17 00:00:00 2001 From: Achille Date: Wed, 5 Oct 2022 11:58:49 -0700 Subject: [PATCH] fix issue 362 (#363) --- parquet_go18_test.go | 59 +++++++++++++++++-- testdata/dms_test_table_LOAD00000001.parquet | Bin 0 -> 7574 bytes value.go | 2 +- 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 testdata/dms_test_table_LOAD00000001.parquet diff --git a/parquet_go18_test.go b/parquet_go18_test.go index 481c62c..86ad18d 100644 --- a/parquet_go18_test.go +++ b/parquet_go18_test.go @@ -5,7 +5,9 @@ package parquet_test import ( "bytes" "fmt" + "io" "log" + "os" "reflect" "testing" @@ -156,11 +158,60 @@ func TestIssue360(t *testing.T) { }, } - if !reflect.DeepEqual(rows, expect) { + assertRowsEqual(t, expect, rows) +} + +func TestIssue362ParquetReadFromGenericReaders(t *testing.T) { + path := "testdata/dms_test_table_LOAD00000001.parquet" + fp, err := os.Open(path) + if err != nil { + t.Fatal(err) + } + defer fp.Close() + + r1 := parquet.NewGenericReader[any](fp) + rows1 := make([]any, r1.NumRows()) + _, err = r1.Read(rows1) + if err != nil && err != io.EOF { + t.Fatal(err) + } + + r2 := parquet.NewGenericReader[any](fp) + rows2 := make([]any, r2.NumRows()) + _, err = r2.Read(rows2) + if err != nil && err != io.EOF { + t.Fatal(err) + } +} + +func TestIssue362ParquetReadFile(t *testing.T) { + rows1, err := parquet.ReadFile[any]("testdata/dms_test_table_LOAD00000001.parquet") + if err != nil { + t.Fatal(err) + } + + rows2, err := parquet.ReadFile[any]("testdata/dms_test_table_LOAD00000001.parquet") + if err != nil { + t.Fatal(err) + } + + assertRowsEqual(t, rows1, rows2) +} + +func assertRowsEqual(t *testing.T, rows1, rows2 []any) { + if !reflect.DeepEqual(rows1, rows2) { t.Error("rows mismatch") - for _, row := range rows { - t.Logf("%#v", row) - } + t.Log("want:") + logRows(t, rows1) + + t.Log("got:") + logRows(t, rows2) + } +} + +func logRows(t *testing.T, rows []any) { + for _, row := range rows { + t.Logf(". %#v\n", row) } } diff --git a/testdata/dms_test_table_LOAD00000001.parquet b/testdata/dms_test_table_LOAD00000001.parquet new file mode 100644 index 0000000000000000000000000000000000000000..6e252689c22ea7f549f98f6ffab1e3144b3a5391 GIT binary patch literal 7574 zcmeGhdyE`qeRglTJFeF!oplcv*qijGN9f4T&d#giEkzzdX@Zo1AO*g8?#{kvXZLm& z7eZSbV@y57M-_R91`!$%LmEinpHk6~rbeR%4Im*<2|+>{1SAdk`{s3X<$9^mN{nu& z{pR=ke!t)Mdw<`2y?oOZEJ={hCg9mXu7%fOayXqjJ(tbpn5@X;giKc0m=`v((q{x# zVg>P7bApr=lLY)uhrf%nW0GUfN?AczYF6Txnw6K5%x0w}cv)6nYBsmzY@S_;m*S1fr~ zjDC3xtG8f<=?Ju_ItNSO)x<9FRYaYYGX#MrFuML(f;ccv5YGt&@jHqjmR&#)*KQ$* z>sAv4eb0(eon@d-tBNX>g*t6p?&=g>W;!tsc{=Tmk-H=D2Ba5Rf|%TRJ$i>A&iL_n zw?7ZX`qugz?;wb?pWMFv8G=}I`$&5)L7euD-|Pgv&b;L-=WQj3%&)Gx;%fwv_=k3T z1ybSu?DjqM>#Ne_3eRa{pk=LH)$Nk%I&NPqxi3aPuo4^p;aJ^xH(N+0)?YF)6LC(` z`tuB)c;KR;!m2NwU1&c4hZ#&VdDxs;_VkV!^Vaic=1S+z(0^HzCP%$xM_^f7N0msh zo>=WVCc4CQVjlAJ`A{L$$wzK`?E7yNQls{hsVDzBes>|F*|nE!N6ve%6oRS0oxN)2 zsh3|V1Wey655GVidaN)!dDA(|fA(TwTEFwxmmPYxFlSEP)BWS$3#qZjIh!ASzA*Lh z{^IS;*9-IuWSSiFEI1V`(CTfaqDSiCxzn%>qk;UWQqzlIJ(~{1$pi8EiiiXoUhyyX zh(wp~f7b)>zb)oK`iu=B97hG_r4L>W;i2v5@pm5#L4tUA>*4FKo~Ms}aNl>%efYwV zAfDQPUwT6~g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x%uk63O$~TlCf*j5SN3B*2TQj>p4ToJ?ffTjcJ|>UJ^tw^@ zVIIR~v)WgEgoL$jmdnMasf1y0quZwj#Ra;Z+&nusT#LghwF2))Tp(cOD|WG7>vkH5 z8e9^xusGW^Q@3Y3fs3)n8&0DWI84M+o#t#{H|Ee)v#$2LP*3#xg#~qPwdyr@$2hb+ zd1yJkJLlE;Cs&4GDzt_BSHKf#3p-+7NkBSfsHR~yJJm8oG2?auT#p$F*=5y%qVRAy zA2N_qJ_Jt6P)Y#ukUklzZ<`@T0H*S^K1hRXGb zAe}RmX{xoRf^<8?xQmYH)st#jODRYW8eYuPUKH&%Z6pu=?S`xHDv^ZclHkvt??qBb4#UhIGEQ zLj7f^&;;34%YjdhUY8ocN3rjRlN9=IhYPsAN6@vrc(Lw+^Pn5&QkV#w>(z3zHQQ{| zVQ2K1c$Z2+$f@*-&}043yB1pAejAlatx$yQ#jvQhpz(W@cwdC#iEKr91A)0{D{@y3 zINUlZmb7jdZ_ag~>a@*1s=`k0i_W{0okouu+!xyHDrU4CBcO6?rCVS^3=*P}O1by(DG)c_g z+$iTL5@!mN8OUbA%{#%#Zz#p zNRV-O@vrbaAbNo|1^g@EPdpX5u$mep6Xcl$ISQP?g%UxI0W^O(gV{2`7G6*Q(Fe>;~4&d;c($jRo$Jx}Hc^-Vk4tTH(oK*oFW*J5h{vz0ia7jFoo;b4V zKXZ?KBCl~j?!D^?xhOr}d(4l0@puyM{f_VQ>?2-ceeBDh6LPC^axOJKk#F1ohJ*J1 r_cdz%^bI@EN7%HIKe{lvmY5#eboCbK%4vf5w;tjxxahqc{zvv-VI3Gc literal 0 HcmV?d00001 diff --git a/value.go b/value.go index 4f8ea07..2d4b299 100644 --- a/value.go +++ b/value.go @@ -695,7 +695,7 @@ func assignValue(dst reflect.Value, src Value) error { return nil } default: - val = reflect.ValueOf(v) + val = reflect.ValueOf(copyBytes(v)) } }