avro-decode-temporal.td 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ set-arg-default default-storage-size=1
  10. # 'date' is days since the start of the UNiX epoch
  11. $ set date={"type": "record", "name": "date_field", "fields": [ { "name": "f1", "type": { "logicalType": "date", "type": "int" } } ] }
  12. $ kafka-create-topic topic=avro-decode-date
  13. $ kafka-ingest format=avro topic=avro-decode-date schema=${date} timestamp=1
  14. {"f1": -1}
  15. {"f1": 0}
  16. {"f1": 1}
  17. {"f1": 12345678}
  18. > CREATE CONNECTION kafka_conn
  19. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  20. > CREATE CLUSTER avro_decode_date_cluster SIZE '${arg.default-storage-size}';
  21. > CREATE SOURCE avro_decode_date
  22. IN CLUSTER avro_decode_date_cluster
  23. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-date-${testdrive.seed}')
  24. FORMAT AVRO USING SCHEMA '${date}'
  25. ENVELOPE NONE
  26. > SELECT * FROM avro_decode_date
  27. 1969-12-31
  28. 1970-01-01
  29. 1970-01-02
  30. +35771-04-27
  31. # Time and time-millis do not appear to be decoded to a temporal data type, see rc/avro/tests/schema.rs
  32. $ set time-millis={"type": "record", "name": "time_millis_field", "fields": [ { "name": "f1", "type": { "logicalType": "time-millis", "type": "int" } } ] }
  33. $ kafka-create-topic topic=avro-decode-time-millis
  34. $ kafka-ingest format=avro topic=avro-decode-time-millis schema=${time-millis} timestamp=1
  35. {"f1": -10}
  36. {"f1": 0}
  37. {"f1": 1}
  38. {"f1": 12345678}
  39. > CREATE CLUSTER avro_decode_time_millis_cluster SIZE '${arg.default-storage-size}';
  40. > CREATE SOURCE avro_decode_time_millis
  41. IN CLUSTER avro_decode_time_millis_cluster
  42. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-date-${testdrive.seed}')
  43. FORMAT AVRO USING SCHEMA '${time-millis}'
  44. ENVELOPE NONE
  45. > SELECT * FROM avro_decode_time_millis
  46. -1
  47. 0
  48. 1
  49. 12345678
  50. #
  51. # timestamp-millis
  52. #
  53. $ set timestamp-millis={"type": "record", "name": "timestamp_millis_field", "fields": [ { "name": "f1", "type": { "logicalType": "timestamp-millis", "type": "long" } } ] }
  54. $ kafka-create-topic topic=avro-decode-timestamp-millis
  55. $ kafka-ingest format=avro topic=avro-decode-timestamp-millis schema=${timestamp-millis} timestamp=1
  56. {"f1": 0}
  57. {"f1": 1}
  58. {"f1": 10}
  59. {"f1": 100}
  60. {"f1": 1000}
  61. {"f1": 10000}
  62. {"f1": 61000}
  63. {"f1": 1234567890}
  64. > CREATE CLUSTER avro_decode_timestamp_millis_cluster SIZE '${arg.default-storage-size}';
  65. > CREATE SOURCE avro_decode_timestamp_millis
  66. IN CLUSTER avro_decode_timestamp_millis_cluster
  67. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-timestamp-millis-${testdrive.seed}')
  68. FORMAT AVRO USING SCHEMA '${timestamp-millis}'
  69. ENVELOPE NONE
  70. > SELECT * FROM avro_decode_timestamp_millis
  71. "1970-01-01 00:00:00"
  72. "1970-01-01 00:00:00.001"
  73. "1970-01-01 00:00:00.010"
  74. "1970-01-01 00:00:00.100"
  75. "1970-01-01 00:00:01"
  76. "1970-01-01 00:00:10"
  77. "1970-01-01 00:01:01"
  78. "1970-01-15 06:56:07.890"
  79. #
  80. # timestamp-micros
  81. #
  82. $ set timestamp-micros={"type": "record", "name": "timestamp_micros_field", "fields": [ { "name": "f1", "type": { "logicalType": "timestamp-micros", "type": "long" } } ] }
  83. $ kafka-create-topic topic=avro-decode-timestamp-micros
  84. $ kafka-ingest format=avro topic=avro-decode-timestamp-micros schema=${timestamp-micros} timestamp=1
  85. {"f1": 0}
  86. {"f1": 1}
  87. {"f1": 10}
  88. {"f1": 100}
  89. {"f1": 1000}
  90. {"f1": 10000}
  91. {"f1": 61000000}
  92. {"f1": 1234567890}
  93. > CREATE CLUSTER avro_decode_timestamp_micros_cluster SIZE '${arg.default-storage-size}';
  94. > CREATE SOURCE avro_decode_timestamp_micros
  95. IN CLUSTER avro_decode_timestamp_micros_cluster
  96. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-timestamp-micros-${testdrive.seed}')
  97. FORMAT AVRO USING SCHEMA '${timestamp-micros}'
  98. ENVELOPE NONE
  99. > SELECT * FROM avro_decode_timestamp_micros
  100. "1970-01-01 00:00:00"
  101. "1970-01-01 00:00:00.000001"
  102. "1970-01-01 00:00:00.000010"
  103. "1970-01-01 00:00:00.000100"
  104. "1970-01-01 00:00:00.001"
  105. "1970-01-01 00:00:00.010"
  106. "1970-01-01 00:01:01"
  107. "1970-01-01 00:20:34.567890"
  108. #
  109. # local-timestamp-millis is not decoded to a temporal type
  110. #
  111. $ set local-timestamp-millis={"type": "record", "name": "timestamp_millis_field", "fields": [ { "name": "f1", "type": { "logicalType": "local-timestamp-millis", "type": "long" } } ] }
  112. $ kafka-create-topic topic=avro-decode-local-timestamp-millis
  113. $ kafka-ingest format=avro topic=avro-decode-local-timestamp-millis schema=${local-timestamp-millis} timestamp=1
  114. {"f1": 0}
  115. {"f1": 1}
  116. {"f1": 10}
  117. {"f1": 100}
  118. {"f1": 1000}
  119. {"f1": 10000}
  120. {"f1": 1234567890}
  121. > CREATE CLUSTER avro_decode_local_timestamp_millis_cluster SIZE '${arg.default-storage-size}';
  122. > CREATE SOURCE avro_decode_local_timestamp_millis
  123. IN CLUSTER avro_decode_local_timestamp_millis_cluster
  124. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-local-timestamp-millis-${testdrive.seed}')
  125. FORMAT AVRO USING SCHEMA '${local-timestamp-millis}'
  126. ENVELOPE NONE
  127. > SELECT * FROM avro_decode_local_timestamp_millis
  128. 0
  129. 1
  130. 10
  131. 100
  132. 1000
  133. 10000
  134. 1234567890
  135. #
  136. # duration is not tested because there is no support for "fixed"
  137. #