Skip to content

Commit

Permalink
add python script to generate variable-large test file
Browse files Browse the repository at this point in the history
  • Loading branch information
LetsMelon committed Jun 18, 2023
1 parent fe6008d commit 3cb1690
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
big*.tsql
34 changes: 34 additions & 0 deletions tests/files/generate_big.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import hashlib
from typing import IO

def number_to_string(number: int) -> str:
byte_representation = number.to_bytes((number.bit_length() + 7) // 8, 'big')

hash_object = hashlib.sha256(byte_representation)
hash_value = hash_object.digest()

letters = [chr((byte % 26) + ord('A')) for byte in hash_value]
hash_string = ''.join(letters)

return hash_string

def write_table(file: IO[bytes], fields: int, number: int) -> None:
datatypes = ["int", "double", "varchar(100)", "char(6)", "uuid"]

fields = [f"\t{datatypes[i % len(datatypes)]} {number_to_string(i + 100)},\n" for i in range(fields)]

lines = ["@primary_key(id)\n", f"table {number_to_string(number)} " + "{\n", "\tint id,\n" ]
lines.extend(fields)
lines.extend(["};\n"])

file.writelines(lines)

if __name__ == "__main__":
file_name = "big.tsql"

with open(file_name, "w") as file:
tables = 1_000
fields = 500

for i in range(1, tables):
write_table(file, fields, i);

0 comments on commit 3cb1690

Please sign in to comment.