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.

102 lines
2.3 KiB

8 months ago
7 months ago
8 months ago
7 months ago
7 months ago
8 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. 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. }