avro-decode-temporal.td 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. > CREATE TABLE avro_decode_date_tbl FROM SOURCE avro_decode_date (REFERENCE "testdrive-avro-decode-date-${testdrive.seed}")
  25. FORMAT AVRO USING SCHEMA '${date}'
  26. ENVELOPE NONE
  27. > SELECT * FROM avro_decode_date_tbl
  28. 1969-12-31
  29. 1970-01-01
  30. 1970-01-02
  31. +35771-04-27
  32. # Time and time-millis do not appear to be decoded to a temporal data type, see rc/avro/tests/schema.rs
  33. $ set time-millis={"type": "record", "name": "time_millis_field", "fields": [ { "name": "f1", "type": { "logicalType": "time-millis", "type": "int" } } ] }
  34. $ kafka-create-topic topic=avro-decode-time-millis
  35. $ kafka-ingest format=avro topic=avro-decode-time-millis schema=${time-millis} timestamp=1
  36. {"f1": -10}
  37. {"f1": 0}
  38. {"f1": 1}
  39. {"f1": 12345678}
  40. > CREATE CLUSTER avro_decode_time_millis_cluster SIZE '${arg.default-storage-size}';
  41. > CREATE SOURCE avro_decode_time_millis
  42. IN CLUSTER avro_decode_time_millis_cluster
  43. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-date-${testdrive.seed}')
  44. > CREATE TABLE avro_decode_time_millis_tbl FROM SOURCE avro_decode_time_millis (REFERENCE "testdrive-avro-decode-date-${testdrive.seed}")
  45. FORMAT AVRO USING SCHEMA '${time-millis}'
  46. ENVELOPE NONE
  47. > SELECT * FROM avro_decode_time_millis_tbl
  48. -1
  49. 0
  50. 1
  51. 12345678
  52. #
  53. # timestamp-millis
  54. #
  55. $ set timestamp-millis={"type": "record", "name": "timestamp_millis_field", "fields": [ { "name": "f1", "type": { "logicalType": "timestamp-millis", "type": "long" } } ] }
  56. $ kafka-create-topic topic=avro-decode-timestamp-millis
  57. $ kafka-ingest format=avro topic=avro-decode-timestamp-millis schema=${timestamp-millis} timestamp=1
  58. {"f1": 0}
  59. {"f1": 1}
  60. {"f1": 10}
  61. {"f1": 100}
  62. {"f1": 1000}
  63. {"f1": 10000}
  64. {"f1": 61000}
  65. {"f1": 1234567890}
  66. > CREATE CLUSTER avro_decode_timestamp_millis_cluster SIZE '${arg.default-storage-size}';
  67. > CREATE SOURCE avro_decode_timestamp_millis
  68. IN CLUSTER avro_decode_timestamp_millis_cluster
  69. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-timestamp-millis-${testdrive.seed}')
  70. > CREATE TABLE avro_decode_timestamp_millis_tbl FROM SOURCE avro_decode_timestamp_millis (REFERENCE "testdrive-avro-decode-timestamp-millis-${testdrive.seed}")
  71. FORMAT AVRO USING SCHEMA '${timestamp-millis}'
  72. ENVELOPE NONE
  73. > SELECT * FROM avro_decode_timestamp_millis_tbl
  74. "1970-01-01 00:00:00"
  75. "1970-01-01 00:00:00.001"
  76. "1970-01-01 00:00:00.010"
  77. "1970-01-01 00:00:00.100"
  78. "1970-01-01 00:00:01"
  79. "1970-01-01 00:00:10"
  80. "1970-01-01 00:01:01"
  81. "1970-01-15 06:56:07.890"
  82. #
  83. # timestamp-micros
  84. #
  85. $ set timestamp-micros={"type": "record", "name": "timestamp_micros_field", "fields": [ { "name": "f1", "type": { "logicalType": "timestamp-micros", "type": "long" } } ] }
  86. $ kafka-create-topic topic=avro-decode-timestamp-micros
  87. $ kafka-ingest format=avro topic=avro-decode-timestamp-micros schema=${timestamp-micros} timestamp=1
  88. {"f1": 0}
  89. {"f1": 1}
  90. {"f1": 10}
  91. {"f1": 100}
  92. {"f1": 1000}
  93. {"f1": 10000}
  94. {"f1": 61000000}
  95. {"f1": 1234567890}
  96. > CREATE CLUSTER avro_decode_timestamp_micros_cluster SIZE '${arg.default-storage-size}';
  97. > CREATE SOURCE avro_decode_timestamp_micros
  98. IN CLUSTER avro_decode_timestamp_micros_cluster
  99. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-timestamp-micros-${testdrive.seed}')
  100. > CREATE TABLE avro_decode_timestamp_micros_tbl FROM SOURCE avro_decode_timestamp_micros (REFERENCE "testdrive-avro-decode-timestamp-micros-${testdrive.seed}")
  101. FORMAT AVRO USING SCHEMA '${timestamp-micros}'
  102. ENVELOPE NONE
  103. > SELECT * FROM avro_decode_timestamp_micros_tbl
  104. "1970-01-01 00:00:00"
  105. "1970-01-01 00:00:00.000001"
  106. "1970-01-01 00:00:00.000010"
  107. "1970-01-01 00:00:00.000100"
  108. "1970-01-01 00:00:00.001"
  109. "1970-01-01 00:00:00.010"
  110. "1970-01-01 00:01:01"
  111. "1970-01-01 00:20:34.567890"
  112. #
  113. # local-timestamp-millis is not decoded to a temporal type
  114. #
  115. $ set local-timestamp-millis={"type": "record", "name": "timestamp_millis_field", "fields": [ { "name": "f1", "type": { "logicalType": "local-timestamp-millis", "type": "long" } } ] }
  116. $ kafka-create-topic topic=avro-decode-local-timestamp-millis
  117. $ kafka-ingest format=avro topic=avro-decode-local-timestamp-millis schema=${local-timestamp-millis} timestamp=1
  118. {"f1": 0}
  119. {"f1": 1}
  120. {"f1": 10}
  121. {"f1": 100}
  122. {"f1": 1000}
  123. {"f1": 10000}
  124. {"f1": 1234567890}
  125. > CREATE CLUSTER avro_decode_local_timestamp_millis_cluster SIZE '${arg.default-storage-size}';
  126. > CREATE SOURCE avro_decode_local_timestamp_millis
  127. IN CLUSTER avro_decode_local_timestamp_millis_cluster
  128. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-avro-decode-local-timestamp-millis-${testdrive.seed}')
  129. > CREATE TABLE avro_decode_local_timestamp_millis_tbl FROM SOURCE avro_decode_local_timestamp_millis (REFERENCE "testdrive-avro-decode-local-timestamp-millis-${testdrive.seed}")
  130. FORMAT AVRO USING SCHEMA '${local-timestamp-millis}'
  131. ENVELOPE NONE
  132. > SELECT * FROM avro_decode_local_timestamp_millis_tbl
  133. 0
  134. 1
  135. 10
  136. 100
  137. 1000
  138. 10000
  139. 1234567890
  140. #
  141. # duration is not tested because there is no support for "fixed"
  142. #