to_parquet_levels_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package schema
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. )
  7. func TestToParquetLevels(t *testing.T) {
  8. type args struct {
  9. recordType *schema_pb.RecordType
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. want *ParquetLevels
  15. }{
  16. {
  17. name: "nested type",
  18. args: args{
  19. RecordTypeBegin().
  20. WithField("ID", TypeInt64).
  21. WithField("CreatedAt", TypeInt64).
  22. WithRecordField("Person",
  23. RecordTypeBegin().
  24. WithField("zName", TypeString).
  25. WithField("emails", ListOf(TypeString)).
  26. RecordTypeEnd()).
  27. WithField("Company", TypeString).
  28. WithRecordField("Address",
  29. RecordTypeBegin().
  30. WithField("Street", TypeString).
  31. WithField("City", TypeString).
  32. RecordTypeEnd()).
  33. RecordTypeEnd(),
  34. },
  35. want: &ParquetLevels{
  36. startColumnIndex: 0,
  37. endColumnIndex: 7,
  38. definitionDepth: 0,
  39. levels: map[string]*ParquetLevels{
  40. "Address": {
  41. startColumnIndex: 0,
  42. endColumnIndex: 2,
  43. definitionDepth: 1,
  44. levels: map[string]*ParquetLevels{
  45. "City": {
  46. startColumnIndex: 0,
  47. endColumnIndex: 1,
  48. definitionDepth: 2,
  49. },
  50. "Street": {
  51. startColumnIndex: 1,
  52. endColumnIndex: 2,
  53. definitionDepth: 2,
  54. },
  55. },
  56. },
  57. "Company": {
  58. startColumnIndex: 2,
  59. endColumnIndex: 3,
  60. definitionDepth: 1,
  61. },
  62. "CreatedAt": {
  63. startColumnIndex: 3,
  64. endColumnIndex: 4,
  65. definitionDepth: 1,
  66. },
  67. "ID": {
  68. startColumnIndex: 4,
  69. endColumnIndex: 5,
  70. definitionDepth: 1,
  71. },
  72. "Person": {
  73. startColumnIndex: 5,
  74. endColumnIndex: 7,
  75. definitionDepth: 1,
  76. levels: map[string]*ParquetLevels{
  77. "emails": {
  78. startColumnIndex: 5,
  79. endColumnIndex: 6,
  80. definitionDepth: 2,
  81. },
  82. "zName": {
  83. startColumnIndex: 6,
  84. endColumnIndex: 7,
  85. definitionDepth: 2,
  86. },
  87. },
  88. },
  89. },
  90. },
  91. },
  92. }
  93. for _, tt := range tests {
  94. t.Run(tt.name, func(t *testing.T) {
  95. got, err := ToParquetLevels(tt.args.recordType)
  96. assert.Nil(t, err)
  97. assert.Equalf(t, tt.want, got, "ToParquetLevels(%v)", tt.args.recordType)
  98. })
  99. }
  100. }