-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(source): fix panic for
ALTER SOURCE
with schema registry (#17293)
Signed-off-by: xxchan <[email protected]>
- Loading branch information
Showing
24 changed files
with
374 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
control substitution on | ||
|
||
# https://github.com/risingwavelabs/risingwave/issues/16486 | ||
|
||
# cleanup | ||
system ok | ||
rpk topic delete 'avro_alter_source_test' || true; \\ | ||
(rpk sr subject delete 'avro_alter_source_test-value' && rpk sr subject delete 'avro_alter_source_test-value' --permanent) || true; | ||
|
||
# create topic and sr subject | ||
system ok | ||
rpk topic create 'avro_alter_source_test' | ||
|
||
system ok | ||
echo '{"type":"record","name":"Root","fields":[{"name":"foo","type":"string"}]}' | jq '{"schema": tojson}' \\ | ||
| curl -X POST -H 'content-type:application/json' -d @- '${RISEDEV_SCHEMA_REGISTRY_URL}/subjects/avro_alter_source_test-value/versions' | ||
|
||
statement ok | ||
create source s | ||
WITH ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'avro_alter_source_test' | ||
) | ||
FORMAT PLAIN ENCODE AVRO ( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}' | ||
); | ||
|
||
# create a new version of schema and produce a message | ||
system ok | ||
echo '{"type":"record","name":"Root","fields":[{"name":"bar","type":"int","default":0},{"name":"foo","type":"string"}]}' | jq '{"schema": tojson}' \\ | ||
| curl -X POST -H 'content-type:application/json' -d @- '${RISEDEV_SCHEMA_REGISTRY_URL}/subjects/avro_alter_source_test-value/versions' | ||
|
||
system ok | ||
echo '{"foo":"ABC", "bar":1}' | rpk topic produce --schema-id=topic avro_alter_source_test | ||
|
||
query ? | ||
select * from s | ||
---- | ||
ABC | ||
|
||
statement error | ||
alter source s format plain encode json; | ||
---- | ||
db error: ERROR: Failed to run the query | ||
|
||
Caused by: | ||
Feature is not yet implemented: the original definition is FORMAT Plain ENCODE Avro, and altering them is not supported yet | ||
No tracking issue yet. Feel free to submit a feature request at https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Ffeature&template=feature_request.yml | ||
|
||
|
||
statement ok | ||
alter source s format plain encode avro (schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}'); | ||
|
||
query ?? | ||
select * from s | ||
---- | ||
ABC 1 | ||
|
||
statement ok | ||
create materialized view mv as select * from s; | ||
|
||
sleep 2s | ||
|
||
query ?? | ||
select * from mv | ||
---- | ||
ABC 1 | ||
|
||
statement ok | ||
drop source s cascade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
control substitution on | ||
|
||
system ok | ||
rpk topic delete sr_pb_test || true; \\ | ||
(rpk sr subject delete 'sr_pb_test-value' && rpk sr subject delete 'sr_pb_test-value' --permanent) || true; | ||
|
||
system ok | ||
python3 e2e_test/source_inline/kafka/protobuf/pb.py "${RISEDEV_KAFKA_BOOTSTRAP_SERVERS}" "${RISEDEV_SCHEMA_REGISTRY_URL}" "sr_pb_test" 20 user | ||
|
||
statement ok | ||
CREATE SOURCE src_user | ||
INCLUDE timestamp -- include explicitly here to test a bug found in https://github.com/risingwavelabs/risingwave/pull/17293 | ||
WITH ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'sr_pb_test', | ||
scan.startup.mode = 'earliest' | ||
) | ||
FORMAT PLAIN ENCODE PROTOBUF( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}', | ||
message = 'test.User' | ||
); | ||
|
||
statement ok | ||
CREATE MATERIALIZED VIEW mv_user AS SELECT * FROM src_user; | ||
|
||
statement ok | ||
CREATE TABLE t_user WITH ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'sr_pb_test', | ||
scan.startup.mode = 'earliest' | ||
) | ||
FORMAT PLAIN ENCODE PROTOBUF( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}', | ||
message = 'test.User' | ||
); | ||
|
||
statement error | ||
SELECT age FROM mv_user; | ||
|
||
statement error | ||
SELECT age FROM t_user; | ||
|
||
# Push more events with extended fields | ||
system ok | ||
python3 e2e_test/source_inline/kafka/protobuf/pb.py "${RISEDEV_KAFKA_BOOTSTRAP_SERVERS}" "${RISEDEV_SCHEMA_REGISTRY_URL}" "sr_pb_test" 5 user_with_more_fields | ||
|
||
sleep 5s | ||
|
||
# Refresh source schema | ||
statement ok | ||
ALTER SOURCE src_user REFRESH SCHEMA; | ||
|
||
statement ok | ||
CREATE MATERIALIZED VIEW mv_user_more AS SELECT * FROM src_user; | ||
|
||
# Refresh table schema. It consume new data before refresh, so the new fields are NULLs | ||
statement ok | ||
ALTER TABLE t_user REFRESH SCHEMA; | ||
|
||
query ???? | ||
SELECT COUNT(*), MAX(age), MIN(age), SUM(age) FROM mv_user_more; | ||
---- | ||
25 104 0 510 | ||
|
||
query ???? | ||
SELECT COUNT(*), MAX(age), MIN(age), SUM(age) FROM t_user; | ||
---- | ||
25 NULL NULL NULL | ||
|
||
# Push more events with extended fields | ||
system ok | ||
python3 e2e_test/source_inline/kafka/protobuf/pb.py "${RISEDEV_KAFKA_BOOTSTRAP_SERVERS}" "${RISEDEV_SCHEMA_REGISTRY_URL}" "sr_pb_test" 5 user_with_more_fields | ||
|
||
sleep 5s | ||
|
||
query ???? | ||
SELECT COUNT(*), MAX(age), MIN(age), SUM(age) FROM t_user; | ||
---- | ||
30 104 100 510 | ||
|
||
statement ok | ||
DROP MATERIALIZED VIEW mv_user_more; | ||
|
||
statement ok | ||
DROP TABLE t_user; | ||
|
||
statement ok | ||
DROP MATERIALIZED VIEW mv_user; | ||
|
||
statement ok | ||
DROP SOURCE src_user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
control substitution on | ||
|
||
system ok | ||
rpk topic delete sr_pb_test || true; \\ | ||
(rpk sr subject delete 'sr_pb_test-value' && rpk sr subject delete 'sr_pb_test-value' --permanent) || true; | ||
|
||
system ok | ||
python3 e2e_test/source_inline/kafka/protobuf/pb.py "${RISEDEV_KAFKA_BOOTSTRAP_SERVERS}" "${RISEDEV_SCHEMA_REGISTRY_URL}" "sr_pb_test" 20 user | ||
|
||
# make sure google/protobuf/source_context.proto is NOT in schema registry | ||
system ok | ||
curl --silent '${RISEDEV_SCHEMA_REGISTRY_URL}' | grep -v 'google/protobuf/source_context.proto' | ||
|
||
# Create a table. | ||
statement ok | ||
create table sr_pb_test with ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'sr_pb_test', | ||
scan.startup.mode = 'earliest') | ||
FORMAT plain ENCODE protobuf( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}', | ||
message = 'test.User' | ||
); | ||
|
||
# for multiple schema registry nodes | ||
statement ok | ||
create table sr_pb_test_bk with ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'sr_pb_test', | ||
scan.startup.mode = 'earliest') | ||
FORMAT plain ENCODE protobuf( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL},${RISEDEV_SCHEMA_REGISTRY_URL}', | ||
message = 'test.User' | ||
); | ||
|
||
# Wait for source | ||
sleep 2s | ||
|
||
# Flush into storage | ||
statement ok | ||
flush; | ||
|
||
query I | ||
select count(*) from sr_pb_test; | ||
---- | ||
20 | ||
|
||
query IT | ||
select min(id), max(id), max((sc).file_name) from sr_pb_test; | ||
---- | ||
0 19 source/context_019.proto | ||
|
||
|
||
statement ok | ||
drop table sr_pb_test; | ||
|
||
statement ok | ||
drop table sr_pb_test_bk; |
Oops, something went wrong.