ClickHouse/tests/queries/0_stateless/02010_lc_native.python

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

171 lines
5.2 KiB
Plaintext
Raw Normal View History

2021-09-29 14:43:35 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
2021-09-29 14:43:35 +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
from tcp_client import (
TCPClient,
CLICKHOUSE_DATABASE,
writeVarUInt,
writeStringBinary,
serializeBlockInfo,
assertPacket,
)
2021-09-29 14:43:35 +00:00
def insertValidLowCardinalityRow():
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
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')
client.send(ba)
2021-09-29 14:43:35 +00:00
# Fin block
client.sendEmptyBlock()
2021-09-29 14:43:35 +00:00
assertPacket(client.readVarUInt(), 5) # End of stream
2021-09-29 14:43:35 +00:00
def insertLowCardinalityRowWithIndexOverflow():
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
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)
client.send(ba)
2021-09-29 14:43:35 +00:00
assertPacket(client.readVarUInt(), 2) # Exception
print(client.readException())
2021-09-29 14:43:35 +00:00
def insertLowCardinalityRowWithIncorrectDictType():
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
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)
client.send(ba)
2021-09-29 14:43:35 +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
def insertLowCardinalityRowWithIncorrectAdditionalKeys():
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
),
)
# external tables
client.sendEmptyBlock()
client.readHeader()
# Data
ba = bytearray()
2023-03-23 15:33:23 +00:00
writeVarUInt(2, ba) # Data
writeStringBinary("", ba)
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')
client.send(ba)
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()
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()