-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add random row count and small pr comments
- Loading branch information
1 parent
5188952
commit 669e182
Showing
4 changed files
with
135 additions
and
7 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
28 changes: 28 additions & 0 deletions
28
test/rest_request_template/test_schema_evolution_w_random_row_count.json
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,28 @@ | ||
{ | ||
"name": "SNOWFLAKE_CONNECTOR_NAME", | ||
"config": { | ||
"connector.class": "com.snowflake.kafka.connector.SnowflakeSinkConnector", | ||
"topics": "SNOWFLAKE_TEST_TOPIC0,SNOWFLAKE_TEST_TOPIC1", | ||
"snowflake.topic2table.map": "SNOWFLAKE_TEST_TOPIC0:SNOWFLAKE_CONNECTOR_NAME,SNOWFLAKE_TEST_TOPIC1:SNOWFLAKE_CONNECTOR_NAME", | ||
"tasks.max": "1", | ||
"buffer.flush.time": "60", | ||
"buffer.count.records": "300", | ||
"buffer.size.bytes": "5000000", | ||
"snowflake.url.name": "SNOWFLAKE_HOST", | ||
"snowflake.user.name": "SNOWFLAKE_USER", | ||
"snowflake.private.key": "SNOWFLAKE_PRIVATE_KEY", | ||
"snowflake.database.name": "SNOWFLAKE_DATABASE", | ||
"snowflake.schema.name": "SNOWFLAKE_SCHEMA", | ||
"snowflake.role.name": "SNOWFLAKE_ROLE", | ||
"snowflake.ingestion.method": "SNOWPIPE_STREAMING", | ||
"key.converter": "org.apache.kafka.connect.storage.StringConverter", | ||
"value.converter": "org.apache.kafka.connect.json.JsonConverter", | ||
"value.converter.schemas.enable": "false", | ||
"jmx": "true", | ||
"errors.tolerance": "all", | ||
"errors.log.enable": true, | ||
"errors.deadletterqueue.topic.name": "DLQ_TOPIC", | ||
"errors.deadletterqueue.topic.replication.factor": 1, | ||
"snowflake.enable.schematization": true | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
test/test_suit/test_schema_evolution_w_random_row_count.py
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,99 @@ | ||
import json | ||
import random | ||
|
||
from test_suit.test_utils import NonRetryableError | ||
from time import sleep | ||
|
||
|
||
# test if the ingestion works when the schematization alter table invalidation happens | ||
# halfway through a batch | ||
class TestSchemaEvolutionWithRandomRowCount: | ||
def __init__(self, driver, nameSalt): | ||
self.driver = driver | ||
self.fileName = "test_schema_evolution_w_random_row_count" | ||
self.topics = [] | ||
self.table = self.fileName + nameSalt | ||
|
||
# records | ||
self.initialRecordCount = random.randrange(1,300) | ||
self.flushRecordCount = 300 | ||
self.recordNum = self.initialRecordCount + self.flushRecordCount | ||
|
||
for i in range(2): | ||
self.topics.append(self.table + str(i)) | ||
|
||
self.records = [] | ||
|
||
self.records.append({ | ||
'PERFORMANCE_STRING': 'Excellent', | ||
'PERFORMANCE_CHAR': 'A', | ||
'RATING_INT': 100 | ||
}) | ||
|
||
self.records.append({ | ||
'PERFORMANCE_STRING': 'Excellent', | ||
'RATING_DOUBLE': 0.99, | ||
'APPROVAL': True | ||
}) | ||
|
||
self.gold_type = { | ||
'PERFORMANCE_STRING': 'VARCHAR', | ||
'PERFORMANCE_CHAR': 'VARCHAR', | ||
'RATING_INT': 'NUMBER', | ||
'RATING_DOUBLE': 'FLOAT', | ||
'APPROVAL': 'BOOLEAN', | ||
'RECORD_METADATA': 'VARIANT' | ||
} | ||
|
||
self.gold_columns = [columnName for columnName in self.gold_type] | ||
|
||
def getConfigFileName(self): | ||
return self.fileName + ".json" | ||
|
||
def send(self): | ||
print("Got random record count of {}".format(str(self.initialRecordCount))) | ||
|
||
for i, topic in enumerate(self.topics): | ||
# send initial batch | ||
key = [] | ||
value = [] | ||
for e in range(self.initialRecordCount): | ||
key.append(json.dumps({'number': str(e)}).encode('utf-8')) | ||
value.append(json.dumps(self.records[i]).encode('utf-8')) | ||
self.driver.sendBytesData(topic, value, key) | ||
|
||
# send second batch that should flush | ||
key = [] | ||
value = [] | ||
for e in range(self.flushRecordCount): | ||
key.append(json.dumps({'number': str(e)}).encode('utf-8')) | ||
value.append(json.dumps(self.records[i]).encode('utf-8')) | ||
self.driver.sendBytesData(topic, value, key) | ||
|
||
def verify(self, round): | ||
sleep(60) | ||
rows = self.driver.snowflake_conn.cursor().execute( | ||
"desc table {}".format(self.table)).fetchall() | ||
res_col = {} | ||
|
||
for index, row in enumerate(rows): | ||
self.gold_columns.remove(row[0]) | ||
if not row[1].startswith(self.gold_type[row[0]]): | ||
raise NonRetryableError("Column {} has the wrong type. got: {}, expected: {}".format(row[0], row[1], | ||
self.gold_type[ | ||
row[0]])) | ||
res_col[row[0]] = index | ||
|
||
print("Columns not in table: ", self.gold_columns) | ||
|
||
for columnName in self.gold_columns: | ||
raise NonRetryableError("Column {} was not created".format(columnName)) | ||
|
||
res = self.driver.snowflake_conn.cursor().execute( | ||
"SELECT count(*) FROM {}".format(self.table)).fetchone()[0] | ||
if res != len(self.topics) * self.recordNum: | ||
print("Number of record expected: {}, got: {}".format(len(self.topics) * self.recordNum, res)) | ||
raise NonRetryableError("Number of record in table is different from number of record sent") | ||
|
||
def clean(self): | ||
self.driver.cleanTableStagePipe(self.table) |
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