You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2 KiB

9 months ago
  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. NewRecordTypeBuilder().
  20. AddLongField("ID").
  21. AddLongField("CreatedAt").
  22. AddRecordField("Person", NewRecordTypeBuilder().
  23. AddStringField("zName").
  24. AddListField("emails", TypeString)).
  25. AddStringField("Company").
  26. AddRecordField("Address", NewRecordTypeBuilder().
  27. AddStringField("Street").
  28. AddStringField("City")).Build(),
  29. },
  30. want: &ParquetLevels{
  31. startColumnIndex: 0,
  32. endColumnIndex: 7,
  33. definitionDepth: 0,
  34. levels: map[string]*ParquetLevels{
  35. "Address": {
  36. startColumnIndex: 0,
  37. endColumnIndex: 2,
  38. definitionDepth: 1,
  39. levels: map[string]*ParquetLevels{
  40. "City": {
  41. startColumnIndex: 0,
  42. endColumnIndex: 1,
  43. definitionDepth: 2,
  44. },
  45. "Street": {
  46. startColumnIndex: 1,
  47. endColumnIndex: 2,
  48. definitionDepth: 2,
  49. },
  50. },
  51. },
  52. "Company": {
  53. startColumnIndex: 2,
  54. endColumnIndex: 3,
  55. definitionDepth: 1,
  56. },
  57. "CreatedAt": {
  58. startColumnIndex: 3,
  59. endColumnIndex: 4,
  60. definitionDepth: 1,
  61. },
  62. "ID": {
  63. startColumnIndex: 4,
  64. endColumnIndex: 5,
  65. definitionDepth: 1,
  66. },
  67. "Person": {
  68. startColumnIndex: 5,
  69. endColumnIndex: 7,
  70. definitionDepth: 1,
  71. levels: map[string]*ParquetLevels{
  72. "emails": {
  73. startColumnIndex: 5,
  74. endColumnIndex: 6,
  75. definitionDepth: 2,
  76. },
  77. "zName": {
  78. startColumnIndex: 6,
  79. endColumnIndex: 7,
  80. definitionDepth: 2,
  81. },
  82. },
  83. },
  84. },
  85. },
  86. },
  87. }
  88. for _, tt := range tests {
  89. t.Run(tt.name, func(t *testing.T) {
  90. got, err := ToParquetLevels(tt.args.recordType)
  91. assert.Nil(t, err)
  92. assert.Equalf(t, tt.want, got, "ToParquetLevels(%v)", tt.args.recordType)
  93. })
  94. }
  95. }