Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/clickhouse_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
CLICKHOUSE_CONNECT_TEST_FUZZ: 50
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install pip
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
runs-on: ubuntu-latest
name: PyLint
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python (3.11)
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install dependencies
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
name: Local Tests Py=${{ matrix.python-version }} CH=${{ matrix.clickhouse-version }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run ClickHouse Container
run: docker run
-d
Expand All @@ -83,7 +83,7 @@ jobs:
--ulimit nofile=262144:262144
clickhouse/clickhouse-server:${{ matrix.clickhouse-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install pip
Expand All @@ -105,13 +105,13 @@ jobs:
runs-on: ubuntu-latest
needs: tests
outputs:
has_secrets: ${{ steps.has_secrets.outputs.defined }}
has_secrets: ${{ steps.has_secrets.outputs.HAS_SECRETS }}
steps:
- id: has_secrets
env:
CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST }}
if: "${{ env.CLOUD_HOST != '' }}"
run: echo "has_secrets=true" >> $GITHUB_OUTPUT
run: echo "HAS_SECRETS=true" >> $GITHUB_OUTPUT


cloud-tests:
Expand All @@ -128,9 +128,9 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
52 changes: 26 additions & 26 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
env:
CIBW_SKIP: 'cp36-* cp37-* pp37-* *-musllinux*'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
uses: pypa/cibuildwheel@v2.16.5
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -34,10 +34,10 @@ jobs:
env:
CIBW_SKIP: 'cp36-* cp37-* pp37-* *-manylinux*'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
uses: pypa/cibuildwheel@v2.16.5
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -48,14 +48,14 @@ jobs:
CIBW_ARCHS_LINUX: aarch64
CIBW_SKIP: 'cp36-* cp37-* pp* *-musllinux*'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
uses: pypa/cibuildwheel@v2.16.5
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -66,14 +66,14 @@ jobs:
CIBW_ARCHS_LINUX: aarch64
CIBW_SKIP: 'cp36-* cp37-* pp* *-manylinux*'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
uses: pypa/cibuildwheel@v2.16.5
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -84,27 +84,27 @@ jobs:
CIBW_ARCHS_LINUX: aarch64
CIBW_BUILD: 'pp*'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
uses: pypa/cibuildwheel@v2.16.5
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

build_macos_wheels:
name: Build wheels on macos
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_ARCHS_MACOS: x86_64 arm64
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -114,10 +114,10 @@ jobs:
env:
CIBW_BUILD_VERBOSITY: 2
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
uses: pypa/cibuildwheel@v2.16.5
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -134,13 +134,13 @@ jobs:
runs-on: ubuntu-latest
if: ${{ inputs.publish_type != 'build' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build source distribution
run: |
rm -rf dist
python setup.py sdist
- name: Retrieve wheels
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: wheelhouse
- name: move and list artifacts
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ ClickHouse Connect has been included as an official Apache Superset database con
However, if you need compatibility with older versions of Superset, you may need clickhouse-connect
v0.5.25, which dynamically loads the EngineSpec from the clickhouse-connect project.

## 0.7.1, 2024-02-28
### Bug Fixes
- Changed type hint of the `query` parameter in Client `query*` methods to `Optional[str]` to work correctly with type analyzers.
This also highlights that using a query_context instead of a query in these methods is supported (and preferred for repeated queries).
Thanks to [Avery Fischer](https://github.com/biggerfisch) for the PR!
- Fixed sending a full table name to the `insert_file` tools function. Closes https://github.com/ClickHouse/clickhouse-connect/issues/305

## 0.7.0, 2024-01-22
### Breaking Change
- Python 3.7 builds are no longer part of the wheels deployed to PyPI
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_connect/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.7.0'
version = '0.7.1'
2 changes: 1 addition & 1 deletion clickhouse_connect/driver/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _prep_query(self, context: QueryContext):
final_query = super()._prep_query(context)
if context.is_insert:
return final_query
return f'{final_query}\n FORMAT {self._write_format}'
return f'{final_query}\n FORMAT {self._read_format}'

def _query_with_context(self, context: QueryContext) -> QueryResult:
headers = {}
Expand Down
7 changes: 6 additions & 1 deletion clickhouse_connect/driver/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def insert_file(client: Client,
database: Optional[str] = None,
settings: Optional[Dict[str, Any]] = None,
compression: Optional[str] = None) -> QuerySummary:
full_table = f'{quote_identifier(database)}.{quote_identifier(table)}' if database else quote_identifier(table)
if not database and table[0] not in ('`', "'") and table.find('.') > 0:
full_table = table
elif database:
full_table = f'{quote_identifier(database)}.{quote_identifier(table)}'
else:
full_table = quote_identifier(table)
if not fmt:
fmt = 'CSV' if column_names else 'CSVWithNames'
if compression is None:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def run_setup(try_c: bool = True):
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11'
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
**kwargs
)
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_db_fixture(test_config: TestConfig) -> Iterator[str]:
def test_table_engine_fixture() -> Iterator[str]:
yield 'MergeTree'


# pylint: disable=too-many-branches
@fixture(scope='session', autouse=True, name='test_client')
def test_client_fixture(test_config: TestConfig, test_db: str) -> Iterator[Client]:
Expand Down
10 changes: 6 additions & 4 deletions tests/integration_tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from clickhouse_connect.driver import Client
from clickhouse_connect.driver.tools import insert_file
from tests.integration_tests.conftest import TestConfig


def test_csv_upload(test_client: Client, table_context: Callable):
Expand All @@ -18,13 +19,14 @@ def test_csv_upload(test_client: Client, table_context: Callable):
assert res['year'] == 2022


def test_parquet_upload(test_client: Client, table_context: Callable):
def test_parquet_upload(test_config: TestConfig, test_client: Client, table_context: Callable):
data_file = f'{Path(__file__).parent}/movies.parquet'
with table_context('test_parquet_upload', ['movie String', 'year UInt16', 'rating Float64']):
insert_result = insert_file(test_client, 'test_parquet_upload', data_file, 'Parquet')
full_table = f'{test_config.test_database}.test_parquet_upload'
with table_context(full_table, ['movie String', 'year UInt16', 'rating Float64']):
insert_result = insert_file(test_client, full_table, data_file, 'Parquet')
assert 250 == insert_result.written_rows
res = test_client.query(
'SELECT count() as count, sum(rating) as rating, max(year) as year FROM test_parquet_upload').first_item
f'SELECT count() as count, sum(rating) as rating, max(year) as year FROM {full_table}').first_item
assert res['count'] == 250
assert res['year'] == 2022

Expand Down