-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tab/fix-csv
- Loading branch information
Showing
123 changed files
with
2,200 additions
and
1,461 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,66 @@ | ||
from protobuf import user_pb2 | ||
import sys | ||
from confluent_kafka import Producer | ||
from confluent_kafka.serialization import ( | ||
SerializationContext, | ||
MessageField, | ||
) | ||
from confluent_kafka.schema_registry import SchemaRegistryClient | ||
from confluent_kafka.schema_registry.protobuf import ProtobufSerializer | ||
|
||
|
||
def delivery_report(err, msg): | ||
if err is not None: | ||
print("Delivery failed for User record {}: {}".format(msg.value(), err)) | ||
|
||
|
||
def get_user(i): | ||
return user_pb2.User( | ||
id=i, | ||
name="User_{}".format(i), | ||
address="Address_{}".format(i), | ||
city="City_{}".format(i), | ||
gender=user_pb2.MALE if i % 2 == 0 else user_pb2.FEMALE, | ||
) | ||
|
||
|
||
def send_to_kafka(producer_conf, schema_registry_conf, topic, num_records): | ||
schema_registry_client = SchemaRegistryClient(schema_registry_conf) | ||
serializer = ProtobufSerializer( | ||
user_pb2.User, | ||
schema_registry_client, | ||
{"use.deprecated.format": False}, | ||
) | ||
|
||
producer = Producer(producer_conf) | ||
for i in range(num_records): | ||
user = get_user(i) | ||
|
||
producer.produce( | ||
topic=topic, | ||
partition=0, | ||
value=serializer(user, SerializationContext(topic, MessageField.VALUE)), | ||
on_delivery=delivery_report, | ||
) | ||
producer.flush() | ||
print("Send {} records to kafka\n".format(num_records)) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 4: | ||
print("pb.py <brokerlist> <schema-registry-url> <topic> <num-records>") | ||
exit(1) | ||
|
||
broker_list = sys.argv[1] | ||
schema_registry_url = sys.argv[2] | ||
topic = sys.argv[3] | ||
num_records = int(sys.argv[4]) | ||
|
||
schema_registry_conf = {"url": schema_registry_url} | ||
producer_conf = {"bootstrap.servers": broker_list} | ||
|
||
try: | ||
send_to_kafka(producer_conf, schema_registry_conf, topic, num_records) | ||
except Exception as e: | ||
print("Send Protobuf data to schema registry and kafka failed {}", e) | ||
exit(1) |
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,36 @@ | ||
# Before running this test, seed data into kafka: | ||
# python3 e2e_test/schema_registry/pb.py | ||
|
||
# Create a table. | ||
statement ok | ||
create table sr_pb_test with ( | ||
connector = 'kafka', | ||
topic = 'sr_pb_test', | ||
properties.bootstrap.server = 'message_queue:29092', | ||
scan.startup.mode = 'earliest', | ||
message = 'test.User') | ||
FORMAT plain ENCODE protobuf( | ||
schema.registry = 'http://message_queue:8081', | ||
message = 'test.User' | ||
); | ||
|
||
# Wait for source | ||
sleep 10s | ||
|
||
# Flush into storage | ||
statement ok | ||
flush; | ||
|
||
query I | ||
select count(*) from sr_pb_test; | ||
---- | ||
20 | ||
|
||
query II | ||
select min(id), max(id) from sr_pb_test; | ||
---- | ||
0 19 | ||
|
||
|
||
statement ok | ||
drop table sr_pb_test; |
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,16 @@ | ||
syntax = "proto3"; | ||
|
||
package test; | ||
|
||
message User { | ||
int32 id = 1; | ||
string name = 2; | ||
string address = 3; | ||
string city = 4; | ||
Gender gender = 5; | ||
} | ||
|
||
enum Gender { | ||
MALE = 0; | ||
FEMALE = 1; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
Oops, something went wrong.