2021-09-29 14:43:35 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
2023-09-09 10:29:39 +00:00
|
|
|
import sys
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-09-09 10:29:39 +00:00
|
|
|
CURDIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
sys.path.insert(0, os.path.join(CURDIR, "helpers"))
|
2023-03-23 15:33:23 +00:00
|
|
|
|
2023-09-09 10:29:39 +00:00
|
|
|
from tcp_client import (
|
|
|
|
TCPClient,
|
|
|
|
CLICKHOUSE_DATABASE,
|
|
|
|
writeVarUInt,
|
|
|
|
writeStringBinary,
|
|
|
|
serializeBlockInfo,
|
|
|
|
assertPacket,
|
|
|
|
)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def insertValidLowCardinalityRow():
|
2023-09-09 10:29:39 +00:00
|
|
|
with TCPClient() as client:
|
|
|
|
client.sendQuery(
|
2023-03-23 15:33:23 +00:00
|
|
|
"insert into {}.tab settings input_format_defaults_for_omitted_fields=0 format TSV".format(
|
|
|
|
CLICKHOUSE_DATABASE
|
|
|
|
),
|
|
|
|
)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# external tables
|
2023-09-09 10:29:39 +00:00
|
|
|
client.sendEmptyBlock()
|
|
|
|
client.readHeader()
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# Data
|
|
|
|
ba = bytearray()
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(2, ba) # Data
|
|
|
|
writeStringBinary("", ba)
|
2021-09-29 14:43:35 +00:00
|
|
|
serializeBlockInfo(ba)
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(1, ba) # rows
|
|
|
|
writeVarUInt(1, ba) # columns
|
|
|
|
writeStringBinary("x", ba)
|
|
|
|
writeStringBinary("LowCardinality(String)", ba)
|
|
|
|
ba.extend([1] + [0] * 7) # SharedDictionariesWithAdditionalKeys
|
|
|
|
ba.extend(
|
|
|
|
[3, 2] + [0] * 6
|
|
|
|
) # indexes type: UInt64 [3], with additional keys [2]
|
|
|
|
ba.extend([1] + [0] * 7) # num_keys in dict
|
|
|
|
writeStringBinary("hello", ba) # key
|
|
|
|
ba.extend([1] + [0] * 7) # num_indexes
|
|
|
|
ba.extend([0] * 8) # UInt64 index (0 for 'hello')
|
2023-09-09 10:29:39 +00:00
|
|
|
client.send(ba)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# Fin block
|
2023-09-09 10:29:39 +00:00
|
|
|
client.sendEmptyBlock()
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-09-09 10:29:39 +00:00
|
|
|
assertPacket(client.readVarUInt(), 5) # End of stream
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def insertLowCardinalityRowWithIndexOverflow():
|
2023-09-09 10:29:39 +00:00
|
|
|
with TCPClient() as client:
|
|
|
|
client.sendQuery(
|
2023-03-23 15:33:23 +00:00
|
|
|
"insert into {}.tab settings input_format_defaults_for_omitted_fields=0 format TSV".format(
|
|
|
|
CLICKHOUSE_DATABASE
|
|
|
|
),
|
|
|
|
)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# external tables
|
2023-09-09 10:29:39 +00:00
|
|
|
client.sendEmptyBlock()
|
|
|
|
client.readHeader()
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# Data
|
|
|
|
ba = bytearray()
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(2, ba) # Data
|
|
|
|
writeStringBinary("", ba)
|
2021-09-29 14:43:35 +00:00
|
|
|
serializeBlockInfo(ba)
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(1, ba) # rows
|
|
|
|
writeVarUInt(1, ba) # columns
|
|
|
|
writeStringBinary("x", ba)
|
|
|
|
writeStringBinary("LowCardinality(String)", ba)
|
|
|
|
ba.extend([1] + [0] * 7) # SharedDictionariesWithAdditionalKeys
|
|
|
|
ba.extend(
|
|
|
|
[3, 2] + [0] * 6
|
|
|
|
) # indexes type: UInt64 [3], with additional keys [2]
|
|
|
|
ba.extend([1] + [0] * 7) # num_keys in dict
|
|
|
|
writeStringBinary("hello", ba) # key
|
|
|
|
ba.extend([1] + [0] * 7) # num_indexes
|
|
|
|
ba.extend([0] * 7 + [1]) # UInt64 index (overflow)
|
2023-09-09 10:29:39 +00:00
|
|
|
client.send(ba)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-09-09 10:29:39 +00:00
|
|
|
assertPacket(client.readVarUInt(), 2) # Exception
|
|
|
|
print(client.readException())
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def insertLowCardinalityRowWithIncorrectDictType():
|
2023-09-09 10:29:39 +00:00
|
|
|
with TCPClient() as client:
|
|
|
|
client.sendQuery(
|
2023-03-23 15:33:23 +00:00
|
|
|
"insert into {}.tab settings input_format_defaults_for_omitted_fields=0 format TSV".format(
|
|
|
|
CLICKHOUSE_DATABASE
|
|
|
|
),
|
|
|
|
)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# external tables
|
2023-09-09 10:29:39 +00:00
|
|
|
client.sendEmptyBlock()
|
|
|
|
client.readHeader()
|
2021-09-29 14:43:35 +00:00
|
|
|
|
|
|
|
# Data
|
|
|
|
ba = bytearray()
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(2, ba) # Data
|
|
|
|
writeStringBinary("", ba)
|
2021-09-29 14:43:35 +00:00
|
|
|
serializeBlockInfo(ba)
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(1, ba) # rows
|
|
|
|
writeVarUInt(1, ba) # columns
|
|
|
|
writeStringBinary("x", ba)
|
|
|
|
writeStringBinary("LowCardinality(String)", ba)
|
|
|
|
ba.extend([1] + [0] * 7) # SharedDictionariesWithAdditionalKeys
|
|
|
|
ba.extend(
|
|
|
|
[3, 3] + [0] * 6
|
|
|
|
) # indexes type: UInt64 [3], with global dict and add keys [1 + 2]
|
|
|
|
ba.extend([1] + [0] * 7) # num_keys in dict
|
|
|
|
writeStringBinary("hello", ba) # key
|
|
|
|
ba.extend([1] + [0] * 7) # num_indexes
|
|
|
|
ba.extend([0] * 8) # UInt64 index (overflow)
|
2023-09-09 10:29:39 +00:00
|
|
|
client.send(ba)
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-09-09 10:29:39 +00:00
|
|
|
assertPacket(client.readVarUInt(), 2) # Exception
|
|
|
|
print(client.readException())
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-03-23 15:33:23 +00:00
|
|
|
|
2021-11-30 14:27:15 +00:00
|
|
|
def insertLowCardinalityRowWithIncorrectAdditionalKeys():
|
2023-09-09 10:29:39 +00:00
|
|
|
with TCPClient() as client:
|
|
|
|
client.sendQuery(
|
2023-03-23 15:33:23 +00:00
|
|
|
"insert into {}.tab settings input_format_defaults_for_omitted_fields=0 format TSV".format(
|
|
|
|
CLICKHOUSE_DATABASE
|
|
|
|
),
|
|
|
|
)
|
2021-11-30 14:27:15 +00:00
|
|
|
|
|
|
|
# external tables
|
2023-09-09 10:29:39 +00:00
|
|
|
client.sendEmptyBlock()
|
|
|
|
client.readHeader()
|
2021-11-30 14:27:15 +00:00
|
|
|
|
|
|
|
# Data
|
|
|
|
ba = bytearray()
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(2, ba) # Data
|
|
|
|
writeStringBinary("", ba)
|
2021-11-30 14:27:15 +00:00
|
|
|
serializeBlockInfo(ba)
|
2023-03-23 15:33:23 +00:00
|
|
|
writeVarUInt(1, ba) # rows
|
|
|
|
writeVarUInt(1, ba) # columns
|
|
|
|
writeStringBinary("x", ba)
|
|
|
|
writeStringBinary("LowCardinality(String)", ba)
|
|
|
|
ba.extend([1] + [0] * 7) # SharedDictionariesWithAdditionalKeys
|
|
|
|
ba.extend(
|
|
|
|
[3, 0] + [0] * 6
|
|
|
|
) # indexes type: UInt64 [3], with NO additional keys [0]
|
|
|
|
ba.extend([1] + [0] * 7) # num_keys in dict
|
|
|
|
writeStringBinary("hello", ba) # key
|
|
|
|
ba.extend([1] + [0] * 7) # num_indexes
|
|
|
|
ba.extend([0] * 8) # UInt64 index (0 for 'hello')
|
2023-09-09 10:29:39 +00:00
|
|
|
client.send(ba)
|
2021-11-30 14:27:15 +00:00
|
|
|
|
2023-09-09 10:29:39 +00:00
|
|
|
assertPacket(client.readVarUInt(), 2) # Exception
|
|
|
|
print(client.readException())
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-03-23 15:33:23 +00:00
|
|
|
|
2021-09-29 14:43:35 +00:00
|
|
|
def main():
|
|
|
|
insertValidLowCardinalityRow()
|
|
|
|
insertLowCardinalityRowWithIndexOverflow()
|
|
|
|
insertLowCardinalityRowWithIncorrectDictType()
|
2021-11-30 14:27:15 +00:00
|
|
|
insertLowCardinalityRowWithIncorrectAdditionalKeys()
|
2021-09-29 14:43:35 +00:00
|
|
|
|
2023-03-23 15:33:23 +00:00
|
|
|
|
2021-09-29 14:43:35 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|