diff --git a/.github/renovate.json b/.github/renovate.json index 3a3dbe6073ded..a2e3a325fad75 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -46,7 +46,7 @@ "addLabels": ["bigquery"] }, { - "matchPackagePatterns": ["duckdb", "duckdb-engine"], + "matchPackagePatterns": ["duckdb"], "addLabels": ["duckdb"] }, { diff --git a/.github/workflows/ibis-backends-skip-helper.yml b/.github/workflows/ibis-backends-skip-helper.yml index 56969fc7c2fba..1432f14864d4f 100644 --- a/.github/workflows/ibis-backends-skip-helper.yml +++ b/.github/workflows/ibis-backends-skip-helper.yml @@ -13,7 +13,7 @@ on: branches: - master - "*.x.x" - - "!the-epic-split" + - the-epic-split pull_request: paths: - "docs/**" @@ -24,7 +24,7 @@ on: branches: - master - "*.x.x" - - "!the-epic-split" + - the-epic-split merge_group: jobs: test_backends: diff --git a/.github/workflows/ibis-backends.yml b/.github/workflows/ibis-backends.yml index 0f60b5289a0c3..b5308e713fc9e 100644 --- a/.github/workflows/ibis-backends.yml +++ b/.github/workflows/ibis-backends.yml @@ -12,7 +12,7 @@ on: branches: - master - "*.x.x" - - "!the-epic-split" + - the-epic-split pull_request: # Skip the backend suite if all changes are docs paths-ignore: @@ -24,7 +24,7 @@ on: branches: - master - "*.x.x" - - "!the-epic-split" + - the-epic-split merge_group: permissions: @@ -55,139 +55,140 @@ jobs: - "3.9" - "3.11" backend: - - name: dask - title: Dask - extras: - - dask - name: duckdb title: DuckDB extras: - duckdb - deltalake - geospatial + - decompiler additional_deps: - torch - - name: pandas - title: Pandas - extras: - - pandas - - name: sqlite - title: SQLite - extras: - - sqlite - - name: datafusion - title: Datafusion - extras: - - datafusion - - name: polars - title: Polars - extras: - - polars - - deltalake - - name: mysql - title: MySQL - services: - - mysql - extras: - - mysql - - geospatial - sys-deps: - - libgeos-dev - name: clickhouse title: ClickHouse services: - clickhouse extras: - clickhouse - - name: postgres - title: PostgreSQL - extras: - - postgres - - geospatial - services: - - postgres - sys-deps: - - libgeos-dev - - name: postgres - title: PostgreSQL + Torch - extras: - - postgres - - geospatial - additional_deps: - - torch - services: - - postgres - sys-deps: - - libgeos-dev - - name: impala - title: Impala - extras: - - impala - services: - - impala - - kudu - sys-deps: - - cmake - - ninja-build - - name: mssql - title: MS SQL Server - extras: - - mssql - services: - - mssql - sys-deps: - - freetds-dev - - unixodbc-dev - - tdsodbc - - name: trino - title: Trino - extras: - - trino - - postgres - services: - - trino - - name: druid - title: Druid - extras: - - druid - services: - - druid - - name: oracle - title: Oracle - serial: true - extras: - - oracle - services: - - oracle - - name: exasol - title: Exasol - serial: true - extras: - - exasol - services: - - exasol - - name: flink - title: Flink - serial: true - extras: - - flink - additional_deps: - - apache-flink - - pytest-split - services: - - flink + # - name: dask + # title: Dask + # extras: + # - dask + # - name: pandas + # title: Pandas + # extras: + # - pandas + # - name: sqlite + # title: SQLite + # extras: + # - sqlite + # - name: datafusion + # title: Datafusion + # extras: + # - datafusion + # - name: polars + # title: Polars + # extras: + # - polars + # - deltalake + # - name: mysql + # title: MySQL + # services: + # - mysql + # extras: + # - mysql + # - geospatial + # sys-deps: + # - libgeos-dev + # - name: postgres + # title: PostgreSQL + # extras: + # - postgres + # - geospatial + # services: + # - postgres + # sys-deps: + # - libgeos-dev + # - name: postgres + # title: PostgreSQL + Torch + # extras: + # - postgres + # - geospatial + # additional_deps: + # - torch + # services: + # - postgres + # sys-deps: + # - libgeos-dev + # - name: impala + # title: Impala + # extras: + # - impala + # services: + # - impala + # - kudu + # sys-deps: + # - cmake + # - ninja-build + # - name: mssql + # title: MS SQL Server + # extras: + # - mssql + # services: + # - mssql + # sys-deps: + # - freetds-dev + # - unixodbc-dev + # - tdsodbc + # - name: trino + # title: Trino + # extras: + # - trino + # - postgres + # services: + # - trino + # - name: druid + # title: Druid + # extras: + # - druid + # services: + # - druid + # - name: oracle + # title: Oracle + # serial: true + # extras: + # - oracle + # services: + # - oracle + # - name: exasol + # title: Exasol + # serial: true + # extras: + # - exasol + # services: + # - exasol + # - name: flink + # title: Flink + # serial: true + # extras: + # - flink + # additional_deps: + # - apache-flink + # - pytest-split + # services: + # - flink exclude: - - os: windows-latest - backend: - name: mysql - title: MySQL - extras: - - mysql - - geospatial - services: - - mysql - sys-deps: - - libgeos-dev + # - os: windows-latest + # backend: + # name: mysql + # title: MySQL + # extras: + # - mysql + # - geospatial + # services: + # - mysql + # sys-deps: + # - libgeos-dev - os: windows-latest backend: name: clickhouse @@ -196,115 +197,115 @@ jobs: - clickhouse services: - clickhouse - - os: windows-latest - backend: - name: postgres - title: PostgreSQL - extras: - - postgres - - geospatial - services: - - postgres - sys-deps: - - libgeos-dev - - os: windows-latest - backend: - name: postgres - title: PostgreSQL + Torch - extras: - - postgres - - geospatial - additional_deps: - - torch - services: - - postgres - sys-deps: - - libgeos-dev - - os: windows-latest - backend: - name: impala - title: Impala - extras: - - impala - services: - - impala - - kudu - sys-deps: - - cmake - - ninja-build - - os: windows-latest - backend: - name: mssql - title: MS SQL Server - extras: - - mssql - services: - - mssql - sys-deps: - - freetds-dev - - unixodbc-dev - - tdsodbc - - os: windows-latest - backend: - name: trino - title: Trino - services: - - trino - extras: - - trino - - postgres - - os: windows-latest - backend: - name: druid - title: Druid - extras: - - druid - services: - - druid - - os: windows-latest - backend: - name: oracle - title: Oracle - serial: true - extras: - - oracle - services: - - oracle - - os: windows-latest - backend: - name: flink - title: Flink - serial: true - extras: - - flink - services: - - flink - - python-version: "3.11" - backend: - name: flink - title: Flink - serial: true - extras: - - flink - services: - - flink - - os: windows-latest - backend: - name: exasol - title: Exasol - serial: true - extras: - - exasol - services: - - exasol + # - os: windows-latest + # backend: + # name: postgres + # title: PostgreSQL + # extras: + # - postgres + # - geospatial + # services: + # - postgres + # sys-deps: + # - libgeos-dev + # - os: windows-latest + # backend: + # name: postgres + # title: PostgreSQL + Torch + # extras: + # - postgres + # - geospatial + # additional_deps: + # - torch + # services: + # - postgres + # sys-deps: + # - libgeos-dev + # - os: windows-latest + # backend: + # name: impala + # title: Impala + # extras: + # - impala + # services: + # - impala + # - kudu + # sys-deps: + # - cmake + # - ninja-build + # - os: windows-latest + # backend: + # name: mssql + # title: MS SQL Server + # extras: + # - mssql + # services: + # - mssql + # sys-deps: + # - freetds-dev + # - unixodbc-dev + # - tdsodbc + # - os: windows-latest + # backend: + # name: trino + # title: Trino + # services: + # - trino + # extras: + # - trino + # - postgres + # - os: windows-latest + # backend: + # name: druid + # title: Druid + # extras: + # - druid + # services: + # - druid + # - os: windows-latest + # backend: + # name: oracle + # title: Oracle + # serial: true + # extras: + # - oracle + # services: + # - oracle + # - os: windows-latest + # backend: + # name: flink + # title: Flink + # serial: true + # extras: + # - flink + # services: + # - flink + # - python-version: "3.11" + # backend: + # name: flink + # title: Flink + # serial: true + # extras: + # - flink + # services: + # - flink + # - os: windows-latest + # backend: + # name: exasol + # title: Exasol + # serial: true + # extras: + # - exasol + # services: + # - exasol steps: - - name: update and install system dependencies - if: matrix.os == 'ubuntu-latest' && matrix.backend.sys-deps != null - run: | - set -euo pipefail - - sudo apt-get update -qq -y - sudo apt-get install -qq -y build-essential ${{ join(matrix.backend.sys-deps, ' ') }} + # - name: update and install system dependencies + # if: matrix.os == 'ubuntu-latest' && matrix.backend.sys-deps != null + # run: | + # set -euo pipefail + # + # sudo apt-get update -qq -y + # sudo apt-get install -qq -y build-essential ${{ join(matrix.backend.sys-deps, ' ') }} - name: install sqlite if: matrix.os == 'windows-latest' && matrix.backend.name == 'sqlite' @@ -358,7 +359,7 @@ jobs: run: poetry run pip list - name: "run parallel tests: ${{ matrix.backend.name }}" - if: ${{ !matrix.backend.serial }} + if: true # ${{ !matrix.backend.serial }} run: just ci-check -m ${{ matrix.backend.name }} --numprocesses auto --dist=loadgroup env: IBIS_TEST_IMPALA_HOST: localhost @@ -369,21 +370,21 @@ jobs: # executes before common tests, they will fail with: # org.apache.flink.table.api.ValidationException: Table `default_catalog`.`default_database`.`functional_alltypes` was not found. # Therefore, we run backend-specific tests second to avoid this. - - name: "run serial tests: ${{ matrix.backend.name }}" - if: matrix.backend.serial && matrix.backend.name == 'flink' - run: | - just ci-check -m ${{ matrix.backend.name }} ibis/backends/tests - just ci-check -m ${{ matrix.backend.name }} ibis/backends/flink/tests - env: - IBIS_EXAMPLES_DATA: ${{ runner.temp }}/examples-${{ matrix.backend.name }}-${{ matrix.os }}-${{ steps.install_python.outputs.python-version }} - FLINK_REMOTE_CLUSTER_ADDR: localhost - FLINK_REMOTE_CLUSTER_PORT: "8081" - - - name: "run serial tests: ${{ matrix.backend.name }}" - if: matrix.backend.serial && matrix.backend.name != 'flink' - run: just ci-check -m ${{ matrix.backend.name }} - env: - IBIS_EXAMPLES_DATA: ${{ runner.temp }}/examples-${{ matrix.backend.name }}-${{ matrix.os }}-${{ steps.install_python.outputs.python-version }} + # - name: "run serial tests: ${{ matrix.backend.name }}" + # if: matrix.backend.serial && matrix.backend.name == 'flink' + # run: | + # just ci-check -m ${{ matrix.backend.name }} ibis/backends/tests + # just ci-check -m ${{ matrix.backend.name }} ibis/backends/flink/tests + # env: + # IBIS_EXAMPLES_DATA: ${{ runner.temp }}/examples-${{ matrix.backend.name }}-${{ matrix.os }}-${{ steps.install_python.outputs.python-version }} + # FLINK_REMOTE_CLUSTER_ADDR: localhost + # FLINK_REMOTE_CLUSTER_PORT: "8081" + # + # - name: "run serial tests: ${{ matrix.backend.name }}" + # if: matrix.backend.serial && matrix.backend.name != 'flink' + # run: just ci-check -m ${{ matrix.backend.name }} + # env: + # IBIS_EXAMPLES_DATA: ${{ runner.temp }}/examples-${{ matrix.backend.name }}-${{ matrix.os }}-${{ steps.install_python.outputs.python-version }} - name: check that no untracked files were produced shell: bash @@ -399,380 +400,390 @@ jobs: if: matrix.backend.services != null && failure() run: docker compose logs - test_backends_min_version: - name: ${{ matrix.backend.title }} Min Version ${{ matrix.os }} python-${{ matrix.python-version }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - windows-latest - python-version: - - "3.9" - - "3.11" - backend: - - name: dask - title: Dask - deps: - - "dask[array,dataframe]@2022.9.1" - - "pandas@1.5.3" - extras: - - dask - - name: postgres - title: PostgreSQL - deps: - - "psycopg2@2.8.4" - - "GeoAlchemy2@0.6.3" - - "geopandas@0.6" - - "Shapely@2" - services: - - postgres - extras: - - postgres - - geospatial - exclude: - - os: windows-latest - backend: - name: postgres - title: PostgreSQL - deps: - - "psycopg2@2.8.4" - - "GeoAlchemy2@0.6.3" - - "geopandas@0.6" - - "Shapely@2" - services: - - postgres - extras: - - postgres - - geospatial - - python-version: "3.11" - backend: - name: postgres - title: PostgreSQL - deps: - - "psycopg2@2.8.4" - - "GeoAlchemy2@0.6.3" - - "geopandas@0.6" - - "Shapely@2" - services: - - postgres - extras: - - postgres - - geospatial - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: install libgeos for shapely - if: matrix.backend.name == 'postgres' - run: | - sudo apt-get update -y -qq - sudo apt-get install -qq -y build-essential libgeos-dev - - - uses: extractions/setup-just@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: download backend data - run: just download-data - - - name: start services - if: matrix.backend.services != null - run: docker compose up --wait ${{ join(matrix.backend.services, ' ') }} - - - name: install python - uses: actions/setup-python@v5 - id: install_python - with: - python-version: ${{ matrix.python-version }} - - - name: install poetry - run: python -m pip install --upgrade pip 'poetry==1.7.1' - - - name: remove lonboard - # it requires a version of pandas that min versions are not compatible with - run: poetry remove lonboard - - - name: install minimum versions - run: poetry add --lock --optional ${{ join(matrix.backend.deps, ' ') }} - - - name: checkout the lock file - run: git checkout poetry.lock - - - name: lock with no updates - # poetry add is aggressive and will update other dependencies like - # numpy and pandas so we keep the pyproject.toml edits and then relock - # without updating anything except the requested versions - run: poetry lock --no-update - - - name: install ibis - run: poetry install --without dev --without docs --extras "${{ join(matrix.backend.extras, ' ') }}" - - - name: run tests - run: just ci-check -m ${{ matrix.backend.name }} --numprocesses auto --dist=loadgroup - - - name: check that no untracked files were produced - shell: bash - run: git checkout poetry.lock pyproject.toml && ! git status --porcelain | tee /dev/stderr | grep . - - - name: upload code coverage - if: success() - uses: codecov/codecov-action@v3 - with: - flags: backend,${{ matrix.backend.name }},${{ runner.os }},python-${{ steps.install_python.outputs.python-version }} - - - name: Show docker compose logs on fail - if: matrix.backend.services != null && failure() - run: docker compose logs - - test_pyspark: - name: PySpark ${{ matrix.os }} python-${{ matrix.python-version }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - python-version: - - "3.10" - steps: - - name: checkout - uses: actions/checkout@v4 - - - uses: actions/setup-java@v4 - with: - distribution: microsoft - java-version: 17 - - - uses: extractions/setup-just@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: download backend data - run: just download-data - - - name: install python - uses: actions/setup-python@v5 - id: install_python - with: - python-version: ${{ matrix.python-version }} - - - name: install poetry - run: python -m pip install --upgrade pip 'poetry==1.7.1' - - - name: remove lonboard - # it requires a version of pandas that pyspark is not compatible with - run: poetry remove lonboard - - - name: install maximum versions of pandas and numpy - run: poetry add --lock 'pandas@<2' 'numpy<1.24' - - - name: checkout the lock file - run: git checkout poetry.lock - - - name: lock with no updates - # poetry add is aggressive and will update other dependencies like - # numpy and pandas so we keep the pyproject.toml edits and then relock - # without updating anything except the requested versions - run: poetry lock --no-update - - - name: install ibis - run: poetry install --without dev --without docs --extras pyspark - - - name: run tests - run: just ci-check -m pyspark - - - name: check that no untracked files were produced - shell: bash - run: git checkout poetry.lock pyproject.toml && ! git status --porcelain | tee /dev/stderr | grep . - - - name: upload code coverage - # only upload coverage for jobs that aren't mostly xfails - if: success() && matrix.python-version != '3.11' - uses: codecov/codecov-action@v3 - with: - flags: backend,pyspark,${{ runner.os }},python-${{ steps.install_python.outputs.python-version }} - - gen_lockfile_sqlalchemy2: - name: Generate Poetry Lockfile for SQLAlchemy 2 - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: install python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - run: python -m pip install --upgrade pip 'poetry==1.7.1' - - - name: remove deps that are not compatible with sqlalchemy 2 - run: poetry remove snowflake-sqlalchemy sqlalchemy-exasol - - - name: add sqlalchemy 2 - run: poetry add --lock --optional 'sqlalchemy>=2,<3' - - - name: checkout the lock file - run: git checkout poetry.lock - - - name: lock with no updates - # poetry add is aggressive and will update other dependencies like - # numpy and pandas so we keep the pyproject.toml edits and then relock - # without updating anything except the requested versions - run: poetry lock --no-update - - - name: check the sqlalchemy version - run: poetry show sqlalchemy --no-ansi | grep version | cut -d ':' -f2- | sed 's/ //g' | grep -P '^2\.' - - - name: upload deps file - uses: actions/upload-artifact@v3 - with: - name: deps - path: | - pyproject.toml - poetry.lock - - test_backends_sqlalchemy2: - name: SQLAlchemy 2 ${{ matrix.backend.title }} ${{ matrix.os }} python-${{ matrix.python-version }} - runs-on: ${{ matrix.os }} - needs: - - gen_lockfile_sqlalchemy2 - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - python-version: - - "3.11" - backend: - - name: mssql - title: MS SQL Server - services: - - mssql - extras: - - mssql - sys-deps: - - freetds-dev - - unixodbc-dev - - tdsodbc - - name: mysql - title: MySQL - services: - - mysql - extras: - - geospatial - - mysql - - name: postgres - title: PostgreSQL - services: - - postgres - extras: - - geospatial - - postgres - sys-deps: - - libgeos-dev - - name: sqlite - title: SQLite - extras: - - sqlite - - name: trino - title: Trino - services: - - trino - extras: - - trino - - postgres - - name: duckdb - title: DuckDB - extras: - - duckdb - - name: oracle - title: Oracle - serial: true - extras: - - oracle - services: - - oracle - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: update and install system dependencies - if: matrix.backend.sys-deps != null - run: | - set -euo pipefail - - sudo apt-get update -qq -y - sudo apt-get install -qq -y build-essential ${{ join(matrix.backend.sys-deps, ' ') }} - - - uses: extractions/setup-just@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: download backend data - run: just download-data - - - name: start services - if: matrix.backend.services != null - run: docker compose up --wait ${{ join(matrix.backend.services, ' ') }} - - - name: install python - uses: actions/setup-python@v5 - id: install_python - with: - python-version: ${{ matrix.python-version }} - - - name: download poetry lockfile - uses: actions/download-artifact@v3 - with: - name: deps - path: deps - - - name: pull out lockfile - run: | - set -euo pipefail - - mv -f deps/* . - rm -r deps - - - uses: syphar/restore-virtualenv@v1 - with: - requirement_files: poetry.lock - custom_cache_key_element: ${{ matrix.backend.name }}-${{ steps.install_python.outputs.python-version }} - - - uses: syphar/restore-pip-download-cache@v1 - with: - requirement_files: poetry.lock - custom_cache_key_element: ${{ steps.install_python.outputs.python-version }} - - - name: install poetry - run: python -m pip install --upgrade pip 'poetry==1.7.1' - - - name: install ibis - run: poetry install --without dev --without docs --extras "${{ join(matrix.backend.extras, ' ') }}" - - - name: run tests - run: just ci-check -m ${{ matrix.backend.name }} --numprocesses auto --dist=loadgroup - - - name: check that no untracked files were produced - shell: bash - run: git checkout poetry.lock pyproject.toml && ! git status --porcelain | tee /dev/stderr | grep . - - - name: upload code coverage - if: success() - uses: codecov/codecov-action@v3 - with: - flags: backend,${{ matrix.backend.name }},${{ runner.os }},python-${{ steps.install_python.outputs.python-version }} + # test_backends_min_version: + # name: ${{ matrix.backend.title }} Min Version ${{ matrix.os }} python-${{ matrix.python-version }} + # runs-on: ${{ matrix.os }} + # env: + # SQLALCHEMY_WARN_20: "1" + # strategy: + # fail-fast: false + # matrix: + # os: + # - ubuntu-latest + # - windows-latest + # python-version: + # - "3.9" + # - "3.11" + # backend: + # - name: dask + # title: Dask + # deps: + # - "dask[array,dataframe]@2022.9.1" + # - "pandas@1.5.3" + # extras: + # - dask + # - name: postgres + # title: PostgreSQL + # deps: + # - "psycopg2@2.8.4" + # - "GeoAlchemy2@0.6.3" + # - "geopandas@0.6" + # - "Shapely@2" + # services: + # - postgres + # extras: + # - postgres + # - geospatial + # exclude: + # - os: windows-latest + # backend: + # name: postgres + # title: PostgreSQL + # deps: + # - "psycopg2@2.8.4" + # - "GeoAlchemy2@0.6.3" + # - "geopandas@0.6" + # - "Shapely@2" + # services: + # - postgres + # extras: + # - postgres + # - geospatial + # - python-version: "3.11" + # backend: + # name: postgres + # title: PostgreSQL + # deps: + # - "psycopg2@2.8.4" + # - "GeoAlchemy2@0.6.3" + # - "geopandas@0.6" + # - "Shapely@2" + # services: + # - postgres + # extras: + # - postgres + # - geospatial + # steps: + # - name: checkout + # uses: actions/checkout@v4 + # + # - name: install libgeos for shapely + # if: matrix.backend.name == 'postgres' + # run: | + # sudo apt-get update -y -qq + # sudo apt-get install -qq -y build-essential libgeos-dev + # + # - uses: extractions/setup-just@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: download backend data + # run: just download-data + # + # - name: start services + # if: matrix.backend.services != null + # run: docker compose up --wait ${{ join(matrix.backend.services, ' ') }} + # + # - name: install python + # uses: actions/setup-python@v5 + # id: install_python + # with: + # python-version: ${{ matrix.python-version }} + # + # - name: install poetry + # run: python -m pip install --upgrade pip 'poetry==1.7.1' + # + # - name: remove lonboard + # # it requires a version of pandas that min versions are not compatible with + # run: poetry remove lonboard + # + # - name: install minimum versions + # run: poetry add --lock --optional ${{ join(matrix.backend.deps, ' ') }} + # + # - name: checkout the lock file + # run: git checkout poetry.lock + # + # - name: lock with no updates + # # poetry add is aggressive and will update other dependencies like + # # numpy and pandas so we keep the pyproject.toml edits and then relock + # # without updating anything except the requested versions + # run: poetry lock --no-update + # + # - name: install ibis + # run: poetry install --without dev --without docs --extras "${{ join(matrix.backend.extras, ' ') }}" + # + # - name: run tests + # run: just ci-check -m ${{ matrix.backend.name }} --numprocesses auto --dist=loadgroup + # + # - name: check that no untracked files were produced + # shell: bash + # run: git checkout poetry.lock pyproject.toml && ! git status --porcelain | tee /dev/stderr | grep . + # + # - name: upload code coverage + # if: success() + # uses: codecov/codecov-action@v3 + # with: + # flags: backend,${{ matrix.backend.name }},${{ runner.os }},python-${{ steps.install_python.outputs.python-version }} + # + # - name: Show docker compose logs on fail + # if: matrix.backend.services != null && failure() + # run: docker compose logs + + # test_pyspark: + # name: PySpark ${{ matrix.os }} python-${{ matrix.python-version }} + # runs-on: ${{ matrix.os }} + # strategy: + # fail-fast: false + # matrix: + # os: + # - ubuntu-latest + # python-version: + # - "3.10" + # steps: + # - name: checkout + # uses: actions/checkout@v4 + # + # - uses: actions/setup-java@v4 + # with: + # distribution: microsoft + # java-version: 17 + # + # - uses: extractions/setup-just@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: download backend data + # run: just download-data + # + # - name: install python + # uses: actions/setup-python@v5 + # id: install_python + # with: + # python-version: ${{ matrix.python-version }} + # + # - name: install poetry + # run: python -m pip install --upgrade pip 'poetry==1.7.1' + # + # - name: remove lonboard + # # it requires a version of pandas that pyspark is not compatible with + # run: poetry remove lonboard + # + # - name: install maximum versions of pandas and numpy + # run: poetry add --lock 'pandas@<2' 'numpy<1.24' + # + # - name: checkout the lock file + # run: git checkout poetry.lock + # + # - name: lock with no updates + # # poetry add is aggressive and will update other dependencies like + # # numpy and pandas so we keep the pyproject.toml edits and then relock + # # without updating anything except the requested versions + # run: poetry lock --no-update + # + # - name: install ibis + # run: poetry install --without dev --without docs --extras pyspark + # + # - name: run tests + # run: just ci-check -m pyspark + # + # - name: check that no untracked files were produced + # shell: bash + # run: git checkout poetry.lock pyproject.toml && ! git status --porcelain | tee /dev/stderr | grep . + # + # - name: upload code coverage + # # only upload coverage for jobs that aren't mostly xfails + # if: success() && matrix.python-version != '3.11' + # uses: codecov/codecov-action@v3 + # with: + # flags: backend,pyspark,${{ runner.os }},python-${{ steps.install_python.outputs.python-version }} + + # gen_lockfile_sqlalchemy2: + # name: Generate Poetry Lockfile for SQLAlchemy 2 + # runs-on: ubuntu-latest + # steps: + # - name: checkout + # uses: actions/checkout@v4 + # + # - name: install python + # uses: actions/setup-python@v5 + # with: + # python-version: "3.11" + # + # - run: python -m pip install --upgrade pip 'poetry==1.7.1' + # + # - name: remove deps that are not compatible with sqlalchemy 2 + # run: poetry remove snowflake-sqlalchemy sqlalchemy-exasol + # + # - name: add sqlalchemy 2 + # run: poetry add --lock --optional 'sqlalchemy>=2,<3' + # + # - name: checkout the lock file + # run: git checkout poetry.lock + # + # - name: lock with no updates + # # poetry add is aggressive and will update other dependencies like + # # numpy and pandas so we keep the pyproject.toml edits and then relock + # # without updating anything except the requested versions + # run: poetry lock --no-update + # + # - name: check the sqlalchemy version + # run: poetry show sqlalchemy --no-ansi | grep version | cut -d ':' -f2- | sed 's/ //g' | grep -P '^2\.' + # + # - name: upload deps file + # uses: actions/upload-artifact@v3 + # with: + # name: deps + # path: | + # pyproject.toml + # poetry.lock + + # test_backends_sqlalchemy2: + # name: SQLAlchemy 2 ${{ matrix.backend.title }} ${{ matrix.os }} python-${{ matrix.python-version }} + # runs-on: ${{ matrix.os }} + # needs: + # - gen_lockfile_sqlalchemy2 + # env: + # ODBCSYSINI: "${{ github.workspace }}/.odbc" + # strategy: + # fail-fast: false + # matrix: + # os: + # - ubuntu-latest + # python-version: + # - "3.11" + # backend: + # - name: mssql + # title: MS SQL Server + # services: + # - mssql + # extras: + # - mssql + # sys-deps: + # - freetds-dev + # - unixodbc-dev + # - tdsodbc + # - name: mysql + # title: MySQL + # services: + # - mysql + # extras: + # - geospatial + # - mysql + # - name: postgres + # title: PostgreSQL + # services: + # - postgres + # extras: + # - geospatial + # - postgres + # sys-deps: + # - libgeos-dev + # - name: sqlite + # title: SQLite + # extras: + # - sqlite + # - name: trino + # title: Trino + # services: + # - trino + # extras: + # - trino + # - postgres + # - name: oracle + # title: Oracle + # serial: true + # extras: + # - oracle + # services: + # - oracle + # steps: + # - name: checkout + # uses: actions/checkout@v4 + # + # - name: update and install system dependencies + # if: matrix.backend.sys-deps != null + # run: | + # set -euo pipefail + # + # sudo apt-get update -qq -y + # sudo apt-get install -qq -y build-essential ${{ join(matrix.backend.sys-deps, ' ') }} + # + # - name: setup odbc for mssql + # if: ${{ matrix.backend.name == 'mssql' }} + # run: | + # mkdir -p "$ODBCSYSINI" + # + # { + # echo '[FreeTDS]' + # echo "Driver = libtdsodbc.so" + # } > "$ODBCSYSINI/odbcinst.ini" + # + # - uses: extractions/setup-just@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: download backend data + # run: just download-data + # + # - name: start services + # if: matrix.backend.services != null + # run: docker compose up --wait ${{ join(matrix.backend.services, ' ') }} + # + # - name: install python + # uses: actions/setup-python@v5 + # id: install_python + # with: + # python-version: ${{ matrix.python-version }} + # + # - name: download poetry lockfile + # uses: actions/download-artifact@v3 + # with: + # name: deps + # path: deps + # + # - name: pull out lockfile + # run: | + # set -euo pipefail + # + # mv -f deps/* . + # rm -r deps + # + # - uses: syphar/restore-virtualenv@v1 + # with: + # requirement_files: poetry.lock + # custom_cache_key_element: ${{ matrix.backend.name }}-${{ steps.install_python.outputs.python-version }} + # + # - uses: syphar/restore-pip-download-cache@v1 + # with: + # requirement_files: poetry.lock + # custom_cache_key_element: ${{ steps.install_python.outputs.python-version }} + # + # - name: install poetry + # run: python -m pip install --upgrade pip 'poetry==1.7.1' + # + # - name: install ibis + # run: poetry install --without dev --without docs --extras "${{ join(matrix.backend.extras, ' ') }}" + # + # - name: run tests + # run: just ci-check -m ${{ matrix.backend.name }} --numprocesses auto --dist=loadgroup + # + # - name: check that no untracked files were produced + # shell: bash + # run: git checkout poetry.lock pyproject.toml && ! git status --porcelain | tee /dev/stderr | grep . + # + # - name: upload code coverage + # if: success() + # uses: codecov/codecov-action@v3 + # with: + # flags: backend,${{ matrix.backend.name }},${{ runner.os }},python-${{ steps.install_python.outputs.python-version }} backends: # this job exists so that we can use a single job from this workflow to gate merging runs-on: ubuntu-latest needs: - - test_backends_min_version + # - test_backends_min_version - test_backends - - test_backends_sqlalchemy2 - - test_pyspark + # - test_backends_sqlalchemy2 + # - test_pyspark steps: - run: exit 0 diff --git a/.github/workflows/ibis-main.yml b/.github/workflows/ibis-main.yml index 50a9482f1785a..2b135914d72eb 100644 --- a/.github/workflows/ibis-main.yml +++ b/.github/workflows/ibis-main.yml @@ -94,12 +94,13 @@ jobs: - name: run all core tests and run benchmarks once parallel if: matrix.os != 'windows-latest' - # TODO(kszucs): restore "just ci-check -m "'core or benchmark'" -n auto" - run: poetry run pytest -v -n auto ibis/common ibis/expr ibis/tests ibis/formats + # TODO(cpcloud): bring back benchmarks smoke tests -m 'core or benchmarks' + run: just ci-check -m core --numprocesses auto - name: run all core tests and run benchmarks once serial if: matrix.os == 'windows-latest' - run: poetry run pytest -v ibis/common ibis/expr ibis/tests ibis/formats + # TODO(cpcloud): bring back benchmarks smoke tests -m 'core or benchmarks' + run: just ci-check -m core - name: upload code coverage if: success() diff --git a/ibis/backends/base/__init__.py b/ibis/backends/base/__init__.py index a5a0cd0d2106e..7190d831ba684 100644 --- a/ibis/backends/base/__init__.py +++ b/ibis/backends/base/__init__.py @@ -31,7 +31,6 @@ import pyarrow as pa import torch - __all__ = ("BaseBackend", "Database", "connect") _IBIS_TO_SQLGLOT_DIALECT = { @@ -1217,9 +1216,9 @@ def _cached(self, expr: ir.Table): if (result := self._query_cache.get(op)) is None: self._query_cache.store(expr) result = self._query_cache[op] - return ir.CachedTableExpr(result) + return ir.CachedTable(result) - def _release_cached(self, expr: ir.CachedTableExpr) -> None: + def _release_cached(self, expr: ir.CachedTable) -> None: """Releases the provided cached expression. Parameters diff --git a/ibis/backends/base/df/timecontext.py b/ibis/backends/base/df/timecontext.py index a04f905ce0c53..f84dd473bc4c4 100644 --- a/ibis/backends/base/df/timecontext.py +++ b/ibis/backends/base/df/timecontext.py @@ -265,19 +265,19 @@ def adjust_context_alias( return adjust_context(op.arg, scope, timecontext) -# @adjust_context.register(ops.AsOfJoin) -# def adjust_context_asof_join( -# op: ops.AsOfJoin, scope: Scope, timecontext: TimeContext -# ) -> TimeContext: -# begin, end = timecontext +@adjust_context.register(ops.AsOfJoin) +def adjust_context_asof_join( + op: ops.AsOfJoin, scope: Scope, timecontext: TimeContext +) -> TimeContext: + begin, end = timecontext -# if op.tolerance is not None: -# from ibis.backends.pandas.execution import execute + if op.tolerance is not None: + from ibis.backends.pandas.execution import execute -# timedelta = execute(op.tolerance) -# return (begin - timedelta, end) + timedelta = execute(op.tolerance) + return (begin - timedelta, end) -# return timecontext + return timecontext @adjust_context.register(ops.WindowFunction) diff --git a/ibis/backends/base/sql/alchemy/registry.py b/ibis/backends/base/sql/alchemy/registry.py index 5ff058f72c8ce..baa5d5fe287e8 100644 --- a/ibis/backends/base/sql/alchemy/registry.py +++ b/ibis/backends/base/sql/alchemy/registry.py @@ -605,7 +605,7 @@ class array_filter(FunctionElement): ops.Coalesce: varargs(sa.func.coalesce), ops.NullIf: fixed_arity(sa.func.nullif, 2), ops.InValues: _in_values, - ops.InColumn: _in_column, + ops.InSubquery: _in_column, ops.Count: reduction(sa.func.count), ops.CountStar: _count_star, ops.CountDistinctStar: _count_distinct_star, diff --git a/ibis/backends/base/sql/compiler/query_builder.py b/ibis/backends/base/sql/compiler/query_builder.py index 50bd21eb62aea..4376e03b4a55f 100644 --- a/ibis/backends/base/sql/compiler/query_builder.py +++ b/ibis/backends/base/sql/compiler/query_builder.py @@ -23,16 +23,6 @@ class TableSetFormatter: - _join_names = { - ops.InnerJoin: "INNER JOIN", - ops.LeftJoin: "LEFT OUTER JOIN", - ops.RightJoin: "RIGHT OUTER JOIN", - ops.OuterJoin: "FULL OUTER JOIN", - ops.LeftAntiJoin: "LEFT ANTI JOIN", - ops.LeftSemiJoin: "LEFT SEMI JOIN", - ops.CrossJoin: "CROSS JOIN", - } - def __init__(self, parent, node, indent=2): # `parent` is a `Select` instance, not a `TableSetFormatter` self.parent = parent diff --git a/ibis/backends/base/sql/compiler/select_builder.py b/ibis/backends/base/sql/compiler/select_builder.py index 41abc75b4a339..f1f9b73cc984e 100644 --- a/ibis/backends/base/sql/compiler/select_builder.py +++ b/ibis/backends/base/sql/compiler/select_builder.py @@ -86,9 +86,9 @@ def _populate_context(self): def _make_table_aliases(self, node): ctx = self.context - if isinstance(node, ops.Join): + if isinstance(node, ops.JoinChain): for arg in node.args: - if isinstance(arg, ops.TableNode): + if isinstance(arg, ops.Relation): self._make_table_aliases(arg) elif not ctx.is_extracted(node): ctx.make_alias(node) @@ -112,7 +112,7 @@ def _collect_elements(self): if isinstance(self.op, ops.DummyTable): self.select_set = list(self.op.values) - elif isinstance(self.op, ops.TableNode): + elif isinstance(self.op, ops.Relation): self._collect(self.op, toplevel=True) else: self.select_set = [self.op] @@ -125,7 +125,7 @@ def _collect(self, op, toplevel=False): f(op, toplevel=toplevel) elif isinstance(op, (ops.PhysicalTable, ops.SQLQueryResult)): self._collect_PhysicalTable(op, toplevel=toplevel) - elif isinstance(op, ops.Join): + elif isinstance(op, ops.JoinChain): self._collect_Join(op, toplevel=toplevel) elif isinstance(op, ops.WindowingTVF): self._collect_WindowingTVF(op, toplevel=toplevel) @@ -140,7 +140,7 @@ def _collect_Distinct(self, op, toplevel=False): def _collect_Limit(self, op, toplevel=False): if toplevel: - if isinstance(table := op.table, ops.Limit): + if isinstance(table := op.parent, ops.Limit): self.table_set = table self.select_set = [table] else: @@ -184,27 +184,18 @@ def _collect_Aggregation(self, op, toplevel=False): self._collect(op.table) - def _collect_Selection(self, op, toplevel=False): - table = op.table + def _collect_Project(self, op, toplevel=False): + table = op.parent if toplevel: - if isinstance(table, ops.Join): + if isinstance(table, ops.JoinChain): self._collect_Join(table) else: self._collect(table) - selections = op.selections - sort_keys = op.sort_keys - filters = op.predicates - - if not selections: - # select * - selections = [table] - - self.order_by = sort_keys - self.select_set = selections + selections = op.values + self.select_set = list(selections.values()) self.table_set = table - self.filters = filters def _collect_InMemoryTable(self, node, toplevel=False): if toplevel: diff --git a/ibis/backends/base/sql/registry/main.py b/ibis/backends/base/sql/registry/main.py index 8a2d8bcbb5b92..91bf90f29707e 100644 --- a/ibis/backends/base/sql/registry/main.py +++ b/ibis/backends/base/sql/registry/main.py @@ -355,7 +355,7 @@ def _floor(t, op): ops.IfElse: fixed_arity("if", 3), ops.Between: between, ops.InValues: binary_infix.in_values, - ops.InColumn: binary_infix.in_column, + ops.InSubquery: binary_infix.in_column, ops.SimpleCase: case.simple_case, ops.SearchedCase: case.searched_case, ops.Field: table_column, diff --git a/ibis/backends/base/sqlglot/__init__.py b/ibis/backends/base/sqlglot/__init__.py index 50cb23ec9a71c..f8cc80e5c76fa 100644 --- a/ibis/backends/base/sqlglot/__init__.py +++ b/ibis/backends/base/sqlglot/__init__.py @@ -32,11 +32,6 @@ def has_operation(cls, operation: type[ops.Value]) -> bool: dispatcher = cls.compiler.visit_node.register.__self__.dispatcher return dispatcher.dispatch(operation) is not dispatcher.dispatch(object) - def _transform( - self, sql: sge.Expression, table_expr: ir.TableExpr - ) -> sge.Expression: - return sql - def table( self, name: str, schema: str | None = None, database: str | None = None ) -> ir.Table: @@ -85,17 +80,16 @@ def _to_sqlglot( sql = sg.select(STAR).from_(sql) assert not isinstance(sql, sge.Subquery) - return [self._transform(sql, table_expr)] + return sql def compile( self, expr: ir.Expr, limit: str | None = None, params=None, **kwargs: Any ): - """Compile an Ibis expression to a ClickHouse SQL string.""" - queries = self._to_sqlglot(expr, limit=limit, params=params, **kwargs) - - return ";\n\n".join( - query.sql(dialect=self.name, pretty=True) for query in queries - ) + """Compile an Ibis expression to a SQL string.""" + query = self._to_sqlglot(expr, limit=limit, params=params, **kwargs) + sql = query.sql(dialect=self.name, pretty=True) + self._log(sql) + return sql def _to_sql(self, expr: ir.Expr, **kwargs) -> str: return self.compile(expr, **kwargs) @@ -221,10 +215,9 @@ def execute( sql = self.compile(table, limit=limit, **kwargs) schema = table.schema() - self._log(sql) with self._safe_raw_sql(sql) as cur: - result = self.fetch_from_cursor(cur, schema) + result = self._fetch_from_cursor(cur, schema) return expr.__pandas_result__(result) def drop_table( diff --git a/ibis/backends/base/sqlglot/compiler.py b/ibis/backends/base/sqlglot/compiler.py index cc3eabd09cf33..e9bb79997e840 100644 --- a/ibis/backends/base/sqlglot/compiler.py +++ b/ibis/backends/base/sqlglot/compiler.py @@ -7,21 +7,28 @@ import math import operator import string -from collections.abc import Mapping +from collections.abc import Iterator, Mapping from functools import partial, singledispatchmethod +from itertools import starmap from typing import TYPE_CHECKING, Any, Callable import sqlglot as sg import sqlglot.expressions as sge +import toolz from public import public import ibis.common.exceptions as com import ibis.expr.datatypes as dt import ibis.expr.operations as ops from ibis.backends.base.sqlglot.rewrites import Select, Window, sqlize -from ibis.common.deferred import _ -from ibis.common.patterns import replace -from ibis.expr.analysis import p, x +from ibis.expr.rewrites import ( + add_one_to_nth_value_input, + add_order_by_to_empty_ranking_window_functions, + empty_in_values_right_side, + one_to_zero_index, + replace_scalar_parameter, + unwrap_scalar_parameter, +) if TYPE_CHECKING: import ibis.expr.schema as sch @@ -97,43 +104,6 @@ def parenthesize(op, arg): STAR = sge.Star() -@replace(p.InValues(..., ())) -def empty_in_values_right_side(_): - """Replace checks against an empty right side with `False`.""" - return ops.Literal(False, dtype=dt.bool) - - -@replace( - p.WindowFunction( - p.PercentRank(x) | p.RankBase(x) | p.CumeDist(x) | p.NTile(x), - p.WindowFrame(..., order_by=()) >> _.copy(order_by=(x,)), - ) -) -def add_order_by_to_empty_ranking_window_functions(_): - """Add an ORDER BY clause to rank window functions that don't have one.""" - return _ - - -@replace( - p.WindowFunction(p.RankBase | p.NTile) - | p.StringFind - | p.FindInSet - | p.ArrayPosition -) -def one_to_zero_index(_, **__): - """Subtract one from one-index functions.""" - return ops.Subtract(_, 1) - - -@replace(ops.NthValue) -def add_one_to_nth_value_input(_, **__): - if isinstance(_.nth, ops.Literal): - nth = ops.Literal(_.nth.value + 1, dtype=_.nth.dtype) - else: - nth = ops.Add(_.nth, 1) - return _.copy(nth=nth) - - @public class SQLGlotCompiler(abc.ABC): __slots__ = "agg", "f" @@ -244,16 +214,18 @@ def fn(node, _, **kwargs): # substitute parameters immediately to avoid having to define a # ScalarParameter translation rule # - # this lets us avoid threading `params` through every `translate_val` call - # only to be used in the one place it would be needed: the ScalarParameter - # `translate_val` rule - params = {param.op(): value for param, value in (params or {}).items()} - replace_literals = p.ScalarParameter >> ( - lambda _: ops.Literal(value=params[_], dtype=_.dtype) - ) + # this lets us avoid threading `params` through every `translate_val` + # call only to be used in the one place it would be needed: the + # ScalarParameter `translate_val` rule + params = { + # remove aliases from scalar parameters + param.op().replace(unwrap_scalar_parameter): value + for param, value in (params or {}).items() + } op = op.replace( - replace_literals | functools.reduce(operator.or_, self.rewrites) + replace_scalar_parameter(params) + | functools.reduce(operator.or_, self.rewrites) ) op = sqlize(op) # apply translate rules in topological order @@ -279,7 +251,7 @@ def visit_ScalarSubquery(self, op, *, rel): @visit_node.register(ops.Alias) def visit_Alias(self, op, *, arg, name): - return arg.as_(self._gen_valid_name(name), quoted=self.quoted) + return arg @visit_node.register(ops.Literal) def visit_Literal(self, op, *, value, dtype, **kw): @@ -422,19 +394,9 @@ def visit_Negate(self, op, *, arg): @visit_node.register(ops.Not) def visit_Not(self, op, *, arg): if isinstance(arg, sge.Filter): - return sge.Filter( - this=self._de_morgan_law(arg.this), expression=arg.expression - ) # transform the not expression using _de_morgan_law + return sge.Filter(this=sg.not_(arg.this), expression=arg.expression) return sg.not_(paren(arg)) - @staticmethod - def _de_morgan_law(logical_op: sge.Expression): - if isinstance(logical_op, sge.LogicalAnd): - return sge.LogicalOr(this=sg.not_(paren(logical_op.this))) - if isinstance(logical_op, sge.LogicalOr): - return sge.LogicalAnd(this=sg.not_(paren(logical_op.this))) - return None - ### Timey McTimeFace @visit_node.register(ops.Date) @@ -535,7 +497,7 @@ def visit_DayOfWeekName(self, op, *, arg): # Saturday == 6 return sge.Case( this=(self.f.dayofweek(arg) + 6) % 7, - ifs=list(itertools.starmap(self.if_, enumerate(calendar.day_name))), + ifs=list(starmap(self.if_, enumerate(calendar.day_name))), ) @visit_node.register(ops.IntervalFromInteger) @@ -648,7 +610,8 @@ def visit_Sum(self, op, *, arg, where): @visit_node.register(ops.Quantile) @visit_node.register(ops.MultiQuantile) def visit_Quantile(self, op, *, arg, quantile, where): - return self.agg.quantile_cont(arg, quantile, where=where) + suffix = "cont" if op.arg.dtype.is_numeric() else "disc" + return self.agg[f"quantile_{suffix}"](arg, quantile, where=where) @visit_node.register(ops.Variance) @visit_node.register(ops.StandardDev) @@ -688,11 +651,11 @@ def visit_SimpleCase(self, op, *, base=None, cases, results, default): @visit_node.register(ops.ExistsSubquery) def visit_ExistsSubquery(self, op, *, rel): - return self.f.exists(rel.this.subquery()) + return self.f.exists(rel.this) @visit_node.register(ops.InSubquery) def visit_InSubquery(self, op, *, rel, needle): - return needle.isin(rel.this.subquery()) + return needle.isin(rel.this) @visit_node.register(ops.ArrayColumn) def visit_ArrayColumn(self, op, *, cols): @@ -709,8 +672,7 @@ def visit_StructColumn(self, op, *, names, values): @visit_node.register(ops.StructField) def visit_StructField(self, op, *, arg, field): - val = arg.this if isinstance(op.arg, ops.Alias) else arg - return val[sge.convert(field)] + return arg[sge.convert(field)] @visit_node.register(ops.IdenticalTo) def visit_IdenticalTo(self, op, *, left, right): @@ -790,7 +752,7 @@ def visit_LagLead(self, op, *, arg, offset, default): @visit_node.register(ops.Argument) def visit_Argument(self, op, *, name: str, shape, dtype): - return sg.to_identifier(name) + return sg.to_identifier(op.param) @visit_node.register(ops.RowID) def visit_RowID(self, op, *, table): @@ -831,6 +793,15 @@ def visit_ArrayContains(self, op, *, arg, other): ## relations + def _dedup_name( + self, key: str, value: sge.Expression + ) -> Iterator[sge.Alias | sge.Column]: + return ( + value.as_(key, quoted=self.quoted) + if not isinstance(value, sge.Column) or key != value.name + else value + ) + @visit_node.register(Select) def visit_Select(self, op, *, parent, selections, predicates, sort_keys): # if we've constructed a useless projection return the parent relation @@ -840,9 +811,9 @@ def visit_Select(self, op, *, parent, selections, predicates, sort_keys): result = parent if selections: - result = sg.select( - *(sel.as_(name, quoted=self.quoted) for name, sel in selections.items()) - ).from_(result) + result = sg.select(*starmap(self._dedup_name, selections.items())).from_( + result + ) if predicates: result = result.where(*predicates) @@ -854,9 +825,7 @@ def visit_Select(self, op, *, parent, selections, predicates, sort_keys): @visit_node.register(ops.DummyTable) def visit_DummyTable(self, op, *, values): - return sg.select( - *(value.as_(key, quoted=self.quoted) for key, value in values.items()) - ) + return sg.select(*starmap(self._dedup_name, values.items())) @visit_node.register(ops.UnboundTable) def visit_UnboundTable(self, op, *, name: str, schema: sch.Schema): @@ -874,13 +843,11 @@ def visit_DatabaseTable(self, op, *, name, namespace, schema, source): @visit_node.register(ops.SelfReference) def visit_SelfReference(self, op, *, parent, identifier): - return parent.as_(op.name, quoted=self.quoted) + return parent @visit_node.register(ops.JoinChain) def visit_JoinChain(self, op, *, first, rest, values): - result = sg.select( - *(value.as_(key, quoted=self.quoted) for key, value in values.items()) - ).from_(first) + result = sg.select(*starmap(self._dedup_name, values.items())).from_(first) for link in rest: if isinstance(link, sge.Alias): @@ -914,6 +881,7 @@ def visit_JoinLink(self, op, *, how, table, predicates): "cross": "cross", "outer": "outer", } + assert predicates return sge.Join( this=table, side=sides[how], kind=kinds[how], on=sg.and_(*predicates) ) @@ -926,12 +894,7 @@ def _gen_valid_name(name: str) -> str: def visit_Project(self, op, *, parent, values): # needs_alias should never be true here in explicitly, but it may get # passed via a (recursive) call to translate_val - return sg.select( - *( - value.as_(self._gen_valid_name(key), quoted=self.quoted) - for key, value in values.items() - ) - ).from_(parent) + return sg.select(*starmap(self._dedup_name, values.items())).from_(parent) @staticmethod def _generate_groups(groups): @@ -940,13 +903,11 @@ def _generate_groups(groups): @visit_node.register(ops.Aggregate) def visit_Aggregate(self, op, *, parent, groups, metrics): sel = sg.select( - *( - value.as_(self._gen_valid_name(key), quoted=self.quoted) - for key, value in groups.items() + *starmap( + self._dedup_name, toolz.keymap(self._gen_valid_name, groups).items() ), - *( - value.as_(self._gen_valid_name(key), quoted=self.quoted) - for key, value in metrics.items() + *starmap( + self._dedup_name, toolz.keymap(self._gen_valid_name, metrics).items() ), ).from_(parent) @@ -1134,6 +1095,18 @@ def visit_SQLQueryResult(self, op, *, query, schema, source): def visit_Unnest(self, op, *, arg): return sge.Explode(this=arg) + @visit_node.register(ops.RegexSplit) + def visit_RegexSplit(self, op, *, arg, pattern): + return sge.RegexpSplit(this=arg, expression=pattern) + + @visit_node.register(ops.Levenshtein) + def visit_Levenshtein(self, op, *, left, right): + return sge.Levenshtein(this=left, expression=right) + + @visit_node.register(ops.JoinTable) + def visit_JoinTable(self, op, *, parent, index): + return parent + _SIMPLE_OPS = { ops.All: "bool_and", diff --git a/ibis/backends/base/sqlglot/datatypes.py b/ibis/backends/base/sqlglot/datatypes.py index 1fdd90ebb61c0..326f20315cf1f 100644 --- a/ibis/backends/base/sqlglot/datatypes.py +++ b/ibis/backends/base/sqlglot/datatypes.py @@ -408,6 +408,13 @@ def _from_sqlglot_TIMESTAMP_MS(cls) -> dt.Timestamp: def _from_sqlglot_TIMESTAMP_NS(cls) -> dt.Timestamp: return dt.Timestamp(scale=9, nullable=cls.default_nullable) + @classmethod + def _from_ibis_GeoSpatial(cls, dtype: dt.GeoSpatial): + assert ( + dtype.geotype == "geometry" + ), "DuckDB only supports geometry types; geography types are not supported" + return sge.DataType(this=typecode.GEOMETRY) + class TrinoType(SqlglotType): dialect = "trino" @@ -433,5 +440,26 @@ class OracleType(SqlglotType): dialect = "oracle" +class SnowflakeType(SqlglotType): + dialect = "snowflake" + default_temporal_scale = 9 + + @classmethod + def _from_sqlglot_FLOAT(cls) -> dt.Float64: + return dt.Float64(nullable=cls.default_nullable) + + @classmethod + def _from_sqlglot_DECIMAL(cls, precision=None, scale=None) -> dt.Decimal: + if scale is None or int(scale.this.this) == 0: + return dt.Int64(nullable=cls.default_nullable) + else: + return super()._from_sqlglot_DECIMAL(precision, scale) + + @classmethod + def _from_sqlglot_ARRAY(cls, value_type=None) -> dt.Array: + assert value_type is None + return dt.Array(dt.json, nullable=cls.default_nullable) + + class SQLiteType(SqlglotType): dialect = "sqlite" diff --git a/ibis/backends/base/sqlglot/rewrites.py b/ibis/backends/base/sqlglot/rewrites.py index 37c32e0385300..ca999208aa393 100644 --- a/ibis/backends/base/sqlglot/rewrites.py +++ b/ibis/backends/base/sqlglot/rewrites.py @@ -3,9 +3,9 @@ from __future__ import annotations -import os from typing import Literal, Optional +import toolz from public import public import ibis.expr.datashape as ds @@ -115,14 +115,11 @@ def merge_select_select(_): return Select( _.parent.parent, selections=selections, - predicates=_.parent.predicates + predicates, - sort_keys=_.parent.sort_keys + sort_keys, + predicates=tuple(toolz.unique(_.parent.predicates + predicates)), + sort_keys=tuple(toolz.unique(_.parent.sort_keys + sort_keys)), ) -DEBUG = os.environ.get("IBIS_SQL_DEBUG", False) - - def sqlize(node): """Lower the ibis expression graph to a SQL-like relational algebra.""" step1 = node.replace( @@ -131,11 +128,5 @@ def sqlize(node): | filter_to_select | sort_to_select ) - if DEBUG: - print("--------- STEP 1 ---------") - print(step1.to_expr()) step2 = step1.replace(merge_select_select) - if DEBUG: - print("--------- STEP 2 ---------") - print(step2.to_expr()) return step2 diff --git a/ibis/backends/clickhouse/__init__.py b/ibis/backends/clickhouse/__init__.py index 9668f47ca49f6..746d35f41cc92 100644 --- a/ibis/backends/clickhouse/__init__.py +++ b/ibis/backends/clickhouse/__init__.py @@ -7,11 +7,11 @@ from contextlib import closing from functools import partial from typing import TYPE_CHECKING, Any, Literal +from urllib.parse import parse_qs, urlparse import clickhouse_connect as cc import pyarrow as pa import pyarrow_hotfix # noqa: F401 -import sqlalchemy as sa import sqlglot as sg import sqlglot.expressions as sge import toolz @@ -26,7 +26,7 @@ from ibis import util from ibis.backends.base import BaseBackend, CanCreateDatabase from ibis.backends.base.sqlglot import SQLGlotBackend -from ibis.backends.base.sqlglot.compiler import C, F +from ibis.backends.base.sqlglot.compiler import C from ibis.backends.clickhouse.compiler import ClickHouseCompiler from ibis.backends.clickhouse.datatypes import ClickhouseType @@ -74,21 +74,28 @@ def _from_url(self, url: str, **kwargs) -> BaseBackend: BaseBackend A backend instance """ - url = sa.engine.make_url(url) - - kwargs = toolz.merge( - { - name: value - for name in ("host", "port", "database", "password") - if (value := getattr(url, name, None)) - }, - kwargs, - ) - if username := url.username: - kwargs["user"] = username - - kwargs.update(url.query) + url = urlparse(url) + database = url.path[1:] + query_params = parse_qs(url.query) + + connect_args = { + "user": url.username, + "password": url.password or "", + "host": url.hostname, + "database": database or "", + } + + for name, value in query_params.items(): + if len(value) > 1: + connect_args[name] = value + elif len(value) == 1: + connect_args[name] = value[0] + else: + raise com.IbisError(f"Invalid URL parameter: {name}") + + kwargs.update(connect_args) self._convert_kwargs(kwargs) + return self.connect(**kwargs) def _convert_kwargs(self, kwargs): @@ -172,7 +179,7 @@ def _safe_raw_sql(self, *args, **kwargs): @property def current_database(self) -> str: - with self._safe_raw_sql(sg.select(F.currentDatabase())) as result: + with self._safe_raw_sql(sg.select(self.compiler.f.currentDatabase())) as result: [(db,)] = result.result_rows return db @@ -194,7 +201,7 @@ def list_tables( query = sg.select(C.name).from_(sg.table("tables", db="system")) if database is None: - database = F.currentDatabase() + database = self.compiler.f.currentDatabase() else: database = sge.convert(database) @@ -681,7 +688,7 @@ def create_table( expression = None if obj is not None: - (expression,) = self._to_sqlglot(obj) + expression = self._to_sqlglot(obj) external_tables.update(self._collect_in_memory_tables(obj)) code = sge.Create( @@ -708,7 +715,7 @@ def create_view( database: str | None = None, overwrite: bool = False, ) -> ir.Table: - (expression,) = self._to_sqlglot(obj) + expression = self._to_sqlglot(obj) src = sge.Create( this=sg.table(name, db=database), kind="VIEW", diff --git a/ibis/backends/clickhouse/compiler.py b/ibis/backends/clickhouse/compiler.py index 56496271c5139..7d04c531d77f3 100644 --- a/ibis/backends/clickhouse/compiler.py +++ b/ibis/backends/clickhouse/compiler.py @@ -6,6 +6,7 @@ from typing import Any import sqlglot as sg +import sqlglot.expressions as sge from sqlglot import exp from sqlglot.dialects import ClickHouse from sqlglot.dialects.dialect import rename_func @@ -79,7 +80,7 @@ def visit_ArrayIndex(self, op, *, arg, index): @visit_node.register(ops.ArrayRepeat) def visit_ArrayRepeat(self, op, *, arg, times): param = sg.to_identifier("_") - func = sg.exp.Lambda(this=arg, expressions=[param]) + func = sge.Lambda(this=arg, expressions=[param]) return self.f.arrayFlatten(self.f.arrayMap(func, self.f.range(times))) @visit_node.register(ops.ArraySlice) @@ -107,7 +108,7 @@ def visit_ArraySlice(self, op, *, arg, start, stop): def visit_CountStar(self, op, *, where, arg): if where is not None: return self.f.countIf(where) - return sg.exp.Count(this=STAR) + return sge.Count(this=STAR) @visit_node.register(ops.Quantile) @visit_node.register(ops.MultiQuantile) @@ -116,7 +117,7 @@ def visit_QuantileMultiQuantile(self, op, *, arg, quantile, where): return self.agg.quantile(arg, quantile, where=where) func = "quantile" + "s" * isinstance(op, ops.MultiQuantile) - return sg.exp.ParameterizedAgg( + return sge.ParameterizedAgg( this=f"{func}If", expressions=util.promote_list(quantile), params=[arg, where], @@ -162,7 +163,7 @@ def visit_StringFind(self, op, *, arg, substr, start, end): @visit_node.register(ops.RegexSearch) def visit_RegexSearch(self, op, *, arg, pattern): - return sg.exp.RegexpLike(this=arg, expression=pattern) + return sge.RegexpLike(this=arg, expression=pattern) @visit_node.register(ops.RegexExtract) def visit_RegexExtract(self, op, *, arg, pattern, index): @@ -230,7 +231,7 @@ def visit_Literal(self, op, *, value, dtype, **kw): v = str(value) return self.f.toIPv6(v) if ":" in v else self.f.toIPv4(v) elif dtype.is_string(): - return sg.exp.convert(str(value).replace(r"\0", r"\\0")) + return sge.convert(str(value).replace(r"\0", r"\\0")) elif dtype.is_decimal(): precision = dtype.precision if precision is None or not 1 <= precision <= 76: @@ -249,26 +250,26 @@ def visit_Literal(self, op, *, value, dtype, **kw): return type_name(value, dtype.scale) elif dtype.is_numeric(): if not math.isfinite(value): - return sg.exp.Literal.number(str(value)) - return sg.exp.convert(value) + return sge.Literal.number(str(value)) + return sge.convert(value) elif dtype.is_interval(): if dtype.unit.short in ("ms", "us", "ns"): raise com.UnsupportedOperationError( "Clickhouse doesn't support subsecond interval resolutions" ) - return sg.exp.Interval( - this=sg.exp.convert(str(value)), unit=dtype.resolution.upper() + return sge.Interval( + this=sge.convert(str(value)), unit=dtype.resolution.upper() ) elif dtype.is_timestamp(): - funcname = "toDateTime" - fmt = "%Y-%m-%dT%H:%M:%S" + funcname = "parseDateTime" if micros := value.microsecond: funcname += "64" - fmt += ".%f" - args = [value.strftime(fmt)] + funcname += "BestEffort" + + args = [value.isoformat()] if micros % 1000: args.append(6) @@ -280,7 +281,33 @@ def visit_Literal(self, op, *, value, dtype, **kw): return self.f[funcname](*args) elif dtype.is_date(): - return self.f.toDate(value.strftime("%Y-%m-%d")) + return self.f.toDate(value.isoformat()) + elif dtype.is_array(): + value_type = dtype.value_type + values = [ + self.visit_Literal( + ops.Literal(v, dtype=value_type), value=v, dtype=value_type, **kw + ) + for v in value + ] + return self.f.array(*values) + elif dtype.is_map(): + value_type = dtype.value_type + keys = [] + values = [] + + for k, v in value.items(): + keys.append(sge.convert(k)) + values.append( + self.visit_Literal( + ops.Literal(v, dtype=value_type), + value=v, + dtype=value_type, + **kw, + ) + ) + + return self.f.map(self.f.array(*keys), self.f.array(*values)) elif dtype.is_struct(): fields = [ self.visit_Literal( @@ -407,9 +434,7 @@ def visit_Clip(self, op, *, arg, lower, upper): def visit_StructField(self, op, *, arg, field: str): arg_dtype = op.arg.dtype idx = arg_dtype.names.index(field) - return self.cast( - sg.exp.Dot(this=arg, expression=sg.exp.convert(idx + 1)), op.dtype - ) + return self.cast(sge.Dot(this=arg, expression=sge.convert(idx + 1)), op.dtype) @visit_node.register(ops.Repeat) def visit_Repeat(self, op, *, arg, times): @@ -440,10 +465,10 @@ def visit_DayOfWeekName(self, op, *, arg): base = ( ((self.f.toDayOfWeek(arg) - 1) % num_weekdays) + num_weekdays ) % num_weekdays - return sg.exp.Case( + return sge.Case( this=base, ifs=list(map(self.if_, *zip(*enumerate(days)))), - default=sg.exp.convert(""), + default=sge.convert(""), ) @visit_node.register(ops.Map) @@ -541,19 +566,19 @@ def visit_ArrayStringJoin(self, op, *, arg, sep): @visit_node.register(ops.ArrayMap) def visit_ArrayMap(self, op, *, arg, param, body): - func = sg.exp.Lambda(this=body, expressions=[param]) + func = sge.Lambda(this=body, expressions=[param]) return self.f.arrayMap(func, arg) @visit_node.register(ops.ArrayFilter) def visit_ArrayFilter(self, op, *, arg, param, body): - func = sg.exp.Lambda(this=body, expressions=[param]) + func = sge.Lambda(this=body, expressions=[param]) return self.f.arrayFilter(func, arg) @visit_node.register(ops.ArrayRemove) def visit_ArrayRemove(self, op, *, arg, other): x = sg.to_identifier("x") body = x.neq(other) - return self.f.arrayFilter(sg.exp.Lambda(this=body, expressions=[x]), arg) + return self.f.arrayFilter(sge.Lambda(this=body, expressions=[x]), arg) @visit_node.register(ops.ArrayUnion) def visit_ArrayUnion(self, op, *, left, right): @@ -578,6 +603,35 @@ def visit_CountDistinctStar( else: return self.f.countDistinct(columns) + @visit_node.register(ops.TimestampRange) + def visit_TimestampRange(self, op, *, start, stop, step): + unit = op.step.dtype.unit.name.lower() + + if not isinstance(op.step, ops.Literal): + raise com.UnsupportedOperationError( + "ClickHouse doesn't support non-literal step values" + ) + + step_value = op.step.value + + offset = sg.to_identifier("offset") + + func = sge.Lambda( + this=self.f.dateAdd(sg.to_identifier(unit), offset, start), + expressions=[offset], + ) + + if step_value == 0: + return self.f.array() + + return self.f.arrayMap( + func, self.f.range(0, self.f.timestampDiff(unit, start, stop), step_value) + ) + + @visit_node.register(ops.RegexSplit) + def visit_RegexSplit(self, op, *, arg, pattern): + return self.f.splitByRegexp(pattern, self.cast(arg, dt.String(nullable=False))) + @staticmethod def _generate_groups(groups): return groups @@ -588,6 +642,7 @@ def _generate_groups(groups): @visit_node.register(ops.Time) @visit_node.register(ops.TimeDelta) @visit_node.register(ops.StringToTimestamp) + @visit_node.register(ops.Levenshtein) def visit_Undefined(self, op, **_): raise com.OperationNotDefinedError(type(op).__name__) diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_cast_double_col/float/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_cast_double_col/float/out.sql index e860397583365..f97b0b7e0747c 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_cast_double_col/float/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_cast_double_col/float/out.sql @@ -1,3 +1,3 @@ SELECT - t0.double_col AS double_col + t0.double_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bigint_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bigint_col/out.sql index 4bec790416366..b2e0d4507c4f4 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bigint_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bigint_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.bigint_col AS bigint_col + t0.bigint_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bool_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bool_col/out.sql index 130cc67206770..d967873daf1f0 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bool_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/bool_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.bool_col AS bool_col + t0.bool_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/date_string_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/date_string_col/out.sql index 30f45904aefea..c8ad0f838a317 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/date_string_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/date_string_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.date_string_col AS date_string_col + t0.date_string_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/double_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/double_col/out.sql index e860397583365..f97b0b7e0747c 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/double_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/double_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.double_col AS double_col + t0.double_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/float_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/float_col/out.sql index 5303bda94aa17..33277148af85b 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/float_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/float_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.float_col AS float_col + t0.float_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/id/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/id/out.sql index 8a5c9fda9ccc6..b4012dbb377d8 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/id/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/id/out.sql @@ -1,3 +1,3 @@ SELECT - t0.id AS id + t0.id FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/int_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/int_col/out.sql index f6d916f491443..6b3541821ed4f 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/int_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/int_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.int_col AS int_col + t0.int_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/month/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/month/out.sql index c7dc05252aa51..d0eb5143c2b46 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/month/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/month/out.sql @@ -1,3 +1,3 @@ SELECT - t0.month AS month + t0.month FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/smallint_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/smallint_col/out.sql index 7a69adfa78c9e..dfcd8e0c01495 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/smallint_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/smallint_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.smallint_col AS smallint_col + t0.smallint_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/string_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/string_col/out.sql index 9be6e5524121b..cfe88fb96a8c1 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/string_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/string_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.string_col AS string_col + t0.string_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/timestamp_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/timestamp_col/out.sql index f251eb35e6924..860302ea8039f 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/timestamp_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/timestamp_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.timestamp_col AS timestamp_col + t0.timestamp_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/tinyint_col/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/tinyint_col/out.sql index 4f3dd3c555a9a..c9f057e3aa118 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/tinyint_col/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/tinyint_col/out.sql @@ -1,3 +1,3 @@ SELECT - t0.tinyint_col AS tinyint_col + t0.tinyint_col FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/year/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/year/out.sql index 7d21b2c53090b..5295b8fc6a8d8 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/year/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_functions/test_noop_cast/year/out.sql @@ -1,3 +1,3 @@ SELECT - t0.year AS year + t0.year FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_array_join_in_subquery/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_array_join_in_subquery/out.sql index 05665f06de1da..a62f4b1f78bcf 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_array_join_in_subquery/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_array_join_in_subquery/out.sql @@ -1,7 +1,5 @@ SELECT - t0.id IN (( - SELECT - arrayJoin(t1.ids) AS ids - FROM way_view AS t1 - )) AS "InSubquery(id)" + t0.id IN (SELECT + arrayJoin(t1.ids) AS ids + FROM way_view AS t1) AS "InSubquery(id)" FROM node_view AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql index 0cc5ae5e12504..034aab28ceef8 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql @@ -2,7 +2,7 @@ SELECT CAST(t1.string_col AS Nullable(Float64)) AS "Cast(string_col, float64)" FROM ( SELECT - t0.string_col AS string_col, + t0.string_col, COUNT(*) AS count FROM functional_alltypes AS t0 GROUP BY diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_join/out.sql index 5156a61980fa9..a13c5f564c3e5 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_join/out.sql @@ -1,11 +1,18 @@ SELECT - t0.a AS a, - t0.b AS b, - t2.c AS c, - t2.d AS d, - t2.c / ( - t0.a - t0.b + t5.a, + t5.b, + t5.c, + t5.d, + t5.c / ( + t5.a - t5.b ) AS e -FROM s AS t0 -INNER JOIN t AS t2 - ON t0.a = t2.c \ No newline at end of file +FROM ( + SELECT + t2.a, + t2.b, + t3.c, + t3.d + FROM s AS t2 + INNER JOIN t AS t3 + ON t2.a = t3.c +) AS t5 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_count_name/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_count_name/out.sql index e6344e2c48f93..6edcaf0c84a93 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_count_name/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_count_name/out.sql @@ -1,5 +1,5 @@ SELECT - t0.a AS a, + t0.a, COALESCE(countIf(NOT ( t0.b )), 0) AS A, diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql index f75d124691e93..1bd6720ed390d 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql @@ -1,17 +1,17 @@ SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE t0.string_col IN ('foo', 'bar') \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql index 280d4be81f9f6..85fd1cae375d2 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql @@ -1,17 +1,17 @@ SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE NOT ( diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql index 6ef5f03a897cf..728987548b001 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql @@ -1,17 +1,17 @@ SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month -FROM functional_alltypes AS t0 -INNER JOIN functional_alltypes AS t1 - ON t0.id = t1.id \ No newline at end of file + t1.id, + t1.bool_col, + t1.tinyint_col, + t1.smallint_col, + t1.int_col, + t1.bigint_col, + t1.float_col, + t1.double_col, + t1.date_string_col, + t1.string_col, + t1.timestamp_col, + t1.year, + t1.month +FROM functional_alltypes AS t1 +INNER JOIN functional_alltypes AS t3 + ON t1.id = t3.id \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out1.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out1.sql index d9820f3b119bf..2ae649a0ea764 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out1.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out1.sql @@ -1,5 +1,5 @@ SELECT - t1.key AS key, + t1.key, SUM(( ( t1.value + 1 @@ -7,8 +7,8 @@ SELECT ) + 3) AS abc FROM ( SELECT - t0.key AS key, - t0.value AS value + t0.key, + t0.value FROM t0 AS t0 WHERE t0.value = 42 diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out2.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out2.sql index cf152c137c021..d22a599a88a79 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out2.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_named_from_filter_groupby/out2.sql @@ -1,5 +1,5 @@ SELECT - t1.key AS key, + t1.key, SUM(( ( t1.value + 1 @@ -7,8 +7,8 @@ SELECT ) + 3) AS foo FROM ( SELECT - t0.key AS key, - t0.value AS value + t0.key, + t0.value FROM t0 AS t0 WHERE t0.value = 42 diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql index b1f45cbca8ef2..99d5c76e03f3c 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql @@ -1,3 +1,3 @@ SELECT * -FROM functional_alltypes AS functional_alltypes_ref \ No newline at end of file +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql index b1a66e3641447..a1bdbc4f3fc31 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -ANY JOIN awards_players AS t2 - ON t0.playerID = t2.awardID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +ANY JOIN awards_players AS t3 + ON t2.playerID = t3.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql index 9e806e782a581..651c9ca466942 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -LEFT ANY JOIN awards_players AS t2 - ON t0.playerID = t2.awardID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +LEFT ANY JOIN awards_players AS t3 + ON t2.playerID = t3.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql index 3e49718a37e7f..ebcca144d2546 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -INNER JOIN awards_players AS t2 - ON t0.playerID = t2.awardID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +INNER JOIN awards_players AS t3 + ON t2.playerID = t3.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql index 3d2ffe6a0df85..5ae2ee1998b18 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -LEFT OUTER JOIN awards_players AS t2 - ON t0.playerID = t2.awardID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +LEFT OUTER JOIN awards_players AS t3 + ON t2.playerID = t3.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql index 84dddb02c5391..43bddb923f0a2 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -ANY JOIN awards_players AS t2 - ON t0.playerID = t2.playerID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +ANY JOIN awards_players AS t3 + ON t2.playerID = t3.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql index 6826f42c27525..5586b8b01ee02 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -LEFT ANY JOIN awards_players AS t2 - ON t0.playerID = t2.playerID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +LEFT ANY JOIN awards_players AS t3 + ON t2.playerID = t3.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql index c1d013f9fe497..f611516b394ef 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -INNER JOIN awards_players AS t2 - ON t0.playerID = t2.playerID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +INNER JOIN awards_players AS t3 + ON t2.playerID = t3.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql index cd444e5fa871d..c820c7e05b880 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql @@ -1,26 +1,26 @@ SELECT - t0.playerID AS playerID, - t0.yearID AS yearID, - t0.stint AS stint, - t0.teamID AS teamID, - t0.lgID AS lgID, - t0.G AS G, - t0.AB AS AB, - t0.R AS R, - t0.H AS H, - t0.X2B AS X2B, - t0.X3B AS X3B, - t0.HR AS HR, - t0.RBI AS RBI, - t0.SB AS SB, - t0.CS AS CS, - t0.BB AS BB, - t0.SO AS SO, - t0.IBB AS IBB, - t0.HBP AS HBP, - t0.SH AS SH, - t0.SF AS SF, - t0.GIDP AS GIDP -FROM batting AS t0 -LEFT OUTER JOIN awards_players AS t2 - ON t0.playerID = t2.playerID \ No newline at end of file + t2.playerID, + t2.yearID, + t2.stint, + t2.teamID, + t2.lgID, + t2.G, + t2.AB, + t2.R, + t2.H, + t2.X2B, + t2.X3B, + t2.HR, + t2.RBI, + t2.SB, + t2.CS, + t2.BB, + t2.SO, + t2.IBB, + t2.HBP, + t2.SH, + t2.SF, + t2.GIDP +FROM batting AS t2 +LEFT OUTER JOIN awards_players AS t3 + ON t2.playerID = t3.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql index 57e97d5ec0950..86d975c44589a 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql @@ -2,19 +2,19 @@ SELECT SUM(t1.float_col) AS "Sum(float_col)" FROM ( SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE t0.int_col > 0 diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql index 53eef384f1480..d2bf6243fdea4 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql @@ -1,24 +1,24 @@ SELECT - t2.string_col AS string_col + t2.string_col FROM ( SELECT - t1.string_col AS string_col, + t1.string_col, SUM(t1.float_col) AS total FROM ( SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE t0.int_col > 0 diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql index 3fc646a6237e1..cb651e1f73692 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql @@ -1,17 +1,17 @@ SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE t0.float_col > 0 AND t0.int_col < ( diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql index e91cbcdc45950..a27f8a736dc53 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql @@ -1,17 +1,17 @@ SELECT - t0.id AS id, - t0.bool_col AS bool_col, - t0.tinyint_col AS tinyint_col, - t0.smallint_col AS smallint_col, - t0.int_col AS int_col, - t0.bigint_col AS bigint_col, - t0.float_col AS float_col, - t0.double_col AS double_col, - t0.date_string_col AS date_string_col, - t0.string_col AS string_col, - t0.timestamp_col AS timestamp_col, - t0.year AS year, - t0.month AS month + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE t0.int_col > 0 AND t0.float_col BETWEEN 0 AND 1 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_timestamp/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_timestamp/out.sql index 2e6c66b7d8313..cee980322a7b2 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_timestamp/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_timestamp/out.sql @@ -1,5 +1,5 @@ SELECT - t0.uuid AS uuid, + t0.uuid, minIf(t0.ts, t0.search_level = 1) AS min_date FROM t AS t0 GROUP BY diff --git a/ibis/backends/conftest.py b/ibis/backends/conftest.py index dd9e5474d58b0..a7459052119f1 100644 --- a/ibis/backends/conftest.py +++ b/ibis/backends/conftest.py @@ -538,7 +538,6 @@ def ddl_con(ddl_backend): @pytest.fixture( params=_get_backends_to_test( keep=( - "duckdb", "exasol", "mssql", "mysql", diff --git a/ibis/backends/duckdb/__init__.py b/ibis/backends/duckdb/__init__.py index 35ebd07b1bac8..b1df755619700 100644 --- a/ibis/backends/duckdb/__init__.py +++ b/ibis/backends/duckdb/__init__.py @@ -9,6 +9,7 @@ from operator import itemgetter from pathlib import Path from typing import TYPE_CHECKING, Any +from urllib.parse import parse_qs, urlparse import duckdb import pandas as pd @@ -16,7 +17,6 @@ import pyarrow_hotfix # noqa: F401 import sqlglot as sg import sqlglot.expressions as sge -import toolz import ibis import ibis.common.exceptions as exc @@ -26,7 +26,6 @@ import ibis.expr.types as ir from ibis import util from ibis.backends.base import CanCreateSchema -from ibis.backends.base.sql.alchemy.geospatial import geospatial_supported from ibis.backends.base.sqlglot import SQLGlotBackend from ibis.backends.base.sqlglot.compiler import STAR, C, F from ibis.backends.base.sqlglot.datatypes import DuckDBType @@ -107,9 +106,12 @@ def raw_sql(self, query: str | sg.Expression, **kwargs: Any) -> Any: query = query.sql(dialect=self.name) return self.con.execute(query, **kwargs) - def _transform( - self, sql: sge.Expression, table_expr: ir.TableExpr - ) -> sge.Expression: + def _to_sqlglot( + self, expr: ir.Expr, limit: str | None = None, params=None, **_: Any + ): + sql = super()._to_sqlglot(expr, limit=limit, params=params) + + table_expr = expr.as_table() geocols = frozenset( name for name, typ in table_expr.schema().items() if typ.is_geospatial() ) @@ -175,7 +177,7 @@ def create_table( self._run_pre_execute_hooks(table) - (query,) = self._to_sqlglot(table) + query = self._to_sqlglot(table) else: query = None @@ -454,22 +456,20 @@ def _from_url(self, url: str, **kwargs) -> BaseBackend: BaseBackend A backend instance """ - import sqlalchemy as sa - - url = sa.engine.make_url(url) - - kwargs = toolz.merge( - { - name: value - for name in ("database", "read_only", "temp_directory") - if (value := getattr(url, name, None)) - }, - kwargs, - ) + url = urlparse(url) + database = url.path[1:] or ":memory:" + query_params = parse_qs(url.query) + + for name, value in query_params.items(): + if len(value) > 1: + kwargs[name] = value + elif len(value) == 1: + kwargs[name] = value[0] + else: + raise exc.IbisError(f"Invalid URL parameter: {name}") - kwargs.update(url.query) self._convert_kwargs(kwargs) - return self.connect(**kwargs) + return self.connect(database=database, **kwargs) def load_extension(self, extension: str, force_install: bool = False) -> None: """Install and load a duckdb extension by name or path. @@ -722,7 +722,7 @@ def read_geo( if source.startswith(("http://", "https://", "s3://")): self._load_extensions(["httpfs"]) - source_expr = sg.select(STAR).from_( + source_expr = sg.select(STAR).from_( self.compiler.f.st_read( source, *(sg.to_identifier(key).eq(val) for key, val in kwargs.items()), @@ -921,10 +921,7 @@ def list_tables( >>> con.list_tables(schema="my_schema") [] >>> with con.begin() as c: - ... c.exec_driver_sql( - ... "CREATE TABLE my_schema.baz (a INTEGER)" - ... ) # doctest: +ELLIPSIS - ... + ... c.exec_driver_sql("CREATE TABLE my_schema.baz (a INTEGER)") # doctest: +ELLIPSIS <...> >>> con.list_tables(schema="my_schema") ['baz'] @@ -1360,7 +1357,7 @@ def to_csv( with self._safe_raw_sql(copy_cmd): pass - def fetch_from_cursor( + def _fetch_from_cursor( self, cursor: duckdb.DuckDBPyConnection, schema: sch.Schema ) -> pd.DataFrame: import pandas as pd @@ -1384,10 +1381,7 @@ def fetch_from_cursor( for name, col in zip(table.column_names, table.columns) } ) - df = DuckDBPandasData.convert_table(df, schema) - if not df.empty and geospatial_supported: - return self._to_geodataframe(df, schema) - return df + return DuckDBPandasData.convert_table(df, schema) # TODO(gforsyth): this may not need to be specialized in the future @staticmethod diff --git a/ibis/backends/duckdb/compiler.py b/ibis/backends/duckdb/compiler.py index 4207f108b8f56..8429f1e796219 100644 --- a/ibis/backends/duckdb/compiler.py +++ b/ibis/backends/duckdb/compiler.py @@ -329,6 +329,12 @@ def visit_Correlation(self, op, *, left, right, how, where): return self.agg.corr(left, right, where=where) + @visit_node.register(ops.GeoConvert) + def visit_GeoConvert(self, op, *, arg, source, target): + # 4th argument is to specify that the result is always_xy so that it + # matches the behavior of the equivalent geopandas functionality + return self.f.st_transform(arg, source, target, True) + _SIMPLE_OPS = { ops.ArrayPosition: "list_indexof", @@ -338,8 +344,8 @@ def visit_Correlation(self, op, *, left, right, how, where): ops.EndsWith: "suffix", ops.Hash: "hash", ops.IntegerRange: "range", + ops.TimestampRange: "range", ops.LPad: "lpad", - ops.Levenshtein: "levenshtein", ops.MapKeys: "map_keys", ops.MapLength: "cardinality", ops.MapMerge: "map_concat", @@ -349,7 +355,6 @@ def visit_Correlation(self, op, *, left, right, how, where): ops.StringAscii: "ascii", ops.TimeFromHMS: "make_time", ops.TypeOf: "typeof", - ops.Unnest: "unnest", ops.GeoPoint: "st_point", ops.GeoAsText: "st_astext", ops.GeoArea: "st_area", diff --git a/ibis/backends/duckdb/registry.py b/ibis/backends/duckdb/registry.py deleted file mode 100644 index 7b675acd369c4..0000000000000 --- a/ibis/backends/duckdb/registry.py +++ /dev/null @@ -1,585 +0,0 @@ -from __future__ import annotations - -import operator -from functools import partial -from typing import TYPE_CHECKING, Any - -import numpy as np -import sqlalchemy as sa -from sqlalchemy.ext.compiler import compiles -from sqlalchemy.sql.functions import GenericFunction - -import ibis.expr.operations as ops -from ibis.backends.base.sql import alchemy -from ibis.backends.base.sql.alchemy import unary -from ibis.backends.base.sql.alchemy.registry import ( - _table_column, - array_filter, - array_map, - geospatial_functions, - reduction, - try_cast, -) -from ibis.backends.duckdb.datatypes import Geometry_WKB -from ibis.backends.postgres.registry import ( - _array_index, - _array_slice, - fixed_arity, - operation_registry, -) -from ibis.common.exceptions import UnsupportedOperationError - -if TYPE_CHECKING: - from collections.abc import Mapping - - from ibis.backends.base.sql.alchemy.datatypes import StructType - -operation_registry = { - op: operation_registry[op] - for op in operation_registry.keys() - geospatial_functions.keys() -} - - -def _round(t, op): - arg, digits = op.args - sa_arg = t.translate(arg) - - if digits is None: - return sa.func.round(sa_arg) - - return sa.func.round(sa_arg, t.translate(digits)) - - -_LOG_BASE_FUNCS = { - 2: sa.func.log2, - 10: sa.func.log, -} - - -def _centroid(t, op): - arg = t.translate(op.arg) - return sa.func.st_centroid(arg, type_=Geometry_WKB) - - -def _geo_end_point(t, op): - arg = t.translate(op.arg) - return sa.func.st_endpoint(arg, type_=Geometry_WKB) - - -def _geo_start_point(t, op): - arg = t.translate(op.arg) - return sa.func.st_startpoint(arg, type_=Geometry_WKB) - - -def _envelope(t, op): - arg = t.translate(op.arg) - return sa.func.st_envelope(arg, type_=Geometry_WKB) - - -def _geo_buffer(t, op): - arg = t.translate(op.arg) - radius = t.translate(op.radius) - return sa.func.st_buffer(arg, radius, type_=Geometry_WKB) - - -def _geo_unary_union(t, op): - arg = t.translate(op.arg) - return sa.func.st_union_agg(arg, type_=Geometry_WKB) - - -def _geo_point(t, op): - left = t.translate(op.left) - right = t.translate(op.right) - return sa.func.st_point(left, right, type_=Geometry_WKB) - - -def _geo_difference(t, op): - left = t.translate(op.left) - right = t.translate(op.right) - return sa.func.st_difference(left, right, type_=Geometry_WKB) - - -def _geo_intersection(t, op): - left = t.translate(op.left) - right = t.translate(op.right) - return sa.func.st_intersection(left, right, type_=Geometry_WKB) - - -def _geo_union(t, op): - left = t.translate(op.left) - right = t.translate(op.right) - return sa.func.st_union(left, right, type_=Geometry_WKB) - - -def _geo_convert(t, op): - arg = t.translate(op.arg) - source = op.source - target = op.target - - # sa.true() setting always_xy=True - return sa.func.st_transform(arg, source, target, sa.true(), type_=Geometry_WKB) - - -def _generic_log(arg, base, *, type_): - return sa.func.ln(arg, type_=type_) / sa.func.ln(base, type_=type_) - - -def _log(t, op): - arg, base = op.args - sqla_type = t.get_sqla_type(op.dtype) - sa_arg = t.translate(arg) - if base is not None: - sa_base = t.translate(base) - try: - base_value = sa_base.value - except AttributeError: - return _generic_log(sa_arg, sa_base, type_=sqla_type) - else: - func = _LOG_BASE_FUNCS.get(base_value, _generic_log) - return func(sa_arg, type_=sqla_type) - return sa.func.ln(sa_arg, type_=sqla_type) - - -def _timestamp_from_unix(t, op): - arg, unit = op.args - arg = t.translate(arg) - - if unit.short == "ms": - return sa.func.epoch_ms(arg) - elif unit.short == "s": - return sa.func.to_timestamp(arg) - else: - raise UnsupportedOperationError(f"{unit!r} unit is not supported!") - - -def _timestamp_bucket(t, op): - arg = t.translate(op.arg) - interval = t.translate(op.interval) - - origin = sa.literal_column("'epoch'::TIMESTAMP") - - if op.offset is not None: - origin += t.translate(op.offset) - return sa.func.time_bucket(interval, arg, origin) - - -class struct_pack(GenericFunction): - def __init__(self, values: Mapping[str, Any], *, type: StructType) -> None: - super().__init__() - self.values = values - self.type = type - - -@compiles(struct_pack, "duckdb") -def compiles_struct_pack(element, compiler, **kw): - quote = compiler.preparer.quote - args = ", ".join( - f"{quote(key)} := {compiler.process(value, **kw)}" - for key, value in element.values.items() - ) - return f"struct_pack({args})" - - -def _literal(t, op): - dtype = op.dtype - value = op.value - - if value is None: - return ( - sa.null() if dtype.is_null() else sa.cast(sa.null(), t.get_sqla_type(dtype)) - ) - - sqla_type = t.get_sqla_type(dtype) - - if dtype.is_interval(): - return getattr(sa.func, f"to_{dtype.unit.plural}")(value) - elif dtype.is_array(): - values = value.tolist() if isinstance(value, np.ndarray) else value - return sa.cast(sa.func.list_value(*values), sqla_type) - elif dtype.is_floating(): - if not np.isfinite(value): - if np.isnan(value): - value = "NaN" - else: - assert np.isinf(value), "value is neither finite, nan nor infinite" - prefix = "-" * (value < 0) - value = f"{prefix}Inf" - return sa.cast(sa.literal(value), sqla_type) - elif dtype.is_struct(): - return struct_pack( - { - key: t.translate(ops.Literal(val, dtype=dtype[key])) - for key, val in value.items() - }, - type=sqla_type, - ) - elif dtype.is_string(): - return sa.literal(value) - elif dtype.is_map(): - return sa.func.map( - sa.func.list_value(*value.keys()), sa.func.list_value(*value.values()) - ) - elif dtype.is_timestamp(): - return sa.cast(sa.literal(value.isoformat()), t.get_sqla_type(dtype)) - elif dtype.is_date(): - return sa.func.make_date(value.year, value.month, value.day) - elif dtype.is_time(): - return sa.func.make_time( - value.hour, value.minute, value.second + value.microsecond / 1e6 - ) - else: - return sa.cast(sa.literal(value), sqla_type) - - -if_ = getattr(sa.func, "if") - - -def _neg_idx_to_pos(array, idx): - arg_length = sa.func.array_length(array) - return if_(idx < 0, arg_length + sa.func.greatest(idx, -arg_length), idx) - - -def _regex_extract(string, pattern, index): - return sa.func.regexp_extract( - string, - pattern, - # DuckDB requires the index to be a constant, so we compile - # the value and inline it by using sa.text - sa.text(str(index.compile(compile_kwargs=dict(literal_binds=True)))), - ) - - -def _json_get_item(left, path): - # Workaround for https://github.com/duckdb/duckdb/issues/5063 - # In some situations duckdb silently does the wrong thing if - # the path is parametrized. - sa_path = sa.text(str(path.compile(compile_kwargs=dict(literal_binds=True)))) - return left.op("->")(sa_path) - - -def _strftime(t, op): - if not isinstance(op.format_str, ops.Literal): - raise UnsupportedOperationError( - f"DuckDB format_str must be a literal `str`; got {type(op.format_str)}" - ) - return sa.func.strftime(t.translate(op.arg), t.translate(op.format_str)) - - -def _strptime(t, op): - if not isinstance(op.format_str, ops.Literal): - raise UnsupportedOperationError( - f"DuckDB format_str must be a literal `str`; got {type(op.format_str)}" - ) - return sa.cast( - sa.func.strptime(t.translate(op.arg), t.translate(op.format_str)), - t.get_sqla_type(op.dtype), - ) - - -def _arbitrary(t, op): - if (how := op.how) == "heavy": - raise UnsupportedOperationError( - f"how={how!r} not supported in the DuckDB backend" - ) - return t._reduction(getattr(sa.func, how), op) - - -def _string_agg(t, op): - if not isinstance(op.sep, ops.Literal): - raise UnsupportedOperationError( - "Separator argument to group_concat operation must be a constant" - ) - agg = sa.func.string_agg(t.translate(op.arg), sa.text(repr(op.sep.value))) - if (where := op.where) is not None: - return agg.filter(t.translate(where)) - return agg - - -def _struct_column(t, op): - return struct_pack( - dict(zip(op.names, map(t.translate, op.values))), - type=t.get_sqla_type(op.dtype), - ) - - -@compiles(array_map, "duckdb") -def compiles_list_apply(element, compiler, **kw): - *args, signature, result = map(partial(compiler.process, **kw), element.clauses) - return f"list_apply({', '.join(args)}, {signature} -> {result})" - - -def _array_map(t, op): - return array_map( - t.translate(op.arg), sa.literal_column(f"({op.param})"), t.translate(op.body) - ) - - -@compiles(array_filter, "duckdb") -def compiles_list_filter(element, compiler, **kw): - *args, signature, result = map(partial(compiler.process, **kw), element.clauses) - return f"list_filter({', '.join(args)}, {signature} -> {result})" - - -def _array_filter(t, op): - return array_filter( - t.translate(op.arg), sa.literal_column(f"({op.param})"), t.translate(op.body) - ) - - -def _array_intersect(t, op): - name = "x" - parameter = ops.Argument( - name=name, shape=op.left.shape, dtype=op.left.dtype.value_type - ) - return t.translate( - ops.ArrayFilter( - op.left, param=parameter.param, body=ops.ArrayContains(op.right, parameter) - ) - ) - - -def _array_zip(t, op): - args = tuple(map(t.translate, op.arg)) - - i = sa.literal_column("i", type_=sa.INTEGER) - dtype = op.dtype - return array_map( - sa.func.range(1, sa.func.greatest(*map(sa.func.array_length, args)) + 1), - i, - struct_pack( - { - name: sa.func.list_extract(arg, i) - for name, arg in zip(dtype.value_type.names, args) - }, - type=t.get_sqla_type(dtype), - ), - ) - - -@compiles(try_cast, "duckdb") -def compiles_try_cast(element, compiler, **kw): - return "TRY_CAST({} AS {})".format( - compiler.process(element.clauses.clauses[0], **kw), - compiler.visit_typeclause(element), - ) - - -def _try_cast(t, op): - arg = t.translate(op.arg) - to = t.get_sqla_type(op.to) - return try_cast(arg, type_=to) - - -_temporal_delta = fixed_arity( - lambda part, start, end: sa.func.date_diff(part, end, start), 3 -) - - -def _to_json_collection(t, op): - typ = t.get_sqla_type(op.dtype) - return try_cast(t.translate(op.arg), typ, type_=typ) - - -def _array_remove(t, op): - arg = op.arg - param = ops.Argument(name="x", shape=arg.shape, dtype=arg.dtype.value_type) - return _array_filter( - t, - ops.ArrayFilter(arg, param=param.param, body=ops.NotEquals(param, op.other)), - ) - - -operation_registry.update( - { - ops.ArrayColumn: ( - lambda t, op: sa.cast( - sa.func.list_value(*map(t.translate, op.cols)), - t.get_sqla_type(op.dtype), - ) - ), - ops.TryCast: _try_cast, - ops.ArrayRepeat: fixed_arity( - lambda arg, times: sa.func.flatten( - sa.func.array( - sa.select(arg).select_from(sa.func.range(times)).scalar_subquery() - ) - ), - 2, - ), - ops.ArrayLength: unary(sa.func.array_length), - ops.ArraySlice: _array_slice( - index_converter=_neg_idx_to_pos, - array_length=sa.func.array_length, - func=sa.func.list_slice, - ), - ops.ArrayIndex: _array_index( - index_converter=_neg_idx_to_pos, func=sa.func.list_extract - ), - ops.ArrayMap: _array_map, - ops.ArrayFilter: _array_filter, - ops.ArrayContains: fixed_arity(sa.func.list_has, 2), - ops.ArrayPosition: fixed_arity( - lambda lst, el: sa.func.list_indexof(lst, el) - 1, 2 - ), - ops.ArrayDistinct: fixed_arity( - lambda arg: if_( - arg.is_(sa.null()), - sa.null(), - # append a null if the input array has a null - sa.func.list_distinct(arg) - + if_( - # list_count doesn't count nulls - sa.func.list_count(arg) < sa.func.array_length(arg), - sa.func.list_value(sa.null()), - sa.func.list_value(), - ), - ), - 1, - ), - ops.ArraySort: fixed_arity(sa.func.list_sort, 1), - ops.ArrayRemove: _array_remove, - ops.ArrayUnion: lambda t, op: t.translate( - ops.ArrayDistinct(ops.ArrayConcat((op.left, op.right))) - ), - ops.ArrayZip: _array_zip, - ops.DayOfWeekName: unary(sa.func.dayname), - ops.Literal: _literal, - ops.Log2: unary(sa.func.log2), - ops.Ln: unary(sa.func.ln), - ops.Log: _log, - ops.IsNan: unary(sa.func.isnan), - ops.Modulus: fixed_arity(operator.mod, 2), - ops.Round: _round, - ops.StructField: ( - lambda t, op: sa.func.struct_extract( - t.translate(op.arg), - sa.text(repr(op.field)), - type_=t.get_sqla_type(op.dtype), - ) - ), - ops.TableColumn: _table_column, - ops.TimestampFromUNIX: _timestamp_from_unix, - ops.TimestampBucket: _timestamp_bucket, - ops.TimestampNow: fixed_arity( - # duckdb 0.6.0 changes now to be a timestamp with time zone force - # it back to the original for backwards compatibility - lambda *_: sa.cast(sa.func.now(), sa.TIMESTAMP), - 0, - ), - ops.RegexExtract: fixed_arity(_regex_extract, 3), - ops.RegexReplace: fixed_arity( - lambda *args: sa.func.regexp_replace(*args, sa.text("'g'")), 3 - ), - ops.RegexSearch: fixed_arity(sa.func.regexp_matches, 2), - ops.StringContains: fixed_arity(sa.func.contains, 2), - ops.ApproxMedian: reduction( - # without inline text, duckdb fails with - # RuntimeError: INTERNAL Error: Invalid PhysicalType for GetTypeIdSize - lambda arg: sa.func.approx_quantile(arg, sa.text(str(0.5))) - ), - ops.ApproxCountDistinct: reduction(sa.func.approx_count_distinct), - ops.Mode: reduction(sa.func.mode), - ops.Strftime: _strftime, - ops.Arbitrary: _arbitrary, - ops.GroupConcat: _string_agg, - ops.StructColumn: _struct_column, - ops.ArgMin: reduction(sa.func.min_by), - ops.ArgMax: reduction(sa.func.max_by), - ops.BitwiseXor: fixed_arity(sa.func.xor, 2), - ops.JSONGetItem: fixed_arity(_json_get_item, 2), - ops.RowID: lambda *_: sa.literal_column("rowid"), - ops.StringToTimestamp: _strptime, - ops.Quantile: lambda t, op: ( - reduction(sa.func.quantile_cont)(t, op) - if op.arg.dtype.is_numeric() - else reduction(sa.func.quantile_disc)(t, op) - ), - ops.MultiQuantile: lambda t, op: ( - reduction(sa.func.quantile_cont)(t, op) - if op.arg.dtype.is_numeric() - else reduction(sa.func.quantile_disc)(t, op) - ), - ops.TypeOf: unary(sa.func.typeof), - ops.IntervalAdd: fixed_arity(operator.add, 2), - ops.IntervalSubtract: fixed_arity(operator.sub, 2), - ops.Capitalize: alchemy.sqlalchemy_operation_registry[ops.Capitalize], - ops.ArrayStringJoin: fixed_arity( - lambda sep, arr: sa.func.array_aggr(arr, sa.text("'string_agg'"), sep), 2 - ), - ops.StartsWith: fixed_arity(sa.func.prefix, 2), - ops.EndsWith: fixed_arity(sa.func.suffix, 2), - ops.Argument: lambda _, op: sa.literal_column(op.param), - ops.Unnest: unary(sa.func.unnest), - ops.MapGet: fixed_arity( - lambda arg, key, default: sa.func.coalesce( - sa.func.list_extract(sa.func.element_at(arg, key), 1), default - ), - 3, - ), - ops.Map: fixed_arity(sa.func.map, 2), - ops.MapContains: fixed_arity( - lambda arg, key: sa.func.array_length(sa.func.element_at(arg, key)) != 0, 2 - ), - ops.MapLength: unary(sa.func.cardinality), - ops.MapKeys: unary(sa.func.map_keys), - ops.MapValues: unary(sa.func.map_values), - ops.MapMerge: fixed_arity(sa.func.map_concat, 2), - ops.Hash: unary(sa.func.hash), - ops.Median: reduction(sa.func.median), - ops.First: reduction(sa.func.first), - ops.Last: reduction(sa.func.last), - ops.ArrayIntersect: _array_intersect, - ops.TimeDelta: _temporal_delta, - ops.DateDelta: _temporal_delta, - ops.TimestampDelta: _temporal_delta, - ops.ToJSONMap: _to_json_collection, - ops.ToJSONArray: _to_json_collection, - ops.ArrayFlatten: unary(sa.func.flatten), - ops.IntegerRange: fixed_arity(sa.func.range, 3), - # geospatial - ops.GeoPoint: _geo_point, - ops.GeoAsText: unary(sa.func.ST_AsText), - ops.GeoArea: unary(sa.func.ST_Area), - ops.GeoBuffer: _geo_buffer, - ops.GeoCentroid: _centroid, - ops.GeoContains: fixed_arity(sa.func.ST_Contains, 2), - ops.GeoCovers: fixed_arity(sa.func.ST_Covers, 2), - ops.GeoCoveredBy: fixed_arity(sa.func.ST_CoveredBy, 2), - ops.GeoCrosses: fixed_arity(sa.func.ST_Crosses, 2), - ops.GeoDifference: _geo_difference, - ops.GeoDisjoint: fixed_arity(sa.func.ST_Disjoint, 2), - ops.GeoDistance: fixed_arity(sa.func.ST_Distance, 2), - ops.GeoDWithin: fixed_arity(sa.func.ST_DWithin, 3), - ops.GeoEndPoint: _geo_end_point, - ops.GeoEnvelope: _envelope, - ops.GeoEquals: fixed_arity(sa.func.ST_Equals, 2), - ops.GeoGeometryType: unary(sa.func.ST_GeometryType), - ops.GeoIntersection: _geo_intersection, - ops.GeoIntersects: fixed_arity(sa.func.ST_Intersects, 2), - ops.GeoIsValid: unary(sa.func.ST_IsValid), - ops.GeoLength: unary(sa.func.ST_Length), - ops.GeoNPoints: unary(sa.func.ST_NPoints), - ops.GeoOverlaps: fixed_arity(sa.func.ST_Overlaps, 2), - ops.GeoStartPoint: _geo_start_point, - ops.GeoTouches: fixed_arity(sa.func.ST_Touches, 2), - ops.GeoUnion: _geo_union, - ops.GeoUnaryUnion: _geo_unary_union, - ops.GeoWithin: fixed_arity(sa.func.ST_Within, 2), - ops.GeoX: unary(sa.func.ST_X), - ops.GeoY: unary(sa.func.ST_Y), - ops.GeoConvert: _geo_convert, - # other ops - ops.TimestampRange: fixed_arity(sa.func.range, 3), - ops.RegexSplit: fixed_arity(sa.func.str_split_regex, 2), - } -) - - -_invalid_operations = { - # ibis.expr.operations.strings - ops.Translate, -} - -operation_registry = { - k: v for k, v in operation_registry.items() if k not in _invalid_operations -} diff --git a/ibis/backends/duckdb/tests/conftest.py b/ibis/backends/duckdb/tests/conftest.py index 3f974c5f806cc..cffe154a51579 100644 --- a/ibis/backends/duckdb/tests/conftest.py +++ b/ibis/backends/duckdb/tests/conftest.py @@ -7,7 +7,7 @@ import ibis from ibis.backends.conftest import TEST_TABLES from ibis.backends.tests.base import BackendTest -from ibis.conftest import SANDBOXED +from ibis.conftest import SANDBOXED, WINDOWS if TYPE_CHECKING: from collections.abc import Iterator @@ -49,8 +49,6 @@ def preload(self): @property def ddl_script(self) -> Iterator[str]: - from ibis.backends.base.sql.alchemy.geospatial import geospatial_supported - parquet_dir = self.data_dir / "parquet" geojson_dir = self.data_dir / "geojson" for table in TEST_TABLES: @@ -60,7 +58,7 @@ def ddl_script(self) -> Iterator[str]: SELECT * FROM read_parquet('{parquet_dir / f'{table}.parquet'}') """ ) - if geospatial_supported and not SANDBOXED: + if not SANDBOXED: for table in TEST_TABLES_GEO: yield ( f""" @@ -82,18 +80,25 @@ def ddl_script(self) -> Iterator[str]: @staticmethod def connect(*, tmpdir, worker_id, **kw) -> BaseBackend: # use an extension directory per test worker to prevent simultaneous - # downloads - extension_directory = tmpdir.getbasetemp().joinpath("duckdb_extensions") - extension_directory.mkdir(exist_ok=True) - return ibis.duckdb.connect(extension_directory=extension_directory, **kw) + # downloads on windows + # + # avoid enabling on linux because this adds a lot of time to parallel + # test runs due to each worker getting its own extensions directory + if WINDOWS: + extension_directory = tmpdir.getbasetemp().joinpath("duckdb_extensions") + extension_directory.mkdir(exist_ok=True) + kw["extension_directory"] = extension_directory + return ibis.duckdb.connect(**kw) def load_tpch(self) -> None: - self.connection.raw_sql("CALL dbgen(sf=0.1)") + """Load the TPC-H dataset.""" + with self.connection._safe_raw_sql("CALL dbgen(sf=0.17)"): + pass def _load_data(self, **_: Any) -> None: """Load test data into a backend.""" - for stmt in self.ddl_script: - self.connection.raw_sql(stmt) + with self.connection._safe_raw_sql(";\n".join(self.ddl_script)): + pass @pytest.fixture(scope="session") diff --git a/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_dwithin/out.sql b/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_dwithin/out.sql index 2d3e7ec658515..e68c658139131 100644 --- a/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_dwithin/out.sql +++ b/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_dwithin/out.sql @@ -1,3 +1,3 @@ SELECT - ST_DWITHIN(t0.geom, t0.geom, CAST(3.0 AS DOUBLE)) AS "GeoDWithin(geom, geom, 3.0)" + ST_DWITHIN(t0.geom, t0.geom, CAST(3.0 AS DOUBLE)) AS tmp FROM t AS t0 \ No newline at end of file diff --git a/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/as_text/out.sql b/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/as_text/out.sql index 498b544a506c5..7da710b2dcebd 100644 --- a/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/as_text/out.sql +++ b/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/as_text/out.sql @@ -1,3 +1,3 @@ SELECT - ST_ASTEXT(t0.geom) AS "GeoAsText(geom)" + ST_ASTEXT(t0.geom) AS tmp FROM t AS t0 \ No newline at end of file diff --git a/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/n_points/out.sql b/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/n_points/out.sql index db42c12ad2373..bf8ba88ffde23 100644 --- a/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/n_points/out.sql +++ b/ibis/backends/duckdb/tests/snapshots/test_geospatial/test_geospatial_unary_snapshot/n_points/out.sql @@ -1,3 +1,3 @@ SELECT - ST_NPOINTS(t0.geom) AS "GeoNPoints(geom)" + ST_NPOINTS(t0.geom) AS tmp FROM t AS t0 \ No newline at end of file diff --git a/ibis/backends/duckdb/tests/test_client.py b/ibis/backends/duckdb/tests/test_client.py index e01467aa5f65b..08cee6fb09547 100644 --- a/ibis/backends/duckdb/tests/test_client.py +++ b/ibis/backends/duckdb/tests/test_client.py @@ -189,6 +189,7 @@ def test_insert(con): assert t.count().execute() == 2 +@pytest.mark.xfail(reason="snowflake backend not yet rewritten") def test_to_other_sql(con, snapshot): pytest.importorskip("snowflake.connector") diff --git a/ibis/backends/duckdb/tests/test_geospatial.py b/ibis/backends/duckdb/tests/test_geospatial.py index 4df79e4203d8b..379a1fd8cdd52 100644 --- a/ibis/backends/duckdb/tests/test_geospatial.py +++ b/ibis/backends/duckdb/tests/test_geospatial.py @@ -16,7 +16,7 @@ def test_geospatial_point(zones, zones_gdf): - coord = zones.x_cent.point(zones.y_cent) + coord = zones.x_cent.point(zones.y_cent).name("coord") # this returns GeometryArray gp_coord = gpd.points_from_xy(zones_gdf.x_cent, zones_gdf.y_cent) @@ -33,13 +33,13 @@ def test_geospatial_point(zones, zones_gdf): ) def test_geospatial_unary_snapshot(operation, keywords, snapshot): t = ibis.table([("geom", "geometry")], name="t") - expr = getattr(t.geom, operation)(**keywords) + expr = getattr(t.geom, operation)(**keywords).name("tmp") snapshot.assert_match(ibis.to_sql(expr), "out.sql") def test_geospatial_dwithin(snapshot): t = ibis.table([("geom", "geometry")], name="t") - expr = t.geom.d_within(t.geom, 3.0) + expr = t.geom.d_within(t.geom, 3.0).name("tmp") snapshot.assert_match(ibis.to_sql(expr), "out.sql") @@ -61,7 +61,7 @@ def test_geospatial_dwithin(snapshot): ], ) def test_geospatial_unary_tm(op, keywords, gp_op, zones, zones_gdf): - expr = getattr(zones.geom, op)(**keywords) + expr = getattr(zones.geom, op)(**keywords).name("tmp") gp_expr = getattr(zones_gdf.geometry, gp_op) tm.assert_series_equal(expr.to_pandas(), gp_expr, check_names=False) @@ -75,10 +75,10 @@ def test_geospatial_unary_tm(op, keywords, gp_op, zones, zones_gdf): ], ) def test_geospatial_xy(op, keywords, gp_op, zones, zones_gdf): - cen = zones.geom.centroid() + cen = zones.geom.centroid().name("centroid") gp_cen = zones_gdf.geometry.centroid - expr = getattr(cen, op)(**keywords) + expr = getattr(cen, op)(**keywords).name("tmp") gp_expr = getattr(gp_cen, gp_op) tm.assert_series_equal(expr.to_pandas(), gp_expr, check_names=False) @@ -87,7 +87,7 @@ def test_geospatial_xy(op, keywords, gp_op, zones, zones_gdf): def test_geospatial_length(lines, lines_gdf): # note: ST_LENGTH returns 0 for the case of polygon # or multi polygon while pandas geopandas returns the perimeter. - length = lines.geom.length() + length = lines.geom.length().name("length") gp_length = lines_gdf.geometry.length tm.assert_series_equal(length.to_pandas(), gp_length, check_names=False) @@ -112,7 +112,7 @@ def test_geospatial_length(lines, lines_gdf): ], ) def test_geospatial_binary_tm(op, gp_op, zones, zones_gdf): - expr = getattr(zones.geom, op)(zones.geom) + expr = getattr(zones.geom, op)(zones.geom).name("tmp") gp_func = getattr(zones_gdf.geometry, gp_op)(zones_gdf.geometry) tm.assert_series_equal(expr.to_pandas(), gp_func, check_names=False) @@ -128,7 +128,7 @@ def test_geospatial_binary_tm(op, gp_op, zones, zones_gdf): ], ) def test_geospatial_unary_gtm(op, gp_op, zones, zones_gdf): - expr = getattr(zones.geom, op)() + expr = getattr(zones.geom, op)().name("tmp") gp_expr = getattr(zones_gdf.geometry, gp_op) gtm.assert_geoseries_equal(expr.to_pandas(), gp_expr, check_crs=False) @@ -145,14 +145,14 @@ def test_geospatial_unary_gtm(op, gp_op, zones, zones_gdf): ], ) def test_geospatial_binary_gtm(op, gp_op, zones, zones_gdf): - expr = getattr(zones.geom, op)(zones.geom) + expr = getattr(zones.geom, op)(zones.geom).name("tmp") gp_func = getattr(zones_gdf.geometry, gp_op)(zones_gdf.geometry) gtm.assert_geoseries_equal(expr.to_pandas(), gp_func, check_crs=False) def test_geospatial_end_point(lines, lines_gdf): - epoint = lines.geom.end_point() + epoint = lines.geom.end_point().name("end_point") # geopandas does not have end_point this is a work around to get it gp_epoint = lines_gdf.geometry.boundary.explode(index_parts=True).xs(1, level=1) @@ -160,7 +160,7 @@ def test_geospatial_end_point(lines, lines_gdf): def test_geospatial_start_point(lines, lines_gdf): - spoint = lines.geom.start_point() + spoint = lines.geom.start_point().name("start_point") # geopandas does not have start_point this is a work around to get it gp_spoint = lines_gdf.geometry.boundary.explode(index_parts=True).xs(0, level=1) @@ -169,7 +169,7 @@ def test_geospatial_start_point(lines, lines_gdf): # this one takes a bit longer than the rest. def test_geospatial_unary_union(zones, zones_gdf): - unary_union = zones.geom.unary_union() + unary_union = zones.geom.unary_union().name("unary_union") # this returns a shapely geometry object gp_unary_union = zones_gdf.geometry.unary_union @@ -181,7 +181,7 @@ def test_geospatial_unary_union(zones, zones_gdf): def test_geospatial_buffer_point(zones, zones_gdf): - cen = zones.geom.centroid() + cen = zones.geom.centroid().name("centroid") gp_cen = zones_gdf.geometry.centroid buffer = cen.buffer(100.0) diff --git a/ibis/backends/duckdb/tests/test_register.py b/ibis/backends/duckdb/tests/test_register.py index 845321836595a..94989b422e219 100644 --- a/ibis/backends/duckdb/tests/test_register.py +++ b/ibis/backends/duckdb/tests/test_register.py @@ -11,7 +11,6 @@ import pandas.testing as tm import pyarrow as pa import pytest -import sqlalchemy as sa import ibis import ibis.common.exceptions as exc @@ -112,7 +111,7 @@ def test_read_geo_from_url(con, monkeypatch): loaded_exts = [] monkeypatch.setattr(con, "_load_extensions", lambda x, **kw: loaded_exts.extend(x)) - with pytest.raises((sa.exc.OperationalError, sa.exc.ProgrammingError)): + with pytest.raises(duckdb.IOException): # The read will fail, either because the URL is bogus (which it is) or # because the current connection doesn't have the spatial extension # installed and so the call to `st_read` will raise a catalog error. @@ -360,7 +359,7 @@ def test_set_temp_dir(tmp_path): "nix on linux cannot download duckdb extensions or data due to sandboxing; " "duckdb will try to automatically install and load read_parquet" ), - raises=(duckdb.IOException, sa.exc.DBAPIError), + raises=duckdb.IOException, ) def test_s3_403_fallback(con, httpserver, monkeypatch): # monkeypatch to avoid downloading extensions in tests diff --git a/ibis/backends/tests/snapshots/test_interactive/test_default_limit/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_default_limit/clickhouse/out.sql new file mode 100644 index 0000000000000..f26c12ac78c85 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_default_limit/clickhouse/out.sql @@ -0,0 +1,5 @@ +SELECT + t0.id, + t0.bool_col +FROM functional_alltypes AS t0 +LIMIT 11 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_default_limit/duckdb/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_default_limit/duckdb/out.sql new file mode 100644 index 0000000000000..f26c12ac78c85 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_default_limit/duckdb/out.sql @@ -0,0 +1,5 @@ +SELECT + t0.id, + t0.bool_col +FROM functional_alltypes AS t0 +LIMIT 11 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_disable_query_limit/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_disable_query_limit/clickhouse/out.sql new file mode 100644 index 0000000000000..f26c12ac78c85 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_disable_query_limit/clickhouse/out.sql @@ -0,0 +1,5 @@ +SELECT + t0.id, + t0.bool_col +FROM functional_alltypes AS t0 +LIMIT 11 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_disable_query_limit/duckdb/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_disable_query_limit/duckdb/out.sql new file mode 100644 index 0000000000000..f26c12ac78c85 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_disable_query_limit/duckdb/out.sql @@ -0,0 +1,5 @@ +SELECT + t0.id, + t0.bool_col +FROM functional_alltypes AS t0 +LIMIT 11 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_interactive_execute_on_repr/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_interactive_execute_on_repr/clickhouse/out.sql new file mode 100644 index 0000000000000..eb7db27313646 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_interactive_execute_on_repr/clickhouse/out.sql @@ -0,0 +1,3 @@ +SELECT + SUM(t0.bigint_col) AS "Sum(bigint_col)" +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_interactive_execute_on_repr/duckdb/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_interactive_execute_on_repr/duckdb/out.sql new file mode 100644 index 0000000000000..eb7db27313646 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_interactive_execute_on_repr/duckdb/out.sql @@ -0,0 +1,3 @@ +SELECT + SUM(t0.bigint_col) AS "Sum(bigint_col)" +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_respect_set_limit/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_respect_set_limit/clickhouse/out.sql new file mode 100644 index 0000000000000..88b2af3a2cc39 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_respect_set_limit/clickhouse/out.sql @@ -0,0 +1,10 @@ +SELECT + * +FROM ( + SELECT + t0.id, + t0.bool_col + FROM functional_alltypes AS t0 + LIMIT 10 +) AS t2 +LIMIT 11 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_interactive/test_respect_set_limit/duckdb/out.sql b/ibis/backends/tests/snapshots/test_interactive/test_respect_set_limit/duckdb/out.sql new file mode 100644 index 0000000000000..88b2af3a2cc39 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_interactive/test_respect_set_limit/duckdb/out.sql @@ -0,0 +1,10 @@ +SELECT + * +FROM ( + SELECT + t0.id, + t0.bool_col + FROM functional_alltypes AS t0 + LIMIT 10 +) AS t2 +LIMIT 11 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_isin_bug/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_sql/test_isin_bug/clickhouse/out.sql index 986701fa646ea..cd122964c87e3 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_isin_bug/clickhouse/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_isin_bug/clickhouse/out.sql @@ -1,9 +1,9 @@ SELECT - t0.x IN (( + t0.x IN ( SELECT - t0.x AS x + t0.x FROM t AS t0 WHERE t0.x > 2 - )) AS "InSubquery(x)" + ) AS "InSubquery(x)" FROM t AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_isin_bug/duckdb/out.sql b/ibis/backends/tests/snapshots/test_sql/test_isin_bug/duckdb/out.sql index 7b8c77fc31e87..dd1d25118977b 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_isin_bug/duckdb/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_isin_bug/duckdb/out.sql @@ -1,9 +1,9 @@ SELECT - t0.x IN (( + t0.x IN ( SELECT - t0.x AS x + t0.x FROM t AS t0 WHERE t0.x > CAST(2 AS TINYINT) - )) AS "InSubquery(x)" + ) AS "InSubquery(x)" FROM t AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql index e2cd68f4d9a35..8962d00fdabe8 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql @@ -1,37 +1,37 @@ SELECT - t10.field_of_study AS field_of_study, - t10.diff AS diff + t10.field_of_study, + t10.diff FROM ( SELECT - t5.field_of_study AS field_of_study, - t5.diff AS diff + t5.field_of_study, + t5.diff FROM ( SELECT - t4.field_of_study AS field_of_study, + t4.field_of_study, any(t4.diff) AS diff FROM ( SELECT - t3.field_of_study AS field_of_study, - t3.years AS years, - t3.degrees AS degrees, - t3.earliest_degrees AS earliest_degrees, - t3.latest_degrees AS latest_degrees, + t3.field_of_study, + t3.years, + t3.degrees, + t3.earliest_degrees, + t3.latest_degrees, t3.latest_degrees - t3.earliest_degrees AS diff FROM ( SELECT - t2.field_of_study AS field_of_study, - t2.years AS years, - t2.degrees AS degrees, + t2.field_of_study, + t2.years, + t2.degrees, any(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS earliest_degrees, anyLast(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS latest_degrees FROM ( SELECT - t1.field_of_study AS field_of_study, + t1.field_of_study, CAST(t1.__pivoted__.1 AS Nullable(String)) AS years, CAST(t1.__pivoted__.2 AS Nullable(Int64)) AS degrees FROM ( SELECT - t0.field_of_study AS field_of_study, + t0.field_of_study, arrayJoin( [CAST(tuple('1970-71', t0."1970-71") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1975-76', t0."1975-76") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1980-81', t0."1980-81") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1985-86', t0."1985-86") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1990-91', t0."1990-91") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1995-96', t0."1995-96") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2000-01', t0."2000-01") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2005-06', t0."2005-06") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2010-11', t0."2010-11") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2011-12', t0."2011-12") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2012-13', t0."2012-13") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2013-14', t0."2013-14") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2014-15', t0."2014-15") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2015-16', t0."2015-16") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2016-17', t0."2016-17") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2017-18', t0."2017-18") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2018-19', t0."2018-19") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2019-20', t0."2019-20") AS Tuple(years Nullable(String), degrees Nullable(Int64)))] ) AS __pivoted__ @@ -48,35 +48,35 @@ FROM ( LIMIT 10 UNION ALL SELECT - t5.field_of_study AS field_of_study, - t5.diff AS diff + t5.field_of_study, + t5.diff FROM ( SELECT - t4.field_of_study AS field_of_study, + t4.field_of_study, any(t4.diff) AS diff FROM ( SELECT - t3.field_of_study AS field_of_study, - t3.years AS years, - t3.degrees AS degrees, - t3.earliest_degrees AS earliest_degrees, - t3.latest_degrees AS latest_degrees, + t3.field_of_study, + t3.years, + t3.degrees, + t3.earliest_degrees, + t3.latest_degrees, t3.latest_degrees - t3.earliest_degrees AS diff FROM ( SELECT - t2.field_of_study AS field_of_study, - t2.years AS years, - t2.degrees AS degrees, + t2.field_of_study, + t2.years, + t2.degrees, any(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS earliest_degrees, anyLast(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS latest_degrees FROM ( SELECT - t1.field_of_study AS field_of_study, + t1.field_of_study, CAST(t1.__pivoted__.1 AS Nullable(String)) AS years, CAST(t1.__pivoted__.2 AS Nullable(Int64)) AS degrees FROM ( SELECT - t0.field_of_study AS field_of_study, + t0.field_of_study, arrayJoin( [CAST(tuple('1970-71', t0."1970-71") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1975-76', t0."1975-76") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1980-81', t0."1980-81") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1985-86', t0."1985-86") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1990-91', t0."1990-91") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('1995-96', t0."1995-96") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2000-01', t0."2000-01") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2005-06', t0."2005-06") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2010-11', t0."2010-11") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2011-12', t0."2011-12") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2012-13', t0."2012-13") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2013-14', t0."2013-14") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2014-15', t0."2014-15") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2015-16', t0."2015-16") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2016-17', t0."2016-17") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2017-18', t0."2017-18") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2018-19', t0."2018-19") AS Tuple(years Nullable(String), degrees Nullable(Int64))), CAST(tuple('2019-20', t0."2019-20") AS Tuple(years Nullable(String), degrees Nullable(Int64)))] ) AS __pivoted__ diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql index 7af0e3831b686..6eaa105c4a491 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql @@ -1,37 +1,37 @@ SELECT - t10.field_of_study AS field_of_study, - t10.diff AS diff + t10.field_of_study, + t10.diff FROM ( SELECT - t5.field_of_study AS field_of_study, - t5.diff AS diff + t5.field_of_study, + t5.diff FROM ( SELECT - t4.field_of_study AS field_of_study, + t4.field_of_study, FIRST(t4.diff) AS diff FROM ( SELECT - t3.field_of_study AS field_of_study, - t3.years AS years, - t3.degrees AS degrees, - t3.earliest_degrees AS earliest_degrees, - t3.latest_degrees AS latest_degrees, + t3.field_of_study, + t3.years, + t3.degrees, + t3.earliest_degrees, + t3.latest_degrees, t3.latest_degrees - t3.earliest_degrees AS diff FROM ( SELECT - t2.field_of_study AS field_of_study, - t2.years AS years, - t2.degrees AS degrees, + t2.field_of_study, + t2.years, + t2.degrees, FIRST(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS earliest_degrees, LAST(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS latest_degrees FROM ( SELECT - t1.field_of_study AS field_of_study, + t1.field_of_study, t1.__pivoted__['years'] AS years, t1.__pivoted__['degrees'] AS degrees FROM ( SELECT - t0.field_of_study AS field_of_study, + t0.field_of_study, UNNEST( [{'years': '1970-71', 'degrees': t0."1970-71"}, {'years': '1975-76', 'degrees': t0."1975-76"}, {'years': '1980-81', 'degrees': t0."1980-81"}, {'years': '1985-86', 'degrees': t0."1985-86"}, {'years': '1990-91', 'degrees': t0."1990-91"}, {'years': '1995-96', 'degrees': t0."1995-96"}, {'years': '2000-01', 'degrees': t0."2000-01"}, {'years': '2005-06', 'degrees': t0."2005-06"}, {'years': '2010-11', 'degrees': t0."2010-11"}, {'years': '2011-12', 'degrees': t0."2011-12"}, {'years': '2012-13', 'degrees': t0."2012-13"}, {'years': '2013-14', 'degrees': t0."2013-14"}, {'years': '2014-15', 'degrees': t0."2014-15"}, {'years': '2015-16', 'degrees': t0."2015-16"}, {'years': '2016-17', 'degrees': t0."2016-17"}, {'years': '2017-18', 'degrees': t0."2017-18"}, {'years': '2018-19', 'degrees': t0."2018-19"}, {'years': '2019-20', 'degrees': t0."2019-20"}] ) AS __pivoted__ @@ -48,35 +48,35 @@ FROM ( LIMIT 10 UNION ALL SELECT - t5.field_of_study AS field_of_study, - t5.diff AS diff + t5.field_of_study, + t5.diff FROM ( SELECT - t4.field_of_study AS field_of_study, + t4.field_of_study, FIRST(t4.diff) AS diff FROM ( SELECT - t3.field_of_study AS field_of_study, - t3.years AS years, - t3.degrees AS degrees, - t3.earliest_degrees AS earliest_degrees, - t3.latest_degrees AS latest_degrees, + t3.field_of_study, + t3.years, + t3.degrees, + t3.earliest_degrees, + t3.latest_degrees, t3.latest_degrees - t3.earliest_degrees AS diff FROM ( SELECT - t2.field_of_study AS field_of_study, - t2.years AS years, - t2.degrees AS degrees, + t2.field_of_study, + t2.years, + t2.degrees, FIRST(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS earliest_degrees, LAST(t2.degrees) OVER (PARTITION BY t2.field_of_study ORDER BY t2.years ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS latest_degrees FROM ( SELECT - t1.field_of_study AS field_of_study, + t1.field_of_study, t1.__pivoted__['years'] AS years, t1.__pivoted__['degrees'] AS degrees FROM ( SELECT - t0.field_of_study AS field_of_study, + t0.field_of_study, UNNEST( [{'years': '1970-71', 'degrees': t0."1970-71"}, {'years': '1975-76', 'degrees': t0."1975-76"}, {'years': '1980-81', 'degrees': t0."1980-81"}, {'years': '1985-86', 'degrees': t0."1985-86"}, {'years': '1990-91', 'degrees': t0."1990-91"}, {'years': '1995-96', 'degrees': t0."1995-96"}, {'years': '2000-01', 'degrees': t0."2000-01"}, {'years': '2005-06', 'degrees': t0."2005-06"}, {'years': '2010-11', 'degrees': t0."2010-11"}, {'years': '2011-12', 'degrees': t0."2011-12"}, {'years': '2012-13', 'degrees': t0."2012-13"}, {'years': '2013-14', 'degrees': t0."2013-14"}, {'years': '2014-15', 'degrees': t0."2014-15"}, {'years': '2015-16', 'degrees': t0."2015-16"}, {'years': '2016-17', 'degrees': t0."2016-17"}, {'years': '2017-18', 'degrees': t0."2017-18"}, {'years': '2018-19', 'degrees': t0."2018-19"}, {'years': '2019-20', 'degrees': t0."2019-20"}] ) AS __pivoted__ diff --git a/ibis/backends/tests/sql/conftest.py b/ibis/backends/tests/sql/conftest.py index 2fd23ed45cb37..04667e60e033b 100644 --- a/ibis/backends/tests/sql/conftest.py +++ b/ibis/backends/tests/sql/conftest.py @@ -1,14 +1,9 @@ from __future__ import annotations import pytest -import sqlglot as sg import ibis - -pytest.importorskip("duckdb") - -from ibis.backends.duckdb import Backend as DuckDBBackend # noqa: E402 -from ibis.tests.expr.mocks import MockBackend # noqa: E402 +from ibis.tests.expr.mocks import MockBackend @pytest.fixture(scope="module") @@ -72,16 +67,8 @@ def bar_t(con): def to_sql(expr, *args, **kwargs) -> str: - if args: - raise TypeError("Unexpected positional arguments") - if kwargs: - raise TypeError("Unexpected keyword arguments") - - sql = DuckDBBackend.compiler.translate(expr.op(), params={}) - if isinstance(sql, sg.exp.Table): - sql = sg.select("*").from_(sql) - - return sql.sql(dialect="duckdb", pretty=True) + pytest.importorskip("duckdb") + return str(ibis.to_sql(expr, *args, dialect="duckdb", **kwargs)) @pytest.fixture(scope="module") diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_and_non_agg_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_and_non_agg_filter/out.sql index f93e098292e7f..4a8b9ef4cb44a 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_and_non_agg_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_and_non_agg_filter/out.sql @@ -1,9 +1,19 @@ -SELECT t0.* -FROM my_table t0 -WHERE (t0.`a` < 100) AND - (t0.`a` = ( - SELECT max(t0.`a`) AS `Max(a)` - FROM my_table t0 - WHERE t0.`a` < 100 -)) AND - (t0.`b` = 'a') \ No newline at end of file +SELECT + t0.a, + t0.b +FROM my_table AS t0 +WHERE + t0.a < CAST(100 AS TINYINT) + AND t0.a = ( + SELECT + MAX(t1.a) AS "Max(a)" + FROM ( + SELECT + t0.a, + t0.b + FROM my_table AS t0 + WHERE + t0.a < CAST(100 AS TINYINT) + ) AS t1 + ) + AND t0.b = 'a' \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter/out.sql index 631a18bd42537..37c5668f835b7 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter/out.sql @@ -1,11 +1,18 @@ -WITH t0 AS ( - SELECT t1.*, t1.`b` * 2 AS `b2` - FROM my_table t1 -) -SELECT t0.`a`, t0.`b2` -FROM t0 -WHERE (t0.`a` < 100) AND - (t0.`a` = ( - SELECT max(t0.`a`) AS `Max(a)` - FROM t0 -)) \ No newline at end of file +SELECT + t0.a, + t0.b * CAST(2 AS TINYINT) AS b2 +FROM my_table AS t0 +WHERE + t0.a < CAST(100 AS TINYINT) + AND t0.a = ( + SELECT + MAX(t1.a) AS "Max(a)" + FROM ( + SELECT + t0.a, + t0.b * CAST(2 AS TINYINT) AS b2 + FROM my_table AS t0 + WHERE + t0.a < CAST(100 AS TINYINT) + ) AS t1 + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter_with_alias/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter_with_alias/out.sql index 631a18bd42537..37c5668f835b7 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter_with_alias/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_agg_filter_with_alias/out.sql @@ -1,11 +1,18 @@ -WITH t0 AS ( - SELECT t1.*, t1.`b` * 2 AS `b2` - FROM my_table t1 -) -SELECT t0.`a`, t0.`b2` -FROM t0 -WHERE (t0.`a` < 100) AND - (t0.`a` = ( - SELECT max(t0.`a`) AS `Max(a)` - FROM t0 -)) \ No newline at end of file +SELECT + t0.a, + t0.b * CAST(2 AS TINYINT) AS b2 +FROM my_table AS t0 +WHERE + t0.a < CAST(100 AS TINYINT) + AND t0.a = ( + SELECT + MAX(t1.a) AS "Max(a)" + FROM ( + SELECT + t0.a, + t0.b * CAST(2 AS TINYINT) AS b2 + FROM my_table AS t0 + WHERE + t0.a < CAST(100 AS TINYINT) + ) AS t1 + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_column_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_column_distinct/out.sql index 636796e7e04d6..d38aa10366c46 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_column_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_column_distinct/out.sql @@ -2,6 +2,6 @@ SELECT DISTINCT * FROM ( SELECT - t0.string_col AS string_col + t0.string_col FROM functional_alltypes AS t0 ) AS t1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_default_name/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_default_name/out.sql index 2bdab32a6fc21..1e1635a607bfb 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_default_name/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_default_name/out.sql @@ -1 +1,3 @@ -t0.int_col + CAST(4 AS TINYINT) \ No newline at end of file +SELECT + t0.int_col + CAST(4 AS TINYINT) AS "Add(int_col, 4)" +FROM int_col_table AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_retains_name/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_retains_name/out.sql index 20cc4cc3cdbb0..0237f96353c11 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_retains_name/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_column_expr_retains_name/out.sql @@ -1 +1,3 @@ -t0.int_col + CAST(4 AS TINYINT) AS foo \ No newline at end of file +SELECT + t0.int_col + CAST(4 AS TINYINT) AS foo +FROM int_col_table AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_count_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_count_distinct/out.sql index f6bd37af0d2f6..1203afe54f42f 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_count_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_count_distinct/out.sql @@ -1,14 +1,24 @@ SELECT - t1.string_col AS string_col, + t1.string_col, COUNT(DISTINCT t1.int_col) AS nunique FROM ( SELECT - * + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE - ( - t0.bigint_col > CAST(0 AS TINYINT) - ) + t0.bigint_col > CAST(0 AS TINYINT) ) AS t1 GROUP BY 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_difference_project_column/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_difference_project_column/out.sql index f5405266b6565..65eba6a3a4c8d 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_difference_project_column/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_difference_project_column/out.sql @@ -1,29 +1,17 @@ SELECT - t5.key AS key + t3.key FROM ( SELECT - t1.string_col AS key, - CAST(t1.float_col AS DOUBLE) AS value - FROM ( - SELECT - * - FROM functional_alltypes AS t0 - WHERE - ( - t0.int_col > CAST(0 AS TINYINT) - ) - ) AS t1 + t0.string_col AS key, + CAST(t0.float_col AS DOUBLE) AS value + FROM functional_alltypes AS t0 + WHERE + t0.int_col > CAST(0 AS TINYINT) EXCEPT SELECT - t2.string_col AS key, - t2.double_col AS value - FROM ( - SELECT - * - FROM functional_alltypes AS t0 - WHERE - ( - t0.int_col <= CAST(0 AS TINYINT) - ) - ) AS t2 -) AS t5 \ No newline at end of file + t0.string_col AS key, + t0.double_col AS value + FROM functional_alltypes AS t0 + WHERE + t0.int_col <= CAST(0 AS TINYINT) +) AS t3 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/decompiled.py b/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/decompiled.py index aef66c38a37ca..9da80d9792e9d 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/decompiled.py @@ -4,6 +4,6 @@ t = ibis.table(name="t", schema={"a": "int64", "b": "string"}) f = t.filter(t.b == "m") agg = f.aggregate([f.a.sum().name("sum"), f.a.max()], by=[f.b]) -f1 = agg.filter(agg.Max(a) == 2) +f1 = agg.filter(agg["Max(a)"] == 2) result = f1.select(f1.b, f1.sum) diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/out.sql index 0b54445c43ce3..0043337a96eef 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_having_from_filter/out.sql @@ -1,28 +1,21 @@ SELECT - t3.b AS b, - t3.sum AS sum + t2.b, + t2.sum FROM ( SELECT - * + t1.b, + SUM(t1.a) AS sum, + MAX(t1.a) AS "Max(a)" FROM ( SELECT - t1.b AS b, - SUM(t1.a) AS sum, - MAX(t1.a) AS "Max(a)" - FROM ( - SELECT - * - FROM t AS t0 - WHERE - ( - t0.b = 'm' - ) - ) AS t1 - GROUP BY - 1 - ) AS t2 - WHERE - ( - t2."Max(a)" = CAST(2 AS TINYINT) - ) -) AS t3 \ No newline at end of file + t0.a, + t0.b + FROM t AS t0 + WHERE + t0.b = 'm' + ) AS t1 + GROUP BY + 1 +) AS t2 +WHERE + t2."Max(a)" = CAST(2 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_having_size/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_having_size/out.sql index b2dc4a533237d..6691834ce1b51 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_having_size/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_having_size/out.sql @@ -1,20 +1,14 @@ SELECT - t2.string_col AS string_col, - t2."CountStar()" AS "CountStar()" + t1.string_col, + t1."CountStar()" FROM ( SELECT - * - FROM ( - SELECT - t0.string_col AS string_col, - COUNT(*) AS "CountStar()", - MAX(t0.double_col) AS "Max(double_col)" - FROM functional_alltypes AS t0 - GROUP BY - 1 - ) AS t1 - WHERE - ( - t1."Max(double_col)" = CAST(1 AS TINYINT) - ) -) AS t2 \ No newline at end of file + t0.string_col, + COUNT(*) AS "CountStar()", + MAX(t0.double_col) AS "Max(double_col)" + FROM functional_alltypes AS t0 + GROUP BY + 1 +) AS t1 +WHERE + t1."Max(double_col)" = CAST(1 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_intersect_project_column/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_intersect_project_column/out.sql index 382428d10e101..7c3cbc2fdf12d 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_intersect_project_column/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_intersect_project_column/out.sql @@ -1,29 +1,17 @@ SELECT - t5.key AS key + t3.key FROM ( SELECT - t1.string_col AS key, - CAST(t1.float_col AS DOUBLE) AS value - FROM ( - SELECT - * - FROM functional_alltypes AS t0 - WHERE - ( - t0.int_col > CAST(0 AS TINYINT) - ) - ) AS t1 + t0.string_col AS key, + CAST(t0.float_col AS DOUBLE) AS value + FROM functional_alltypes AS t0 + WHERE + t0.int_col > CAST(0 AS TINYINT) INTERSECT SELECT - t2.string_col AS key, - t2.double_col AS value - FROM ( - SELECT - * - FROM functional_alltypes AS t0 - WHERE - ( - t0.int_col <= CAST(0 AS TINYINT) - ) - ) AS t2 -) AS t5 \ No newline at end of file + t0.string_col AS key, + t0.double_col AS value + FROM functional_alltypes AS t0 + WHERE + t0.int_col <= CAST(0 AS TINYINT) +) AS t3 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_multiple_count_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_multiple_count_distinct/out.sql index bcb0a9b1869f6..cbb6ac1079a35 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_multiple_count_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_multiple_count_distinct/out.sql @@ -1,5 +1,5 @@ SELECT - t0.string_col AS string_col, + t0.string_col, COUNT(DISTINCT t0.int_col) AS int_card, COUNT(DISTINCT t0.smallint_col) AS smallint_card FROM functional_alltypes AS t0 diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_pushdown_with_or/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_pushdown_with_or/out.sql index 1fe424dcfbe9f..45fa51a79cba6 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_pushdown_with_or/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_pushdown_with_or/out.sql @@ -1,10 +1,11 @@ SELECT - * + t0.double_col, + t0.string_col, + t0.int_col, + t0.float_col FROM functional_alltypes AS t0 WHERE - ( - t0.double_col > CAST(3.14 AS DOUBLE) - ) + t0.double_col > CAST(3.14 AS DOUBLE) AND CONTAINS(t0.string_col, 'foo') AND ( ( diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_simple_agg_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_simple_agg_filter/out.sql index d0e1564bcf778..c1410ecdac478 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_simple_agg_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_simple_agg_filter/out.sql @@ -1,8 +1,18 @@ -SELECT t0.* -FROM my_table t0 -WHERE (t0.`a` < 100) AND - (t0.`a` = ( - SELECT max(t0.`a`) AS `Max(a)` - FROM my_table t0 - WHERE t0.`a` < 100 -)) \ No newline at end of file +SELECT + t0.a, + t0.b +FROM my_table AS t0 +WHERE + t0.a < CAST(100 AS TINYINT) + AND t0.a = ( + SELECT + MAX(t1.a) AS "Max(a)" + FROM ( + SELECT + t0.a, + t0.b + FROM my_table AS t0 + WHERE + t0.a < CAST(100 AS TINYINT) + ) AS t1 + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/decompiled.py b/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/decompiled.py index a18437fa4d101..aef3bd85e8097 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/decompiled.py @@ -11,9 +11,7 @@ }, ) param = ibis.param("timestamp") -proj = alltypes.select( - [alltypes.float_col, alltypes.timestamp_col, alltypes.int_col, alltypes.string_col] -).filter(alltypes.timestamp_col < param.name("my_param")) -agg = proj.group_by(proj.string_col).aggregate(proj.float_col.sum().name("foo")) +f = alltypes.filter(alltypes.timestamp_col < param.name("my_param")) +agg = f.aggregate([f.float_col.sum().name("foo")], by=[f.string_col]) result = agg.foo.count() diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/out.sql index 40f4523b6453f..7ceaa3d33e796 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_subquery_where_location/out.sql @@ -1,11 +1,19 @@ -WITH t0 AS ( - SELECT t2.`float_col`, t2.`timestamp_col`, t2.`int_col`, t2.`string_col` - FROM alltypes t2 - WHERE t2.`timestamp_col` < '2014-01-01T00:00:00' -) -SELECT count(t1.`foo`) AS `Count(foo)` +SELECT + COUNT(t2.foo) AS "Count(foo)" FROM ( - SELECT t0.`string_col`, sum(t0.`float_col`) AS `foo` - FROM t0 - GROUP BY 1 -) t1 \ No newline at end of file + SELECT + t1.string_col, + SUM(t1.float_col) AS foo + FROM ( + SELECT + t0.float_col, + t0.timestamp_col, + t0.int_col, + t0.string_col + FROM alltypes AS t0 + WHERE + t0.timestamp_col < MAKE_TIMESTAMP(2014, 1, 1, 0, 0, 0.0) + ) AS t1 + GROUP BY + 1 +) AS t2 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql index d0a0f1a458c6a..4d00f47c36b00 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql @@ -1,25 +1,18 @@ SELECT - t1.string_col AS key, - CAST(t1.float_col AS DOUBLE) AS value + t3.key, + t3.value FROM ( SELECT - * + t0.string_col AS key, + CAST(t0.float_col AS DOUBLE) AS value FROM functional_alltypes AS t0 WHERE - ( - t0.int_col > CAST(0 AS TINYINT) - ) -) AS t1 -EXCEPT -SELECT - t2.string_col AS key, - t2.double_col AS value -FROM ( + t0.int_col > CAST(0 AS TINYINT) + EXCEPT SELECT - * + t0.string_col AS key, + t0.double_col AS value FROM functional_alltypes AS t0 WHERE - ( - t0.int_col <= CAST(0 AS TINYINT) - ) -) AS t2 \ No newline at end of file + t0.int_col <= CAST(0 AS TINYINT) +) AS t3 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/decompiled.py b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/decompiled.py index 3b35a0e24ef25..76016cf2fc5fb 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/decompiled.py @@ -21,5 +21,5 @@ ) result = functional_alltypes.select( - [functional_alltypes.string_col, functional_alltypes.int_col] + functional_alltypes.string_col, functional_alltypes.int_col ).distinct() diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/out.sql index f98b3697b64fb..483b4fef6f492 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_distinct/out.sql @@ -2,7 +2,7 @@ SELECT DISTINCT * FROM ( SELECT - t0.string_col AS string_col, - t0.int_col AS int_col + t0.string_col, + t0.int_col FROM functional_alltypes AS t0 ) AS t1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/decompiled.py b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/decompiled.py index 51188cc25f4e2..143198197ad60 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/decompiled.py @@ -5,7 +5,10 @@ s = ibis.table(name="s", schema={"b": "string"}) t = ibis.table(name="t", schema={"a": "int64", "b": "string", "c": "timestamp"}) f = t.filter(t.c == lit) -p = f.select(f.a, f.b, lit.name("the_date")) -joinchain = p.inner_join(s, p.b == s.b) +joinchain = ( + f.select(f.a, f.b, lit.name("the_date")) + .inner_join(s, f.select(f.a, f.b, lit.name("the_date")).b == s.b) + .select(f.select(f.a, f.b, lit.name("the_date")).a) +) result = joinchain.filter(joinchain.a < 1.0) diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/out.sql index f1828ac4c2f5f..bf3eedb03752e 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_drop_with_filter/out.sql @@ -1,27 +1,19 @@ SELECT - * + t6.a FROM ( SELECT - t3.a AS a + t4.a FROM ( SELECT - t2.a AS a, - t2.b AS b, + t0.a, + t0.b, MAKE_TIMESTAMP(2018, 1, 1, 0, 0, 0.0) AS the_date - FROM ( - SELECT - * - FROM t AS t1 - WHERE - ( - t1.c = MAKE_TIMESTAMP(2018, 1, 1, 0, 0, 0.0) - ) - ) AS t2 - ) AS t3 - INNER JOIN s AS t0 - ON t3.b = t0.b -) AS t5 + FROM t AS t0 + WHERE + t0.c = MAKE_TIMESTAMP(2018, 1, 1, 0, 0, 0.0) + ) AS t4 + INNER JOIN s AS t2 + ON t4.b = t2.b +) AS t6 WHERE - ( - t5.a < CAST(1.0 AS DOUBLE) - ) \ No newline at end of file + t6.a < CAST(1.0 AS DOUBLE) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql index a1a843860bae6..72a05ef24e92d 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql @@ -1,25 +1,18 @@ SELECT - t1.string_col AS key, - CAST(t1.float_col AS DOUBLE) AS value + t3.key, + t3.value FROM ( SELECT - * + t0.string_col AS key, + CAST(t0.float_col AS DOUBLE) AS value FROM functional_alltypes AS t0 WHERE - ( - t0.int_col > CAST(0 AS TINYINT) - ) -) AS t1 -INTERSECT -SELECT - t2.string_col AS key, - t2.double_col AS value -FROM ( + t0.int_col > CAST(0 AS TINYINT) + INTERSECT SELECT - * + t0.string_col AS key, + t0.double_col AS value FROM functional_alltypes AS t0 WHERE - ( - t0.int_col <= CAST(0 AS TINYINT) - ) -) AS t2 \ No newline at end of file + t0.int_col <= CAST(0 AS TINYINT) +) AS t3 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql index fe2052bf4317f..0bf62fa423da4 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql @@ -1,25 +1,18 @@ SELECT - t1.string_col AS key, - CAST(t1.float_col AS DOUBLE) AS value + t3.key, + t3.value FROM ( SELECT - * + t0.string_col AS key, + CAST(t0.float_col AS DOUBLE) AS value FROM functional_alltypes AS t0 WHERE - ( - t0.int_col > CAST(0 AS TINYINT) - ) -) AS t1 -UNION -SELECT - t2.string_col AS key, - t2.double_col AS value -FROM ( + t0.int_col > CAST(0 AS TINYINT) + UNION SELECT - * + t0.string_col AS key, + t0.double_col AS value FROM functional_alltypes AS t0 WHERE - ( - t0.int_col <= CAST(0 AS TINYINT) - ) -) AS t2 \ No newline at end of file + t0.int_col <= CAST(0 AS TINYINT) +) AS t3 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql index 9380eee82c2ae..dda59184ba536 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql @@ -1,11 +1,18 @@ SELECT - * -FROM t AS t0 -ORDER BY - t0.b ASC -UNION ALL -SELECT - * -FROM t AS t0 -ORDER BY - t0.b ASC \ No newline at end of file + t2.a, + t2.b +FROM ( + SELECT + t0.a, + t0.b + FROM t AS t0 + ORDER BY + t0.b ASC + UNION ALL + SELECT + t0.a, + t0.b + FROM t AS t0 + ORDER BY + t0.b ASC +) AS t2 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_union_project_column/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_union_project_column/out.sql index 15ac865a88b0a..b2fb8620109b8 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_union_project_column/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_union_project_column/out.sql @@ -1,29 +1,17 @@ SELECT - t5.key AS key + t3.key FROM ( SELECT - t1.string_col AS key, - CAST(t1.float_col AS DOUBLE) AS value - FROM ( - SELECT - * - FROM functional_alltypes AS t0 - WHERE - ( - t0.int_col > CAST(0 AS TINYINT) - ) - ) AS t1 + t0.string_col AS key, + CAST(t0.float_col AS DOUBLE) AS value + FROM functional_alltypes AS t0 + WHERE + t0.int_col > CAST(0 AS TINYINT) UNION ALL SELECT - t2.string_col AS key, - t2.double_col AS value - FROM ( - SELECT - * - FROM functional_alltypes AS t0 - WHERE - ( - t0.int_col <= CAST(0 AS TINYINT) - ) - ) AS t2 -) AS t5 \ No newline at end of file + t0.string_col AS key, + t0.double_col AS value + FROM functional_alltypes AS t0 + WHERE + t0.int_col <= CAST(0 AS TINYINT) +) AS t3 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/decompiled.py index c807087cf1225..2cf13f7c2cc1a 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/decompiled.py @@ -15,6 +15,16 @@ }, ) -result = tpch_region.inner_join( - tpch_nation, tpch_region.r_regionkey == tpch_nation.n_regionkey -).count() +result = ( + tpch_region.inner_join( + tpch_nation, tpch_region.r_regionkey == tpch_nation.n_regionkey + ) + .select( + tpch_nation.n_nationkey, + tpch_nation.n_name, + tpch_nation.n_regionkey, + tpch_nation.n_comment, + tpch_region.r_name.name("region"), + ) + .count() +) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/out.sql index 6407e4987c291..3011cdb409b48 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_count_joined/out.sql @@ -1 +1,13 @@ -COUNT(*) \ No newline at end of file +SELECT + COUNT(*) AS "CountStar()" +FROM ( + SELECT + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment, + t2.r_name AS region + FROM tpch_region AS t2 + INNER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey +) AS t5 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/explicit.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/explicit.sql index 6da69b8c5673b..47945167c00a9 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/explicit.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/explicit.sql @@ -1,14 +1,13 @@ SELECT - * + t1.foo_id, + t1.total FROM ( SELECT - t0.foo_id AS foo_id, + t0.foo_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY 1 ) AS t1 WHERE - ( - t1.total AS total > CAST(10 AS TINYINT) - ) \ No newline at end of file + t1.total > CAST(10 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/inline.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/inline.sql index 214ec1ede144c..35e4fe0adc244 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/inline.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_having/inline.sql @@ -1,20 +1,14 @@ SELECT - t2.foo_id AS foo_id, - t2.total AS total + t1.foo_id, + t1.total FROM ( SELECT - * - FROM ( - SELECT - t0.foo_id AS foo_id, - SUM(t0.f) AS total, - COUNT(*) AS "CountStar()" - FROM star1 AS t0 - GROUP BY - 1 - ) AS t1 - WHERE - ( - t1."CountStar()" > CAST(100 AS TINYINT) - ) -) AS t2 \ No newline at end of file + t0.foo_id, + SUM(t0.f) AS total, + COUNT(*) AS "CountStar()" + FROM star1 AS t0 + GROUP BY + 1 +) AS t1 +WHERE + t1."CountStar()" > CAST(100 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_alias_bug/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_alias_bug/out.sql index 72adf2407ec15..a15f1a8cce7e2 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_alias_bug/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_alias_bug/out.sql @@ -1,16 +1,16 @@ SELECT - t3.foo_id AS foo_id, - SUM(t3.value1) AS total + t5.foo_id, + SUM(t5.value1) AS total FROM ( SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id, - t1.value1 AS value1 - FROM star1 AS t0 - INNER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id -) AS t3 + t2.c, + t2.f, + t2.foo_id, + t2.bar_id, + t3.value1 + FROM star1 AS t2 + INNER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id +) AS t5 GROUP BY 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered.sql index 3304bb7d330b9..82d666c54c3ff 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered.sql @@ -1,31 +1,23 @@ SELECT - t2.g AS g, - SUM(t2.foo) AS "foo total" + t1.g, + SUM(t1.foo) AS "foo total" FROM ( SELECT - t1.a AS a, - t1.b AS b, - t1.c AS c, - t1.d AS d, - t1.e AS e, - t1.f AS f, - t1.g AS g, - t1.h AS h, - t1.i AS i, - t1.j AS j, - t1.k AS k, - t1.a + t1.b AS foo - FROM ( - SELECT - * - FROM alltypes AS t0 - WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) AND ( - t0.g = 'bar' - ) - ) AS t1 -) AS t2 + t0.a, + t0.b, + t0.c, + t0.d, + t0.e, + t0.f, + t0.g, + t0.h, + t0.i, + t0.j, + t0.k, + t0.a + t0.b AS foo + FROM alltypes AS t0 + WHERE + t0.f > CAST(0 AS TINYINT) AND t0.g = 'bar' +) AS t1 GROUP BY - 1 + 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered2.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered2.sql index a2bbff51e021f..32772c5a969d7 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered2.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/agg_filtered2.sql @@ -1,33 +1,25 @@ SELECT - t2.g AS g, - SUM(t2.foo) AS "foo total" + t1.g, + SUM(t1.foo) AS "foo total" FROM ( SELECT - t1.a AS a, - t1.b AS b, - t1.c AS c, - t1.d AS d, - t1.e AS e, - t1.f AS f, - t1.g AS g, - t1.h AS h, - t1.i AS i, - t1.j AS j, - t1.k AS k, - t1.a + t1.b AS foo - FROM ( - SELECT - * - FROM alltypes AS t0 - WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) AND ( - ( - t0.a + t0.b - ) < CAST(10 AS TINYINT) - ) - ) AS t1 -) AS t2 + t0.a, + t0.b, + t0.c, + t0.d, + t0.e, + t0.f, + t0.g, + t0.h, + t0.i, + t0.j, + t0.k, + t0.a + t0.b AS foo + FROM alltypes AS t0 + WHERE + t0.f > CAST(0 AS TINYINT) AND ( + t0.a + t0.b + ) < CAST(10 AS TINYINT) +) AS t1 GROUP BY - 1 + 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/filtered.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/filtered.sql index 4809093f21a02..7407d5fcf78b1 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/filtered.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/filtered.sql @@ -1,24 +1,16 @@ SELECT - t1.a AS a, - t1.b AS b, - t1.c AS c, - t1.d AS d, - t1.e AS e, - t1.f AS f, - t1.g AS g, - t1.h AS h, - t1.i AS i, - t1.j AS j, - t1.k AS k, - t1.a + t1.b AS foo -FROM ( - SELECT - * - FROM alltypes AS t0 - WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) AND ( - t0.g = 'bar' - ) -) AS t1 + t0.a, + t0.b, + t0.c, + t0.d, + t0.e, + t0.f, + t0.g, + t0.h, + t0.i, + t0.j, + t0.k, + t0.a + t0.b AS foo +FROM alltypes AS t0 +WHERE + t0.f > CAST(0 AS TINYINT) AND t0.g = 'bar' \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/proj.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/proj.sql index 0208ce9dfe03c..0917ea29aae14 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/proj.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_aggregate_projection_subquery/proj.sql @@ -1,22 +1,16 @@ SELECT - t1.a AS a, - t1.b AS b, - t1.c AS c, - t1.d AS d, - t1.e AS e, - t1.f AS f, - t1.g AS g, - t1.h AS h, - t1.i AS i, - t1.j AS j, - t1.k AS k, - t1.a + t1.b AS foo -FROM ( - SELECT - * - FROM alltypes AS t0 - WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) -) AS t1 + t0.a, + t0.b, + t0.c, + t0.d, + t0.e, + t0.f, + t0.g, + t0.h, + t0.i, + t0.j, + t0.k, + t0.a + t0.b AS foo +FROM alltypes AS t0 +WHERE + t0.f > CAST(0 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/decompiled.py index 1f1a500887e93..dc83d63276ea3 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/decompiled.py @@ -9,4 +9,6 @@ name="star2", schema={"foo_id": "string", "value1": "float64", "value3": "float64"} ) -result = star1.anti_join(star2, star1.foo_id == star2.foo_id) +result = star1.anti_join(star2, star1.foo_id == star2.foo_id).select( + star1.c, star1.f, star1.foo_id, star1.bar_id +) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/out.sql index 021e6eec101ec..f2ef0d0d3f677 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_anti_join/out.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -ANTI JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id \ No newline at end of file + t2.c, + t2.f, + t2.foo_id, + t2.bar_id +FROM star1 AS t2 +ANTI JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_bool_bool/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_bool_bool/out.sql index fd6b1490e250c..b110ecf4f3b87 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_bool_bool/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_bool_bool/out.sql @@ -1,9 +1,9 @@ SELECT - * + t0.dest, + t0.origin, + t0.arrdelay FROM airlines AS t0 WHERE ( - ( - CAST(t0.dest AS BIGINT) = CAST(0 AS TINYINT) - ) = TRUE - ) \ No newline at end of file + CAST(t0.dest AS BIGINT) = CAST(0 AS TINYINT) + ) = TRUE \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_duplicated_where/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_duplicated_where/out.sql index 59632deb743c3..173b6323b2439 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_duplicated_where/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_duplicated_where/out.sql @@ -1,17 +1,23 @@ -WITH t0 AS ( - SELECT t3.`arrdelay`, t3.`dest` - FROM airlines t3 -), -t1 AS ( - SELECT t0.*, avg(t0.`arrdelay`) OVER (PARTITION BY t0.`dest`) AS `dest_avg`, - t0.`arrdelay` - avg(t0.`arrdelay`) OVER (PARTITION BY t0.`dest`) AS `dev` - FROM t0 -) -SELECT t2.* +SELECT + t2.arrdelay, + t2.dest, + t2.dest_avg, + t2.dev FROM ( - SELECT t1.* - FROM t1 - WHERE t1.`dev` IS NOT NULL -) t2 -ORDER BY t2.`dev` DESC + SELECT + t1.arrdelay, + t1.dest, + AVG(t1.arrdelay) OVER (PARTITION BY t1.dest ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS dest_avg, + t1.arrdelay - AVG(t1.arrdelay) OVER (PARTITION BY t1.dest ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS dev + FROM ( + SELECT + t0.arrdelay, + t0.dest + FROM airlines AS t0 + ) AS t1 +) AS t2 +WHERE + NOT t2.dev IS NULL +ORDER BY + t2.dev DESC LIMIT 10 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_project_multiple_times/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_project_multiple_times/out.sql index fb3f43560215f..88011a4c2cf9a 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_project_multiple_times/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_bug_project_multiple_times/out.sql @@ -1,55 +1,43 @@ SELECT - t5.c_name AS c_name, - t5.r_name AS r_name, - t5.n_name AS n_name -FROM ( - SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t1.n_name AS n_name, - t2.r_name AS r_name - FROM tpch_customer AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.c_nationkey = t1.n_nationkey - INNER JOIN tpch_region AS t2 - ON t1.n_regionkey = t2.r_regionkey -) AS t5 + t3.c_name, + t5.r_name, + t4.n_name +FROM tpch_customer AS t3 +INNER JOIN tpch_nation AS t4 + ON t3.c_nationkey = t4.n_nationkey +INNER JOIN tpch_region AS t5 + ON t4.n_regionkey = t5.r_regionkey SEMI JOIN ( SELECT - * + t9.n_name, + t9."Sum(Cast(c_acctbal, float64))" FROM ( SELECT - t5.n_name AS n_name, - SUM(CAST(t5.c_acctbal AS DOUBLE)) AS "Sum(Cast(c_acctbal, float64))" + t8.n_name, + SUM(CAST(t8.c_acctbal AS DOUBLE)) AS "Sum(Cast(c_acctbal, float64))" FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t1.n_name AS n_name, - t2.r_name AS r_name - FROM tpch_customer AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.c_nationkey = t1.n_nationkey - INNER JOIN tpch_region AS t2 - ON t1.n_regionkey = t2.r_regionkey - ) AS t5 + t3.c_custkey, + t3.c_name, + t3.c_address, + t3.c_nationkey, + t3.c_phone, + t3.c_acctbal, + t3.c_mktsegment, + t3.c_comment, + t4.n_name, + t5.r_name + FROM tpch_customer AS t3 + INNER JOIN tpch_nation AS t4 + ON t3.c_nationkey = t4.n_nationkey + INNER JOIN tpch_region AS t5 + ON t4.n_regionkey = t5.r_regionkey + ) AS t8 GROUP BY 1 - ) AS t6 + ) AS t9 ORDER BY - t6."Sum(Cast(c_acctbal, float64))" DESC + t9."Sum(Cast(c_acctbal, float64))" DESC LIMIT 10 -) AS t8 - ON t5.n_name = t8.n_name \ No newline at end of file +) AS t12 + ON t4.n_name = t12.n_name \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_case_in_projection/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_case_in_projection/out.sql index 03a2bfc76996e..4b25c0cd6d1e6 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_case_in_projection/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_case_in_projection/out.sql @@ -7,15 +7,15 @@ SELECT THEN t0.g ELSE CAST(NULL AS TEXT) END AS col2, - t0.a AS a, - t0.b AS b, - t0.c AS c, - t0.d AS d, - t0.e AS e, - t0.f AS f, - t0.g AS g, - t0.h AS h, - t0.i AS i, - t0.j AS j, - t0.k AS k + t0.a, + t0.b, + t0.c, + t0.d, + t0.e, + t0.f, + t0.g, + t0.h, + t0.i, + t0.j, + t0.k FROM alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_chain_limit_doesnt_collapse/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_chain_limit_doesnt_collapse/result.sql index 48625bcc8a00f..df7349fd3de02 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_chain_limit_doesnt_collapse/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_chain_limit_doesnt_collapse/result.sql @@ -2,10 +2,11 @@ SELECT * FROM ( SELECT - * + t1.city, + t1."Count(city)" FROM ( SELECT - t0.city AS city, + t0.city, COUNT(t0.city) AS "Count(city)" FROM tbl AS t0 GROUP BY @@ -21,10 +22,11 @@ OFFSET ( COUNT(*) + CAST(-5 AS TINYINT) FROM ( SELECT - * + t1.city, + t1."Count(city)" FROM ( SELECT - t0.city AS city, + t0.city, COUNT(t0.city) AS "Count(city)" FROM tbl AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql index fe43159d7cacf..57f027a897ecb 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql @@ -1,9 +1,14 @@ SELECT - CAST(t0.diag + CAST(1 AS TINYINT) AS INT) AS diag, - t0.status AS status -FROM aids2_one AS t0 -UNION ALL -SELECT - CAST(t1.diag + CAST(1 AS TINYINT) AS INT) AS diag, - t1.status AS status -FROM aids2_two AS t1 \ No newline at end of file + t4.diag, + t4.status +FROM ( + SELECT + CAST(t0.diag + CAST(1 AS TINYINT) AS INT) AS diag, + t0.status + FROM aids2_one AS t0 + UNION ALL + SELECT + CAST(t1.diag + CAST(1 AS TINYINT) AS INT) AS diag, + t1.status + FROM aids2_two AS t1 +) AS t4 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_double_nested_subquery_no_aliases/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_double_nested_subquery_no_aliases/out.sql index 720c3146efdf8..6578a858c971a 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_double_nested_subquery_no_aliases/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_double_nested_subquery_no_aliases/out.sql @@ -1,16 +1,16 @@ SELECT - t2.key1 AS key1, + t2.key1, SUM(t2.total) AS total FROM ( SELECT - t1.key1 AS key1, - t1.key2 AS key2, + t1.key1, + t1.key2, SUM(t1.total) AS total FROM ( SELECT - t0.key1 AS key1, - t0.key2 AS key2, - t0.key3 AS key3, + t0.key1, + t0.key2, + t0.key3, SUM(t0.value) AS total FROM foo_table AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/decompiled.py index a4ca0e75b9207..23f7c5d416017 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/decompiled.py @@ -1,11 +1,9 @@ import ibis -result = ( - ibis.table( - name="star1", - schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, - ) - .foo_id.endswith(ibis.literal("foo")) - .name("tmp") +star1 = ibis.table( + name="star1", + schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, ) + +result = star1.foo_id.endswith(ibis.literal("foo")).name("tmp") diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/out.sql index a7b8c0e5c1851..8114e54d36955 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_endswith/out.sql @@ -1 +1,3 @@ -SUFFIX(t0.foo_id, 'foo') AS tmp \ No newline at end of file +SELECT + SUFFIX(t0.foo_id, 'foo') AS tmp +FROM star1 AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_exists_subquery/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_exists_subquery/out.sql new file mode 100644 index 0000000000000..89f8c66d24dcd --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_exists_subquery/out.sql @@ -0,0 +1,13 @@ +SELECT + t0.key1, + t0.key2, + t0.value1 +FROM t1 AS t0 +WHERE + EXISTS( + SELECT + CAST(1 AS TINYINT) AS "1" + FROM t2 AS t1 + WHERE + t0.key1 = t1.key1 + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_inside_exists/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_inside_exists/out.sql index 1ca28225ea6ae..bffa5a6720b02 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_inside_exists/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_inside_exists/out.sql @@ -1,21 +1,14 @@ SELECT - * + t0.session_id, + t0.user_id, + t0.event_type, + t0.ts FROM events AS t0 WHERE EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM ( - SELECT - * - FROM purchases AS t1 - WHERE - ( - t1.ts > '2015-08-15' - ) AND ( - t0.user_id = t1.user_id - ) - ) AS t2 - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM purchases AS t1 + WHERE + t1.ts > '2015-08-15' AND t0.user_id = t1.user_id ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_predicates/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_predicates/out.sql index fbd2b7d3c76df..fb4bf6a1c3fff 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_predicates/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_predicates/out.sql @@ -1,7 +1,7 @@ SELECT - * + t0.color FROM t AS t0 WHERE LOWER(t0.color) LIKE '%de%' AND CONTAINS(LOWER(t0.color), 'de') - AND REGEXP_MATCHES(LOWER(t0.color), '.*ge.*', 's') + AND REGEXP_MATCHES(LOWER(t0.color), '.*ge.*', 's') \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_self_join_analysis_bug/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_self_join_analysis_bug/result.sql index 1ad66bd2d42ed..2bdce97b5fa2e 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_self_join_analysis_bug/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_self_join_analysis_bug/result.sql @@ -1,13 +1,15 @@ SELECT - t2.region AS region, - t2.total - t3.total AS diff + t4.region, + t4.total - t5.total AS diff FROM ( SELECT - * + t1.region, + t1.kind, + t1.total FROM ( SELECT - t0.region AS region, - t0.kind AS kind, + t0.region, + t0.kind, SUM(t0.amount) AS total FROM purchases AS t0 GROUP BY @@ -15,17 +17,17 @@ FROM ( 2 ) AS t1 WHERE - ( - t1.kind = 'foo' - ) -) AS t2 + t1.kind = 'foo' +) AS t4 INNER JOIN ( SELECT - * + t1.region, + t1.kind, + t1.total FROM ( SELECT - t0.region AS region, - t0.kind AS kind, + t0.region, + t0.kind, SUM(t0.amount) AS total FROM purchases AS t0 GROUP BY @@ -33,8 +35,6 @@ INNER JOIN ( 2 ) AS t1 WHERE - ( - t1.kind = 'bar' - ) -) AS t3 - ON t2.region = t3.region \ No newline at end of file + t1.kind = 'bar' +) AS t5 + ON t4.region = t5.region \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr3.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr3.sql index 5cb4f21a3d2ce..4f1205ba038e9 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr3.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr3.sql @@ -1,21 +1,23 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > LN( - ( + t0.f > LN( + ( + SELECT + AVG(t1.f) AS "Mean(f)" + FROM ( SELECT - AVG(t1.f) AS "Mean(f)" - FROM ( - SELECT - * - FROM star1 AS t0 - WHERE - ( - t0.foo_id = 'foo' - ) - ) AS t1 - ) + t0.c, + t0.f, + t0.foo_id, + t0.bar_id + FROM star1 AS t0 + WHERE + t0.foo_id = 'foo' + ) AS t1 ) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr4.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr4.sql index 4c5fa610555f2..640d7f8d09a40 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr4.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_filter_subquery_derived_reduction/expr4.sql @@ -1,23 +1,25 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > ( - LN( - ( + t0.f > ( + LN( + ( + SELECT + AVG(t1.f) AS "Mean(f)" + FROM ( SELECT - AVG(t1.f) AS "Mean(f)" - FROM ( - SELECT - * - FROM star1 AS t0 - WHERE - ( - t0.foo_id = 'foo' - ) - ) AS t1 - ) - ) + CAST(1 AS TINYINT) - ) + t0.c, + t0.f, + t0.foo_id, + t0.bar_id + FROM star1 AS t0 + WHERE + t0.foo_id = 'foo' + ) AS t1 + ) + ) + CAST(1 AS TINYINT) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/decompiled.py index 0d2f6cdef48c1..37d25bd80aba2 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/decompiled.py @@ -4,11 +4,8 @@ tbl = ibis.table( name="tbl", schema={"foo": "int32", "bar": "int64", "value": "float64"} ) -alias = (tbl.foo + tbl.bar).name("baz") -proj = tbl.select([tbl, alias]) +f = tbl.filter(tbl.value > 0) -result = ( - tbl.select([tbl, alias]) - .filter(tbl.value > 0) - .select([proj, (proj.foo * 2).name("qux")]) +result = f.select( + f.foo, f.bar, f.value, (f.foo + f.bar).name("baz"), (f.foo * 2).name("qux") ) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project.sql index 6ddb56dc6476e..bc1d0cc451184 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project.sql @@ -1,7 +1,7 @@ SELECT - t0.foo AS foo, - t0.bar AS bar, - t0.value AS value, + t0.foo, + t0.bar, + t0.value, t0.foo + t0.bar AS baz, t0.foo * CAST(2 AS TINYINT) AS qux FROM tbl AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project_filter.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project_filter.sql index 8383b5c79c8ae..4f8cda85cc5c1 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project_filter.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_fuse_projections/project_filter.sql @@ -1,15 +1,9 @@ SELECT - t1.foo AS foo, - t1.bar AS bar, - t1.value AS value, - t1.foo + t1.bar AS baz, - t1.foo * CAST(2 AS TINYINT) AS qux -FROM ( - SELECT - * - FROM tbl AS t0 - WHERE - ( - t0.value > CAST(0 AS TINYINT) - ) -) AS t1 \ No newline at end of file + t0.foo, + t0.bar, + t0.value, + t0.foo + t0.bar AS baz, + t0.foo * CAST(2 AS TINYINT) AS qux +FROM tbl AS t0 +WHERE + t0.value > CAST(0 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown/result.sql index 73d0a7bfd20c5..dc33ad4a62ff1 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown/result.sql @@ -1,13 +1,7 @@ SELECT - t1.x + CAST(1 AS TINYINT) AS x -FROM ( - SELECT - * - FROM t AS t0 - WHERE - ( - ( - t0.x + CAST(1 AS TINYINT) - ) > CAST(1 AS TINYINT) - ) -) AS t1 \ No newline at end of file + t0.x + CAST(1 AS TINYINT) AS x +FROM t AS t0 +WHERE + ( + t0.x + CAST(1 AS TINYINT) + ) > CAST(1 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown_with_literal/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown_with_literal/result.sql index b8ceefcb67c91..2fd5fe2ddc07b 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown_with_literal/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_incorrect_predicate_pushdown_with_literal/result.sql @@ -1,11 +1,5 @@ SELECT CAST(1 AS TINYINT) AS a -FROM ( - SELECT - * - FROM t AS t0 - WHERE - ( - CAST(1 AS TINYINT) > CAST(1 AS TINYINT) - ) -) AS t1 \ No newline at end of file +FROM t AS t0 +WHERE + CAST(1 AS TINYINT) > CAST(1 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/decompiled.py index 029cc24d6008c..ce3143f2e407f 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/decompiled.py @@ -9,7 +9,28 @@ name="third", schema={"key2": "string", "key3": "string", "value3": "float64"} ) fourth = ibis.table(name="fourth", schema={"key3": "string", "value4": "float64"}) -joinchain = first.inner_join(second, first.key1 == second.key1) -joinchain1 = third.inner_join(fourth, third.key3 == fourth.key3) -result = joinchain.inner_join(joinchain1, joinchain.key2 == joinchain1.key2) +result = ( + first.inner_join(second, first.key1 == second.key1) + .inner_join( + third.inner_join(fourth, third.key3 == fourth.key3).select( + third.key2, third.key3, third.value3, fourth.value4 + ), + first.key2 + == third.inner_join(fourth, third.key3 == fourth.key3) + .select(third.key2, third.key3, third.value3, fourth.value4) + .key2, + ) + .select( + first.key1, + first.key2, + first.value1, + second.value2, + third.inner_join(fourth, third.key3 == fourth.key3) + .select(third.key2, third.key3, third.value3, fourth.value4) + .value3, + third.inner_join(fourth, third.key3 == fourth.key3) + .select(third.key2, third.key3, third.value3, fourth.value4) + .value4, + ) +) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/out.sql index 86958930e55ea..a66ce49c2bc52 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_between_joins/out.sql @@ -1,28 +1,21 @@ SELECT - t6.key1 AS key1, - t6.key2 AS key2, - t6.value1 AS value1, - t6.value2 AS value2, - t7.value3 AS value3, - t7.value4 AS value4 -FROM ( - SELECT - t0.key1 AS key1, - t0.key2 AS key2, - t0.value1 AS value1, - t1.value2 AS value2 - FROM first AS t0 - INNER JOIN second AS t1 - ON t0.key1 = t1.key1 -) AS t6 + t4.key1, + t4.key2, + t4.value1, + t5.value2, + t11.value3, + t11.value4 +FROM first AS t4 +INNER JOIN second AS t5 + ON t4.key1 = t5.key1 INNER JOIN ( SELECT - t2.key2 AS key2, - t2.key3 AS key3, - t2.value3 AS value3, - t3.value4 AS value4 - FROM third AS t2 - INNER JOIN fourth AS t3 - ON t2.key3 = t3.key3 -) AS t7 - ON t6.key2 = t7.key2 \ No newline at end of file + t6.key2, + t6.key3, + t6.value3, + t7.value4 + FROM third AS t6 + INNER JOIN fourth AS t7 + ON t6.key3 = t7.key3 +) AS t11 + ON t4.key2 = t11.key2 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_filtered_tables_no_pushdown/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_filtered_tables_no_pushdown/out.sql index 6b3adafa9878f..879cd074a3acf 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_filtered_tables_no_pushdown/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_filtered_tables_no_pushdown/out.sql @@ -1,20 +1,28 @@ -WITH t0 AS ( - SELECT t2.* - FROM b t2 - WHERE (t2.`year` = 2016) AND - (t2.`month` = 2) AND - (t2.`day` = 29) -), -t1 AS ( - SELECT t2.* - FROM a t2 - WHERE (t2.`year` = 2016) AND - (t2.`month` = 2) AND - (t2.`day` = 29) -) -SELECT t1.`value_a`, t0.`value_b` -FROM t1 - LEFT OUTER JOIN t0 - ON (t1.`year` = t0.`year`) AND - (t1.`month` = t0.`month`) AND - (t1.`day` = t0.`day`) \ No newline at end of file +SELECT + t4.value_a, + t5.value_b +FROM ( + SELECT + t0.year, + t0.month, + t0.day, + t0.value_a + FROM a AS t0 + WHERE + t0.year = CAST(2016 AS SMALLINT) + AND t0.month = CAST(2 AS TINYINT) + AND t0.day = CAST(29 AS TINYINT) +) AS t4 +LEFT OUTER JOIN ( + SELECT + t1.year, + t1.month, + t1.day, + t1.value_b + FROM b AS t1 + WHERE + t1.year = CAST(2016 AS SMALLINT) + AND t1.month = CAST(2 AS TINYINT) + AND t1.day = CAST(29 AS TINYINT) +) AS t5 + ON t4.year = t5.year AND t4.month = t5.month AND t4.day = t5.day \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/decompiled.py index 44a6ed339c719..e2fefc7e64931 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/decompiled.py @@ -28,6 +28,26 @@ }, ) -result = tpch_nation.inner_join( - tpch_region, tpch_nation.n_regionkey == tpch_region.r_regionkey -).inner_join(tpch_customer, tpch_nation.n_nationkey == tpch_customer.c_nationkey) +result = ( + tpch_nation.inner_join( + tpch_region, tpch_nation.n_regionkey == tpch_region.r_regionkey + ) + .inner_join(tpch_customer, tpch_nation.n_nationkey == tpch_customer.c_nationkey) + .select( + tpch_nation.n_nationkey, + tpch_nation.n_name, + tpch_nation.n_regionkey, + tpch_nation.n_comment, + tpch_region.r_regionkey, + tpch_region.r_name, + tpch_region.r_comment, + tpch_customer.c_custkey, + tpch_customer.c_name, + tpch_customer.c_address, + tpch_customer.c_nationkey, + tpch_customer.c_phone, + tpch_customer.c_acctbal, + tpch_customer.c_mktsegment, + tpch_customer.c_comment, + ) +) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/out.sql index 7d32758ef61c3..28ef4cadbb22e 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_just_materialized/out.sql @@ -1,21 +1,21 @@ SELECT - t0.n_nationkey AS n_nationkey, - t0.n_name AS n_name, - t0.n_regionkey AS n_regionkey, - t0.n_comment AS n_comment, - t1.r_regionkey AS r_regionkey, - t1.r_name AS r_name, - t1.r_comment AS r_comment, - t2.c_custkey AS c_custkey, - t2.c_name AS c_name, - t2.c_address AS c_address, - t2.c_nationkey AS c_nationkey, - t2.c_phone AS c_phone, - t2.c_acctbal AS c_acctbal, - t2.c_mktsegment AS c_mktsegment, - t2.c_comment AS c_comment -FROM tpch_nation AS t0 -INNER JOIN tpch_region AS t1 - ON t0.n_regionkey = t1.r_regionkey -INNER JOIN tpch_customer AS t2 - ON t0.n_nationkey = t2.c_nationkey \ No newline at end of file + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment, + t4.r_regionkey, + t4.r_name, + t4.r_comment, + t5.c_custkey, + t5.c_name, + t5.c_address, + t5.c_nationkey, + t5.c_phone, + t5.c_acctbal, + t5.c_mktsegment, + t5.c_comment +FROM tpch_nation AS t3 +INNER JOIN tpch_region AS t4 + ON t3.n_regionkey = t4.r_regionkey +INNER JOIN tpch_customer AS t5 + ON t3.n_nationkey = t5.c_nationkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_projection_subquery_bug/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_projection_subquery_bug/out.sql index 3d73c83b16db3..ccaf14d422299 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_projection_subquery_bug/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_projection_subquery_bug/out.sql @@ -1,23 +1,17 @@ SELECT - t1.c_custkey AS c_custkey, - t1.c_name AS c_name, - t1.c_address AS c_address, - t1.c_nationkey AS c_nationkey, - t1.c_phone AS c_phone, - t1.c_acctbal AS c_acctbal, - t1.c_mktsegment AS c_mktsegment, - t1.c_comment AS c_comment, - t4.n_nationkey AS n_nationkey, - t4.nation AS nation, - t4.region AS region -FROM ( - SELECT - t0.n_nationkey AS n_nationkey, - t0.n_name AS nation, - t2.r_name AS region - FROM tpch_nation AS t0 - INNER JOIN tpch_region AS t2 - ON t0.n_regionkey = t2.r_regionkey -) AS t4 -INNER JOIN tpch_customer AS t1 - ON t4.n_nationkey = t1.c_nationkey \ No newline at end of file + t5.c_custkey, + t5.c_name, + t5.c_address, + t5.c_nationkey, + t5.c_phone, + t5.c_acctbal, + t5.c_mktsegment, + t5.c_comment, + t3.n_nationkey, + t3.n_name AS nation, + t4.r_name AS region +FROM tpch_nation AS t3 +INNER JOIN tpch_region AS t4 + ON t3.n_regionkey = t4.r_regionkey +INNER JOIN tpch_customer AS t5 + ON t3.n_nationkey = t5.c_nationkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_conditional_aggregate/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_conditional_aggregate/result.sql index fe9f2b5b67f3e..7b3d0ffe12efc 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_conditional_aggregate/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_conditional_aggregate/result.sql @@ -1,23 +1,31 @@ SELECT - t0.on AS on, - t0.by AS by, - t1.on AS on_right, - t1.by AS by_right, - t1.val AS val -FROM left AS t0 -LEFT OUTER JOIN right AS t1 - ON t0.by = t1.by + t6.on, + t6.by, + t6.on_right, + t6.by_right, + t6.val +FROM ( + SELECT + t2.on, + t2.by, + t3.on AS on_right, + t3.by AS by_right, + t3.val + FROM left AS t2 + LEFT OUTER JOIN right AS t3 + ON t2.by = t3.by +) AS t6 WHERE - t1.on = ( + t6.on_right = ( SELECT - MAX(t3.on) AS "Max(on)" + MAX(t4.on) AS "Max(on)" FROM ( SELECT - t1.on AS on, - t1.by AS by, - t1.val AS val + t1.on, + t1.by, + t1.val FROM right AS t1 WHERE t1.by = t0.by AND t1.on <= t0.on - ) AS t3 + ) AS t4 ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_limited_table/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_limited_table/out.sql index 136cb7d2c69dd..1ea81d25a3127 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_limited_table/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_join_with_limited_table/out.sql @@ -1,13 +1,13 @@ SELECT - t2.c AS c, - t2.f AS f, - t2.foo_id AS foo_id, - t2.bar_id AS bar_id + t4.c, + t4.f, + t4.foo_id, + t4.bar_id FROM ( SELECT * FROM star1 AS t0 LIMIT 100 -) AS t2 -INNER JOIN star2 AS t1 - ON t2.foo_id = t1.foo_id \ No newline at end of file +) AS t4 +INNER JOIN star2 AS t3 + ON t4.foo_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_cte_extract/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_cte_extract/out.sql index 6a0ea118caef5..e32be66727648 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_cte_extract/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_cte_extract/out.sql @@ -1,8 +1,27 @@ -WITH t0 AS ( - SELECT t2.* - FROM functional_alltypes t2 +SELECT + t2.id, + t2.bool_col, + t2.tinyint_col, + t2.smallint_col, + t2.int_col, + t2.bigint_col, + t2.float_col, + t2.double_col, + t2.date_string_col, + t2.string_col, + t2.timestamp_col, + t2.year, + t2.month +FROM ( + SELECT + * + FROM functional_alltypes AS t0 LIMIT 100 -) -SELECT t0.* -FROM t0 - INNER JOIN t0 t1 \ No newline at end of file +) AS t2 +INNER JOIN ( + SELECT + * + FROM functional_alltypes AS t0 + LIMIT 100 +) AS t4 + ON TRUE \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/decompiled.py index 80cbfb72f010b..334f4b168218f 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/decompiled.py @@ -27,34 +27,32 @@ functional_alltypes.tinyint_col < selfreference.timestamp_col.minute(), ) .select( - [ - functional_alltypes.id, - functional_alltypes.bool_col, - functional_alltypes.tinyint_col, - functional_alltypes.smallint_col, - functional_alltypes.int_col, - functional_alltypes.bigint_col, - functional_alltypes.float_col, - functional_alltypes.double_col, - functional_alltypes.date_string_col, - functional_alltypes.string_col, - functional_alltypes.timestamp_col, - functional_alltypes.year, - functional_alltypes.month, - selfreference.id.name("id_right"), - selfreference.bool_col.name("bool_col_right"), - selfreference.tinyint_col.name("tinyint_col_right"), - selfreference.smallint_col.name("smallint_col_right"), - selfreference.int_col.name("int_col_right"), - selfreference.bigint_col.name("bigint_col_right"), - selfreference.float_col.name("float_col_right"), - selfreference.double_col.name("double_col_right"), - selfreference.date_string_col.name("date_string_col_right"), - selfreference.string_col.name("string_col_right"), - selfreference.timestamp_col.name("timestamp_col_right"), - selfreference.year.name("year_right"), - selfreference.month.name("month_right"), - ] + functional_alltypes.id, + functional_alltypes.bool_col, + functional_alltypes.tinyint_col, + functional_alltypes.smallint_col, + functional_alltypes.int_col, + functional_alltypes.bigint_col, + functional_alltypes.float_col, + functional_alltypes.double_col, + functional_alltypes.date_string_col, + functional_alltypes.string_col, + functional_alltypes.timestamp_col, + functional_alltypes.year, + functional_alltypes.month, + selfreference.id.name("id_right"), + selfreference.bool_col.name("bool_col_right"), + selfreference.tinyint_col.name("tinyint_col_right"), + selfreference.smallint_col.name("smallint_col_right"), + selfreference.int_col.name("int_col_right"), + selfreference.bigint_col.name("bigint_col_right"), + selfreference.float_col.name("float_col_right"), + selfreference.double_col.name("double_col_right"), + selfreference.date_string_col.name("date_string_col_right"), + selfreference.string_col.name("string_col_right"), + selfreference.timestamp_col.name("timestamp_col_right"), + selfreference.year.name("year_right"), + selfreference.month.name("month_right"), ) .count() ) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/out.sql index 6407e4987c291..26824f377a3ea 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_limit_with_self_join/out.sql @@ -1 +1,34 @@ -COUNT(*) \ No newline at end of file +SELECT + COUNT(*) AS "CountStar()" +FROM ( + SELECT + t1.id, + t1.bool_col, + t1.tinyint_col, + t1.smallint_col, + t1.int_col, + t1.bigint_col, + t1.float_col, + t1.double_col, + t1.date_string_col, + t1.string_col, + t1.timestamp_col, + t1.year, + t1.month, + t3.id AS id_right, + t3.bool_col AS bool_col_right, + t3.tinyint_col AS tinyint_col_right, + t3.smallint_col AS smallint_col_right, + t3.int_col AS int_col_right, + t3.bigint_col AS bigint_col_right, + t3.float_col AS float_col_right, + t3.double_col AS double_col_right, + t3.date_string_col AS date_string_col_right, + t3.string_col AS string_col_right, + t3.timestamp_col AS timestamp_col_right, + t3.year AS year_right, + t3.month AS month_right + FROM functional_alltypes AS t1 + INNER JOIN functional_alltypes AS t3 + ON t1.tinyint_col < EXTRACT('minute' FROM t3.timestamp_col) +) AS t5 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_loj_subquery_filter_handling/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_loj_subquery_filter_handling/out.sql index bf1ecb1da5783..fd5640b69685d 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_loj_subquery_filter_handling/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_loj_subquery_filter_handling/out.sql @@ -1,24 +1,22 @@ SELECT - t2.id AS left_id, - t2.desc AS left_desc, - t3.id AS right_id, - t3.desc AS right_desc + t4.id AS left_id, + t4.desc AS left_desc, + t5.id AS right_id, + t5.desc AS right_desc FROM ( SELECT - * + t0.id, + t0.desc FROM foo AS t0 WHERE - ( - t0.id < CAST(2 AS TINYINT) - ) -) AS t2 + t0.id < CAST(2 AS TINYINT) +) AS t4 LEFT OUTER JOIN ( SELECT - * + t1.id, + t1.desc FROM bar AS t1 WHERE - ( - t1.id < CAST(3 AS TINYINT) - ) -) AS t3 - ON t2.id = t3.id AND t2.desc = t3.desc \ No newline at end of file + t1.id < CAST(3 AS TINYINT) +) AS t5 + ON t4.id = t5.id AND t4.desc = t5.desc \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/decompiled.py index 894f52809414b..00f53b84cbf4d 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/decompiled.py @@ -10,6 +10,8 @@ ) star3 = ibis.table(name="star3", schema={"bar_id": "string", "value2": "float64"}) -result = star1.left_join(star2, star1.foo_id == star2.foo_id).inner_join( - star3, star1.bar_id == star3.bar_id +result = ( + star1.left_join(star2, star1.foo_id == star2.foo_id) + .inner_join(star3, star1.bar_id == star3.bar_id) + .select(star1.c, star1.f, star1.foo_id, star1.bar_id, star2.value1, star3.value2) ) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/out.sql index 79ad2e20002df..4d414f3986974 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_joins/out.sql @@ -1,12 +1,12 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id, - t1.value1 AS value1, - t2.value2 AS value2 -FROM star1 AS t0 -LEFT OUTER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id -INNER JOIN star3 AS t2 - ON t0.bar_id = t2.bar_id \ No newline at end of file + t3.c, + t3.f, + t3.foo_id, + t3.bar_id, + t4.value1, + t5.value2 +FROM star1 AS t3 +LEFT OUTER JOIN star2 AS t4 + ON t3.foo_id = t4.foo_id +INNER JOIN star3 AS t5 + ON t3.bar_id = t5.bar_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/decompiled.py index 3d256c68c24d6..a2704f369e8a5 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/decompiled.py @@ -1,25 +1,23 @@ import ibis -result = ( - ibis.table( - name="functional_alltypes", - schema={ - "id": "int32", - "bool_col": "boolean", - "tinyint_col": "int8", - "smallint_col": "int16", - "int_col": "int32", - "bigint_col": "int64", - "float_col": "float32", - "double_col": "float64", - "date_string_col": "string", - "string_col": "string", - "timestamp_col": "timestamp", - "year": "int32", - "month": "int32", - }, - ) - .limit(20) - .limit(10) +functional_alltypes = ibis.table( + name="functional_alltypes", + schema={ + "id": "int32", + "bool_col": "boolean", + "tinyint_col": "int8", + "smallint_col": "int16", + "int_col": "int32", + "bigint_col": "int64", + "float_col": "float32", + "double_col": "float64", + "date_string_col": "string", + "string_col": "string", + "timestamp_col": "timestamp", + "year": "int32", + "month": "int32", + }, ) + +result = functional_alltypes.limit(20).limit(10) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/out.sql index b88ec7dcdd9d6..7f7d28627c2ff 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_multiple_limits/out.sql @@ -6,4 +6,4 @@ FROM ( FROM functional_alltypes AS t0 LIMIT 20 ) AS t1 -LIMIT 10 +LIMIT 10 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_order_by_on_limit_yield_subquery/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_order_by_on_limit_yield_subquery/out.sql index bbc32482815d3..315083748ef87 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_order_by_on_limit_yield_subquery/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_order_by_on_limit_yield_subquery/out.sql @@ -1,8 +1,9 @@ SELECT - * + t2.string_col, + t2.nrows FROM ( SELECT - t0.string_col AS string_col, + t0.string_col, COUNT(*) AS nrows FROM functional_alltypes AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_projection_filter_fuse/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_projection_filter_fuse/out.sql index ad8215827d467..c93dbd9ab8dc4 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_projection_filter_fuse/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_projection_filter_fuse/out.sql @@ -1,6 +1,7 @@ -SELECT t0.`a`, t0.`b`, t0.`c` -FROM ( - SELECT t1.* - FROM foo t1 - WHERE t1.`a` > 0 -) t0 \ No newline at end of file +SELECT + t0.a, + t0.b, + t0.c +FROM foo AS t0 +WHERE + t0.a > CAST(0 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_scalar_subquery_different_table/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_scalar_subquery_different_table/out.sql index a37945ee2f137..fdc7cf00bcd2c 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_scalar_subquery_different_table/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_scalar_subquery_different_table/out.sql @@ -1,11 +1,12 @@ SELECT - * + t0.job, + t0.dept_id, + t0.year, + t0.y FROM foo AS t0 WHERE - ( - t0.y > ( - SELECT - MAX(t1.x) AS "Max(x)" - FROM bar AS t1 - ) + t0.y > ( + SELECT + MAX(t1.x) AS "Max(x)" + FROM bar AS t1 ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_explicit_column/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_explicit_column/out.sql index 29e72c8336aa5..dbf4aadac2031 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_explicit_column/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_explicit_column/out.sql @@ -1,5 +1,5 @@ SELECT - t0.foo_id AS foo_id, + t0.foo_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_string_columns/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_string_columns/out.sql index 116832bf3c3a7..be9b430bd3d3b 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_string_columns/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/agg_string_columns/out.sql @@ -1,6 +1,6 @@ SELECT - t0.foo_id AS foo_id, - t0.bar_id AS bar_id, + t0.foo_id, + t0.bar_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/decompiled.py index f811fdd901f79..948decc08bfce 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/decompiled.py @@ -1,7 +1,9 @@ import ibis -result = ibis.table( +star1 = ibis.table( name="star1", schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, -).count() +) + +result = star1.count() diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/out.sql index 6407e4987c291..a924af63f39d5 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/aggregate_table_count_metric/out.sql @@ -1 +1,3 @@ -COUNT(*) \ No newline at end of file +SELECT + COUNT(*) AS "CountStar()" +FROM star1 AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/filter_then_limit/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/filter_then_limit/out.sql index ec694656a01b6..31e87b57f3eac 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/filter_then_limit/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/filter_then_limit/out.sql @@ -1,8 +1,9 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) + t0.f > CAST(0 AS TINYINT) LIMIT 10 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_simple/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_simple/decompiled.py index 736a1368dbe5d..3b82e874ef594 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_simple/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_simple/decompiled.py @@ -1,7 +1,9 @@ import ibis -result = ibis.table( +star1 = ibis.table( name="star1", schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, -).limit(10) +) + +result = star1.limit(10) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/decompiled.py index 2767182490a8a..f002a286656dc 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/decompiled.py @@ -1,9 +1,10 @@ import ibis -limit = ibis.table( +star1 = ibis.table( name="star1", schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, -).limit(10) +) +limit = star1.limit(10) result = limit.filter(limit.f > 0) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/out.sql index 431ba054f9f98..ab4dd6df71588 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_then_filter/out.sql @@ -1,5 +1,8 @@ SELECT - * + t1.c, + t1.f, + t1.foo_id, + t1.bar_id FROM ( SELECT * @@ -7,6 +10,4 @@ FROM ( LIMIT 10 ) AS t1 WHERE - ( - t1.f > CAST(0 AS TINYINT) - ) \ No newline at end of file + t1.f > CAST(0 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_with_offset/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_with_offset/decompiled.py index 97d5358b784c0..46ad8f50727da 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_with_offset/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/limit_with_offset/decompiled.py @@ -1,7 +1,9 @@ import ibis -result = ibis.table( +star1 = ibis.table( name="star1", schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, -).limit(10, 5) +) + +result = star1.limit(10, 5) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/self_reference_simple/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/self_reference_simple/decompiled.py index 48689a1f4b932..6765237757124 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/self_reference_simple/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/self_reference_simple/decompiled.py @@ -4,4 +4,4 @@ result = ibis.table( name="star1", schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, -).view() +) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/single_column/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/single_column/out.sql index a401619ae2d82..bb666f269b2a8 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/single_column/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_select_sql/single_column/out.sql @@ -1,5 +1,8 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 ORDER BY t0.f ASC \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_self_join_subquery_distinct_equal/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_self_join_subquery_distinct_equal/out.sql index 374a6dbdd0e75..d262b49d64c10 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_self_join_subquery_distinct_equal/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_self_join_subquery_distinct_equal/out.sql @@ -1,30 +1,20 @@ SELECT - t3.r_name AS r_name, - t4.n_name AS n_name -FROM ( - SELECT - t0.r_regionkey AS r_regionkey, - t0.r_name AS r_name, - t0.r_comment AS r_comment, - t1.n_nationkey AS n_nationkey, - t1.n_name AS n_name, - t1.n_regionkey AS n_regionkey, - t1.n_comment AS n_comment - FROM tpch_region AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.r_regionkey = t1.n_regionkey -) AS t3 + t7.r_name, + t7.n_name +FROM tpch_region AS t2 +INNER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey INNER JOIN ( SELECT - t0.r_regionkey AS r_regionkey, - t0.r_name AS r_name, - t0.r_comment AS r_comment, - t1.n_nationkey AS n_nationkey, - t1.n_name AS n_name, - t1.n_regionkey AS n_regionkey, - t1.n_comment AS n_comment - FROM tpch_region AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.r_regionkey = t1.n_regionkey -) AS t4 - ON t3.r_regionkey = t4.r_regionkey \ No newline at end of file + t2.r_regionkey, + t2.r_name, + t2.r_comment, + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment + FROM tpch_region AS t2 + INNER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey +) AS t7 + ON t2.r_regionkey = t7.r_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/decompiled.py index 02140f8bb8a73..6e73ee23967bc 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/decompiled.py @@ -9,4 +9,6 @@ name="star2", schema={"foo_id": "string", "value1": "float64", "value3": "float64"} ) -result = star1.semi_join(star2, star1.foo_id == star2.foo_id) +result = star1.semi_join(star2, star1.foo_id == star2.foo_id).select( + star1.c, star1.f, star1.foo_id, star1.bar_id +) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/out.sql index 0cfc52ab309b8..802ea0aad1c68 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_semi_join/out.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -SEMI JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id \ No newline at end of file + t2.c, + t2.f, + t2.foo_id, + t2.bar_id +FROM star1 AS t2 +SEMI JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/decompiled.py index 09d698686546c..527f8071b3289 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/decompiled.py @@ -11,4 +11,4 @@ result = star1.inner_join( star2, [star1.foo_id == star2.foo_id, star1.bar_id == star2.foo_id] -) +).select(star1.c, star1.f, star1.foo_id, star1.bar_id) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner.sql index e1aed9698bc11..56f5488cdde32 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -INNER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id + t2.c, + t2.f, + t2.foo_id, + t2.bar_id +FROM star1 AS t2 +INNER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner_two_preds.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner_two_preds.sql index 63cc978163fc2..59916704c75d7 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner_two_preds.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/inner_two_preds.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -INNER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id AND t0.bar_id = t1.foo_id \ No newline at end of file + t2.c, + t2.f, + t2.foo_id, + t2.bar_id +FROM star1 AS t2 +INNER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id AND t2.bar_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/left.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/left.sql index 3cc6681236aea..0b9cd8c009211 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/left.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/left.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -LEFT OUTER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id + t2.c, + t2.f, + t2.foo_id, + t2.bar_id +FROM star1 AS t2 +LEFT OUTER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/outer.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/outer.sql index 09d791f98b1e6..91950bc952c5f 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/outer.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_simple_joins/outer.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -FULL OUTER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id \ No newline at end of file + t2.c, + t2.f, + t2.foo_id, + t2.bar_id +FROM star1 AS t2 +FULL OUTER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result1.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result1.sql index 8e97174b77d90..5877da115f7b2 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result1.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result1.sql @@ -1,16 +1,12 @@ SELECT - t2.b AS b, + t1.b, COUNT(*) AS b_count FROM ( SELECT - t1.b AS b - FROM ( - SELECT - * - FROM t AS t0 - ORDER BY - t0.a ASC - ) AS t1 -) AS t2 + t0.b + FROM t AS t0 + ORDER BY + t0.a ASC +) AS t1 GROUP BY 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result2.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result2.sql index b6331cb950312..b40324745e05b 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result2.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_sort_then_group_by_propagates_keys/result2.sql @@ -1,16 +1,12 @@ SELECT - t2.b AS b, + t1.b, COUNT(*) AS b_count FROM ( SELECT - t1.b AS b - FROM ( - SELECT - * - FROM t AS t0 - ORDER BY - t0.b ASC - ) AS t1 -) AS t2 + t0.b + FROM t AS t0 + ORDER BY + t0.b ASC +) AS t1 GROUP BY 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/decompiled.py index 2a3bfca845bdb..18a6c4da10985 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/decompiled.py @@ -1,11 +1,9 @@ import ibis -result = ( - ibis.table( - name="star1", - schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, - ) - .foo_id.startswith(ibis.literal("foo")) - .name("tmp") +star1 = ibis.table( + name="star1", + schema={"c": "int32", "f": "float64", "foo_id": "string", "bar_id": "string"}, ) + +result = star1.foo_id.startswith(ibis.literal("foo")).name("tmp") diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/out.sql index bf7995d43b4ee..05528dd5f869a 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_startswith/out.sql @@ -1 +1,3 @@ -STARTS_WITH(t0.foo_id, 'foo') AS tmp \ No newline at end of file +SELECT + STARTS_WITH(t0.foo_id, 'foo') AS tmp +FROM star1 AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_factor_correlated_subquery/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_factor_correlated_subquery/out.sql index 67f775236f0f1..ab07ecf75d0e6 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_factor_correlated_subquery/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_factor_correlated_subquery/out.sql @@ -1,60 +1,76 @@ SELECT - * + t11.c_custkey, + t11.c_name, + t11.c_address, + t11.c_nationkey, + t11.c_phone, + t11.c_acctbal, + t11.c_mktsegment, + t11.c_comment, + t11.region, + t11.amount, + t11.odate FROM ( SELECT - t2.c_custkey AS c_custkey, - t2.c_name AS c_name, - t2.c_address AS c_address, - t2.c_nationkey AS c_nationkey, - t2.c_phone AS c_phone, - t2.c_acctbal AS c_acctbal, - t2.c_mktsegment AS c_mktsegment, - t2.c_comment AS c_comment, - t0.r_name AS region, - t3.o_totalprice AS amount, - CAST(t3.o_orderdate AS TIMESTAMP) AS odate - FROM tpch_region AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.r_regionkey = t1.n_regionkey - INNER JOIN tpch_customer AS t2 - ON t2.c_nationkey = t1.n_nationkey - INNER JOIN tpch_orders AS t3 - ON t3.o_custkey = t2.c_custkey -) AS t7 + t6.c_custkey, + t6.c_name, + t6.c_address, + t6.c_nationkey, + t6.c_phone, + t6.c_acctbal, + t6.c_mktsegment, + t6.c_comment, + t4.r_name AS region, + t7.o_totalprice AS amount, + CAST(t7.o_orderdate AS TIMESTAMP) AS odate + FROM tpch_region AS t4 + INNER JOIN tpch_nation AS t5 + ON t4.r_regionkey = t5.n_regionkey + INNER JOIN tpch_customer AS t6 + ON t6.c_nationkey = t5.n_nationkey + INNER JOIN tpch_orders AS t7 + ON t7.o_custkey = t6.c_custkey +) AS t11 WHERE - ( - t7.amount > ( + t11.amount > ( + SELECT + AVG(t13.amount) AS "Mean(amount)" + FROM ( SELECT - AVG(t9.amount) AS "Mean(amount)" + t12.c_custkey, + t12.c_name, + t12.c_address, + t12.c_nationkey, + t12.c_phone, + t12.c_acctbal, + t12.c_mktsegment, + t12.c_comment, + t12.region, + t12.amount, + t12.odate FROM ( SELECT - * - FROM ( - SELECT - t2.c_custkey AS c_custkey, - t2.c_name AS c_name, - t2.c_address AS c_address, - t2.c_nationkey AS c_nationkey, - t2.c_phone AS c_phone, - t2.c_acctbal AS c_acctbal, - t2.c_mktsegment AS c_mktsegment, - t2.c_comment AS c_comment, - t0.r_name AS region, - t3.o_totalprice AS amount, - CAST(t3.o_orderdate AS TIMESTAMP) AS odate - FROM tpch_region AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.r_regionkey = t1.n_regionkey - INNER JOIN tpch_customer AS t2 - ON t2.c_nationkey = t1.n_nationkey - INNER JOIN tpch_orders AS t3 - ON t3.o_custkey = t2.c_custkey - ) AS t8 - WHERE - ( - t8.region = t7.region - ) - ) AS t9 - ) + t6.c_custkey, + t6.c_name, + t6.c_address, + t6.c_nationkey, + t6.c_phone, + t6.c_acctbal, + t6.c_mktsegment, + t6.c_comment, + t4.r_name AS region, + t7.o_totalprice AS amount, + CAST(t7.o_orderdate AS TIMESTAMP) AS odate + FROM tpch_region AS t4 + INNER JOIN tpch_nation AS t5 + ON t4.r_regionkey = t5.n_regionkey + INNER JOIN tpch_customer AS t6 + ON t6.c_nationkey = t5.n_nationkey + INNER JOIN tpch_orders AS t7 + ON t7.o_custkey = t6.c_custkey + ) AS t12 + WHERE + t12.region = t12.region + ) AS t13 ) LIMIT 10 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr.sql index 6829667d5210f..404caac504636 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr.sql @@ -1,11 +1,12 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > ( - SELECT - AVG(t0.f) AS "Mean(f)" - FROM star1 AS t0 - ) - ) + t0.f > ( + SELECT + AVG(t0.f) AS "Mean(f)" + FROM star1 AS t0 + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr2.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr2.sql index d196e74c2bf7b..fdbdef535ce43 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr2.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_filter_predicate/expr2.sql @@ -1,19 +1,21 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > ( + t0.f > ( + SELECT + AVG(t1.f) AS "Mean(f)" + FROM ( SELECT - AVG(t1.f) AS "Mean(f)" - FROM ( - SELECT - * - FROM star1 AS t0 - WHERE - ( - t0.foo_id = 'foo' - ) - ) AS t1 - ) - ) + t0.c, + t0.f, + t0.foo_id, + t0.bar_id + FROM star1 AS t0 + WHERE + t0.foo_id = 'foo' + ) AS t1 + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/decompiled.py index 9a11e7e90c512..a2a8f64d4fd29 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/decompiled.py @@ -17,11 +17,11 @@ "k": "time", }, ) -agg = alltypes.group_by([alltypes.a, alltypes.g]).aggregate( - alltypes.f.sum().name("metric") -) +agg = alltypes.aggregate([alltypes.f.sum().name("metric")], by=[alltypes.a, alltypes.g]) selfreference = agg.view() -proj = agg.inner_join(selfreference, agg.g == selfreference.g).select(agg) -union = proj.union(proj.view()) +joinchain = agg.inner_join(selfreference, agg.g == selfreference.g).select( + agg.a, agg.g, agg.metric +) +selfreference1 = joinchain.view() -result = union.select([union.a, union.g, union.metric]) +result = joinchain.union(selfreference1) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql index e7785e9117d31..57e0912af4a65 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql @@ -1,51 +1,57 @@ SELECT - t1.a AS a, - t1.g AS g, - t1.metric AS metric + t8.a, + t8.g, + t8.metric FROM ( SELECT - t0.a AS a, - t0.g AS g, - SUM(t0.f) AS metric - FROM alltypes AS t0 - GROUP BY - 1, - 2 -) AS t1 -INNER JOIN ( + t2.a, + t2.g, + t2.metric + FROM ( + SELECT + t0.a, + t0.g, + SUM(t0.f) AS metric + FROM alltypes AS t0 + GROUP BY + 1, + 2 + ) AS t2 + INNER JOIN ( + SELECT + t0.a, + t0.g, + SUM(t0.f) AS metric + FROM alltypes AS t0 + GROUP BY + 1, + 2 + ) AS t4 + ON t2.g = t4.g + UNION ALL SELECT - t0.a AS a, - t0.g AS g, - SUM(t0.f) AS metric - FROM alltypes AS t0 - GROUP BY - 1, - 2 -) AS t2 - ON t1.g = t2.g -UNION ALL -SELECT - t1.a AS a, - t1.g AS g, - t1.metric AS metric -FROM ( - SELECT - t0.a AS a, - t0.g AS g, - SUM(t0.f) AS metric - FROM alltypes AS t0 - GROUP BY - 1, - 2 -) AS t1 -INNER JOIN ( - SELECT - t0.a AS a, - t0.g AS g, - SUM(t0.f) AS metric - FROM alltypes AS t0 - GROUP BY - 1, - 2 -) AS t2 - ON t1.g = t2.g \ No newline at end of file + t2.a, + t2.g, + t2.metric + FROM ( + SELECT + t0.a, + t0.g, + SUM(t0.f) AS metric + FROM alltypes AS t0 + GROUP BY + 1, + 2 + ) AS t2 + INNER JOIN ( + SELECT + t0.a, + t0.g, + SUM(t0.f) AS metric + FROM alltypes AS t0 + GROUP BY + 1, + 2 + ) AS t4 + ON t2.g = t4.g +) AS t8 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_used_for_self_join/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_used_for_self_join/out.sql index 496b5b45619e4..57edded675158 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_used_for_self_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_used_for_self_join/out.sql @@ -1,41 +1,41 @@ SELECT - t4.g AS g, - MAX(t4.total - t4.total_right) AS metric + t6.g, + MAX(t6.total - t6.total_right) AS metric FROM ( SELECT - t1.g AS g, - t1.a AS a, - t1.b AS b, - t1.total AS total, - t2.g AS g_right, - t2.a AS a_right, - t2.b AS b_right, - t2.total AS total_right + t2.g, + t2.a, + t2.b, + t2.total, + t4.g AS g_right, + t4.a AS a_right, + t4.b AS b_right, + t4.total AS total_right FROM ( SELECT - t0.g AS g, - t0.a AS a, - t0.b AS b, + t0.g, + t0.a, + t0.b, SUM(t0.f) AS total FROM alltypes AS t0 GROUP BY 1, 2, 3 - ) AS t1 + ) AS t2 INNER JOIN ( SELECT - t0.g AS g, - t0.a AS a, - t0.b AS b, + t0.g, + t0.a, + t0.b, SUM(t0.f) AS total FROM alltypes AS t0 GROUP BY 1, 2, 3 - ) AS t2 - ON t1.a = t2.b -) AS t4 + ) AS t4 + ON t2.a = t4.b +) AS t6 GROUP BY 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_analysis_bug/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_analysis_bug/out.sql index 551821a247c45..5145b5c7361fe 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_analysis_bug/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_analysis_bug/out.sql @@ -1,40 +1,45 @@ SELECT - t6.origin AS origin, + t8.origin, COUNT(*) AS "CountStar()" FROM ( SELECT - t1.dest AS dest, - t1.origin AS origin, - t1.arrdelay AS arrdelay + t2.dest, + t2.origin, + t2.arrdelay FROM ( SELECT - * + t0.dest, + t0.origin, + t0.arrdelay FROM airlines AS t0 WHERE t0.dest IN ('ORD', 'JFK', 'SFO') - ) AS t1 + ) AS t2 SEMI JOIN ( SELECT - * + t3.dest, + t3."Mean(arrdelay)" FROM ( SELECT - t1.dest AS dest, + t1.dest, AVG(t1.arrdelay) AS "Mean(arrdelay)" FROM ( SELECT - * + t0.dest, + t0.origin, + t0.arrdelay FROM airlines AS t0 WHERE t0.dest IN ('ORD', 'JFK', 'SFO') ) AS t1 GROUP BY 1 - ) AS t2 + ) AS t3 ORDER BY - t2."Mean(arrdelay)" DESC + t3."Mean(arrdelay)" DESC LIMIT 10 - ) AS t4 - ON t1.dest = t4.dest -) AS t6 + ) AS t6 + ON t2.dest = t6.dest +) AS t8 GROUP BY 1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e1.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e1.sql index 077bcd8cb40b9..6d86baa0190cb 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e1.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e1.sql @@ -1,23 +1,24 @@ SELECT - t0.foo AS foo, - t0.bar AS bar, - t0.city AS city, - t0.v1 AS v1, - t0.v2 AS v2 -FROM tbl AS t0 + t1.foo, + t1.bar, + t1.city, + t1.v1, + t1.v2 +FROM tbl AS t1 SEMI JOIN ( SELECT - * + t2.city, + t2."Mean(v2)" FROM ( SELECT - t0.city AS city, + t0.city, AVG(t0.v2) AS "Mean(v2)" FROM tbl AS t0 GROUP BY 1 - ) AS t1 + ) AS t2 ORDER BY - t1."Mean(v2)" DESC + t2."Mean(v2)" DESC LIMIT 10 -) AS t3 - ON t0.city = t3.city \ No newline at end of file +) AS t5 + ON t1.city = t5.city \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e2.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e2.sql index 6f15e53a0d5b4..53e239ad98c84 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e2.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_operation/e2.sql @@ -1,23 +1,24 @@ SELECT - t0.foo AS foo, - t0.bar AS bar, - t0.city AS city, - t0.v1 AS v1, - t0.v2 AS v2 -FROM tbl AS t0 + t1.foo, + t1.bar, + t1.city, + t1.v1, + t1.v2 +FROM tbl AS t1 SEMI JOIN ( SELECT - * + t2.city, + t2."Count(city)" FROM ( SELECT - t0.city AS city, + t0.city, COUNT(t0.city) AS "Count(city)" FROM tbl AS t0 GROUP BY 1 - ) AS t1 + ) AS t2 ORDER BY - t1."Count(city)" DESC + t2."Count(city)" DESC LIMIT 10 -) AS t3 - ON t0.city = t3.city \ No newline at end of file +) AS t5 + ON t1.city = t5.city \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_predicate_pushdown_bug/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_predicate_pushdown_bug/out.sql index 237a4f77eb329..9dffcedd667bf 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_predicate_pushdown_bug/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_predicate_pushdown_bug/out.sql @@ -1,62 +1,50 @@ SELECT - t5.c_custkey AS c_custkey, - t5.c_name AS c_name, - t5.c_address AS c_address, - t5.c_nationkey AS c_nationkey, - t5.c_phone AS c_phone, - t5.c_acctbal AS c_acctbal, - t5.c_mktsegment AS c_mktsegment, - t5.c_comment AS c_comment, - t5.n_name AS n_name, - t5.r_name AS r_name -FROM ( - SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t1.n_name AS n_name, - t2.r_name AS r_name - FROM tpch_customer AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.c_nationkey = t1.n_nationkey - INNER JOIN tpch_region AS t2 - ON t1.n_regionkey = t2.r_regionkey -) AS t5 + t3.c_custkey, + t3.c_name, + t3.c_address, + t3.c_nationkey, + t3.c_phone, + t3.c_acctbal, + t3.c_mktsegment, + t3.c_comment, + t4.n_name, + t5.r_name +FROM tpch_customer AS t3 +INNER JOIN tpch_nation AS t4 + ON t3.c_nationkey = t4.n_nationkey +INNER JOIN tpch_region AS t5 + ON t4.n_regionkey = t5.r_regionkey SEMI JOIN ( SELECT - * + t9.n_name, + t9."Sum(c_acctbal)" FROM ( SELECT - t5.n_name AS n_name, - SUM(t5.c_acctbal) AS "Sum(c_acctbal)" + t8.n_name, + SUM(t8.c_acctbal) AS "Sum(c_acctbal)" FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t1.n_name AS n_name, - t2.r_name AS r_name - FROM tpch_customer AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.c_nationkey = t1.n_nationkey - INNER JOIN tpch_region AS t2 - ON t1.n_regionkey = t2.r_regionkey - ) AS t5 + t3.c_custkey, + t3.c_name, + t3.c_address, + t3.c_nationkey, + t3.c_phone, + t3.c_acctbal, + t3.c_mktsegment, + t3.c_comment, + t4.n_name, + t5.r_name + FROM tpch_customer AS t3 + INNER JOIN tpch_nation AS t4 + ON t3.c_nationkey = t4.n_nationkey + INNER JOIN tpch_region AS t5 + ON t4.n_regionkey = t5.r_regionkey + ) AS t8 GROUP BY 1 - ) AS t6 + ) AS t9 ORDER BY - t6."Sum(c_acctbal)" DESC + t9."Sum(c_acctbal)" DESC LIMIT 10 -) AS t8 - ON t5.n_name = t8.n_name \ No newline at end of file +) AS t12 + ON t4.n_name = t12.n_name \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_to_aggregate/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_to_aggregate/out.sql index 55fd82ce48b98..fe46767993fe0 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_to_aggregate/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_topk_to_aggregate/out.sql @@ -1,8 +1,9 @@ SELECT - * + t1.dest, + t1."Mean(arrdelay)" FROM ( SELECT - t0.dest AS dest, + t0.dest, AVG(t0.arrdelay) AS "Mean(arrdelay)" FROM airlines AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_tpch_self_join_failure/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_tpch_self_join_failure/out.sql index cf9c5a649d4b7..aa75e2be0ae10 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_tpch_self_join_failure/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_tpch_self_join_failure/out.sql @@ -1,53 +1,53 @@ SELECT - t8.region AS region, - t8.year AS year, - t8.total - t9.total AS yoy_change + t13.region, + t13.year, + t13.total - t15.total AS yoy_change FROM ( SELECT - t7.region AS region, - EXTRACT('year' FROM t7.odate) AS year, - CAST(SUM(t7.amount) AS DOUBLE) AS total + t11.region, + EXTRACT('year' FROM t11.odate) AS year, + CAST(SUM(t11.amount) AS DOUBLE) AS total FROM ( SELECT - t0.r_name AS region, - t1.n_name AS nation, - t3.o_totalprice AS amount, - CAST(t3.o_orderdate AS TIMESTAMP) AS odate - FROM tpch_region AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.r_regionkey = t1.n_regionkey - INNER JOIN tpch_customer AS t2 - ON t2.c_nationkey = t1.n_nationkey - INNER JOIN tpch_orders AS t3 - ON t3.o_custkey = t2.c_custkey - ) AS t7 + t4.r_name AS region, + t5.n_name AS nation, + t7.o_totalprice AS amount, + CAST(t7.o_orderdate AS TIMESTAMP) AS odate + FROM tpch_region AS t4 + INNER JOIN tpch_nation AS t5 + ON t4.r_regionkey = t5.n_regionkey + INNER JOIN tpch_customer AS t6 + ON t6.c_nationkey = t5.n_nationkey + INNER JOIN tpch_orders AS t7 + ON t7.o_custkey = t6.c_custkey + ) AS t11 GROUP BY 1, 2 -) AS t8 +) AS t13 INNER JOIN ( SELECT - t7.region AS region, - EXTRACT('year' FROM t7.odate) AS year, - CAST(SUM(t7.amount) AS DOUBLE) AS total + t11.region, + EXTRACT('year' FROM t11.odate) AS year, + CAST(SUM(t11.amount) AS DOUBLE) AS total FROM ( SELECT - t0.r_name AS region, - t1.n_name AS nation, - t3.o_totalprice AS amount, - CAST(t3.o_orderdate AS TIMESTAMP) AS odate - FROM tpch_region AS t0 - INNER JOIN tpch_nation AS t1 - ON t0.r_regionkey = t1.n_regionkey - INNER JOIN tpch_customer AS t2 - ON t2.c_nationkey = t1.n_nationkey - INNER JOIN tpch_orders AS t3 - ON t3.o_custkey = t2.c_custkey - ) AS t7 + t4.r_name AS region, + t5.n_name AS nation, + t7.o_totalprice AS amount, + CAST(t7.o_orderdate AS TIMESTAMP) AS odate + FROM tpch_region AS t4 + INNER JOIN tpch_nation AS t5 + ON t4.r_regionkey = t5.n_regionkey + INNER JOIN tpch_customer AS t6 + ON t6.c_nationkey = t5.n_nationkey + INNER JOIN tpch_orders AS t7 + ON t7.o_custkey = t6.c_custkey + ) AS t11 GROUP BY 1, 2 -) AS t9 - ON t8.year = ( - t9.year - CAST(1 AS TINYINT) +) AS t15 + ON t13.year = ( + t15.year - CAST(1 AS TINYINT) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_analyze_scalar_op/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_analyze_scalar_op/out.sql index 6407e4987c291..102f8d7fc1529 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_analyze_scalar_op/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_analyze_scalar_op/out.sql @@ -1 +1,26 @@ -COUNT(*) \ No newline at end of file +SELECT + COUNT(*) AS "CountStar()" +FROM ( + SELECT + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month + FROM functional_alltypes AS t0 + WHERE + t0.timestamp_col < ( + MAKE_TIMESTAMP(2010, 1, 1, 0, 0, 0.0) + INTERVAL '3' MONTH + ) + AND t0.timestamp_col < ( + CAST(CURRENT_TIMESTAMP AS TIMESTAMP) + INTERVAL '10' DAY + ) +) AS t1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/decompiled.py index e44d7f2cff3a2..434705fa87426 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/decompiled.py @@ -8,6 +8,8 @@ star2 = ibis.table( name="star2", schema={"foo_id": "string", "value1": "float64", "value3": "float64"} ) -joinchain = star1.inner_join(star2, star1.foo_id == star2.foo_id) +joinchain = star1.inner_join(star2, star1.foo_id == star2.foo_id).select( + star1.c, star1.f, star1.foo_id, star1.bar_id, (star1.f - star2.value1).name("diff") +) result = joinchain.filter(joinchain.diff > 1) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/out.sql index 7168e81df0e57..98fedc20876d5 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_no_pushdown_possible/out.sql @@ -1,17 +1,19 @@ SELECT - * + t5.c, + t5.f, + t5.foo_id, + t5.bar_id, + t5.diff FROM ( SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id, - t0.f - t1.value1 AS diff - FROM star1 AS t0 - INNER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id -) AS t3 + t2.c, + t2.f, + t2.foo_id, + t2.bar_id, + t2.f - t3.value1 AS diff + FROM star1 AS t2 + INNER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id +) AS t5 WHERE - ( - t3.diff > CAST(1 AS TINYINT) - ) \ No newline at end of file + t5.diff > CAST(1 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_between/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_between/out.sql index 136c64d28e4e4..34036b117531c 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_between/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_between/out.sql @@ -1,8 +1,15 @@ SELECT - * + t0.a, + t0.b, + t0.c, + t0.d, + t0.e, + t0.f, + t0.g, + t0.h, + t0.i, + t0.j, + t0.k FROM alltypes AS t0 WHERE - ( - t0.a > CAST(0 AS TINYINT) - ) - AND t0.f BETWEEN CAST(0 AS TINYINT) AND CAST(1 AS TINYINT) \ No newline at end of file + t0.a > CAST(0 AS TINYINT) AND t0.f BETWEEN CAST(0 AS TINYINT) AND CAST(1 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/decompiled.py b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/decompiled.py index b89e0510e17a4..45ea3c0684a0f 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/decompiled.py @@ -8,6 +8,8 @@ star2 = ibis.table( name="star2", schema={"foo_id": "string", "value1": "float64", "value3": "float64"} ) -joinchain = star1.inner_join(star2, star1.foo_id == star2.foo_id) +joinchain = star1.inner_join(star2, star1.foo_id == star2.foo_id).select( + star1.c, star1.f, star1.foo_id, star1.bar_id, star2.value1, star2.value3 +) result = joinchain.filter(joinchain.f > 0, joinchain.value3 < 1000) diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/out.sql index 27f0563003e4f..3f187d69a7fc1 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_where_with_join/out.sql @@ -1,20 +1,21 @@ SELECT - * + t5.c, + t5.f, + t5.foo_id, + t5.bar_id, + t5.value1, + t5.value3 FROM ( SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id, - t1.value1 AS value1, - t1.value3 AS value3 - FROM star1 AS t0 - INNER JOIN star2 AS t1 - ON t0.foo_id = t1.foo_id -) AS t3 + t2.c, + t2.f, + t2.foo_id, + t2.bar_id, + t3.value1, + t3.value3 + FROM star1 AS t2 + INNER JOIN star2 AS t3 + ON t2.foo_id = t3.foo_id +) AS t5 WHERE - ( - t3.f > CAST(0 AS TINYINT) - ) AND ( - t3.value3 < CAST(1000 AS SMALLINT) - ) \ No newline at end of file + t5.f > CAST(0 AS TINYINT) AND t5.value3 < CAST(1000 AS SMALLINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_count/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_count/out.sql index 214ec1ede144c..35e4fe0adc244 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_count/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_count/out.sql @@ -1,20 +1,14 @@ SELECT - t2.foo_id AS foo_id, - t2.total AS total + t1.foo_id, + t1.total FROM ( SELECT - * - FROM ( - SELECT - t0.foo_id AS foo_id, - SUM(t0.f) AS total, - COUNT(*) AS "CountStar()" - FROM star1 AS t0 - GROUP BY - 1 - ) AS t1 - WHERE - ( - t1."CountStar()" > CAST(100 AS TINYINT) - ) -) AS t2 \ No newline at end of file + t0.foo_id, + SUM(t0.f) AS total, + COUNT(*) AS "CountStar()" + FROM star1 AS t0 + GROUP BY + 1 +) AS t1 +WHERE + t1."CountStar()" > CAST(100 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_sum/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_sum/out.sql index 307170b0f208a..47945167c00a9 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_sum/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/having_sum/out.sql @@ -1,14 +1,13 @@ SELECT - * + t1.foo_id, + t1.total FROM ( SELECT - t0.foo_id AS foo_id, + t0.foo_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY 1 ) AS t1 WHERE - ( - t1.total > CAST(10 AS TINYINT) - ) \ No newline at end of file + t1.total > CAST(10 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/single/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/single/out.sql index 29e72c8336aa5..dbf4aadac2031 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/single/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/single/out.sql @@ -1,5 +1,5 @@ SELECT - t0.foo_id AS foo_id, + t0.foo_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/two/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/two/out.sql index 116832bf3c3a7..be9b430bd3d3b 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/two/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_aggregate/two/out.sql @@ -1,6 +1,6 @@ SELECT - t0.foo_id AS foo_id, - t0.bar_id AS bar_id, + t0.foo_id, + t0.bar_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_between/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_between/out.sql index a944dbd5c9580..c4f686443cee7 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_between/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_between/out.sql @@ -1 +1,3 @@ -t0.double_col BETWEEN CAST(5 AS TINYINT) AND CAST(10 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col BETWEEN CAST(5 AS TINYINT) AND CAST(10 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/and/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/and/out.sql index 6e3e0443a5321..d2e722d4fa187 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/and/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/and/out.sql @@ -1,5 +1,7 @@ -( - t0.double_col > CAST(0 AS TINYINT) -) AND ( - t0.double_col < CAST(5 AS TINYINT) -) AS tmp \ No newline at end of file +SELECT + ( + t0.double_col > CAST(0 AS TINYINT) + ) AND ( + t0.double_col < CAST(5 AS TINYINT) + ) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/or/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/or/out.sql index b0f919bdac1aa..4b0542464299b 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/or/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_boolean_conjunction/or/out.sql @@ -1,5 +1,7 @@ -( - t0.double_col < CAST(0 AS TINYINT) -) OR ( - t0.double_col > CAST(5 AS TINYINT) -) AS tmp \ No newline at end of file +SELECT + ( + t0.double_col < CAST(0 AS TINYINT) + ) OR ( + t0.double_col > CAST(5 AS TINYINT) + ) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_coalesce/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_coalesce/out.sql index 233633ba658a8..df5a9329fcb49 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_coalesce/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_coalesce/out.sql @@ -1,5 +1,7 @@ -COALESCE( - CASE WHEN t0.double_col > CAST(30 AS TINYINT) THEN t0.double_col ELSE NULL END, - NULL, - t0.float_col -) AS tmp \ No newline at end of file +SELECT + COALESCE( + CASE WHEN t0.double_col > CAST(30 AS TINYINT) THEN t0.double_col ELSE NULL END, + NULL, + t0.float_col + ) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/eq/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/eq/out.sql index 19a939098145c..2ad44306e1cdd 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/eq/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/eq/out.sql @@ -1 +1,3 @@ -t0.double_col = CAST(5 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col = CAST(5 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ge/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ge/out.sql index 1c278dc0cb73a..8b722a8197540 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ge/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ge/out.sql @@ -1 +1,3 @@ -t0.double_col >= CAST(5 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col >= CAST(5 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/gt/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/gt/out.sql index 4fbdd9ab3b1ce..ca8c8d134d60c 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/gt/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/gt/out.sql @@ -1 +1,3 @@ -t0.double_col > CAST(5 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col > CAST(5 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/le/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/le/out.sql index 41acc5d90cadb..53bf7d0d2dbb3 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/le/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/le/out.sql @@ -1 +1,3 @@ -t0.double_col <= CAST(5 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col <= CAST(5 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/lt/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/lt/out.sql index a6fb94a63f56c..627be18407895 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/lt/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/lt/out.sql @@ -1 +1,3 @@ -t0.double_col < CAST(5 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col < CAST(5 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ne/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ne/out.sql index 98a382b281679..685a418a8eb43 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ne/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_comparisons/ne/out.sql @@ -1 +1,3 @@ -t0.double_col <> CAST(5 AS TINYINT) AS tmp \ No newline at end of file +SELECT + t0.double_col <> CAST(5 AS TINYINT) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_cte_factor_distinct_but_equal/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_cte_factor_distinct_but_equal/out.sql index 4e808e0ff710f..1aa27939686af 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_cte_factor_distinct_but_equal/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_cte_factor_distinct_but_equal/out.sql @@ -1,20 +1,20 @@ SELECT - t2.g AS g, - t2.metric AS metric + t3.g, + t3.metric FROM ( SELECT - t0.g AS g, + t0.g, SUM(t0.f) AS metric FROM alltypes AS t0 GROUP BY 1 -) AS t2 +) AS t3 INNER JOIN ( SELECT - t1.g AS g, + t1.g, SUM(t1.f) AS metric FROM alltypes AS t1 GROUP BY 1 -) AS t4 - ON t2.g = t4.g \ No newline at end of file +) AS t6 + ON t3.g = t6.g \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/count_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/count_distinct/out.sql index e2c1fc57b53fc..37382bcf51498 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/count_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/count_distinct/out.sql @@ -1 +1,3 @@ -COUNT(DISTINCT t0.int_col) AS nunique \ No newline at end of file +SELECT + COUNT(DISTINCT t0.int_col) AS nunique +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/group_by_count_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/group_by_count_distinct/out.sql index c4d51f3540050..14b6c6d834770 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/group_by_count_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/group_by_count_distinct/out.sql @@ -1,5 +1,5 @@ SELECT - t0.string_col AS string_col, + t0.string_col, COUNT(DISTINCT t0.int_col) AS nunique FROM functional_alltypes AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/projection_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/projection_distinct/out.sql index f98b3697b64fb..483b4fef6f492 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/projection_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/projection_distinct/out.sql @@ -2,7 +2,7 @@ SELECT DISTINCT * FROM ( SELECT - t0.string_col AS string_col, - t0.int_col AS int_col + t0.string_col, + t0.int_col FROM functional_alltypes AS t0 ) AS t1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/single_column_projection_distinct/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/single_column_projection_distinct/out.sql index 636796e7e04d6..d38aa10366c46 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/single_column_projection_distinct/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_distinct/single_column_projection_distinct/out.sql @@ -2,6 +2,6 @@ SELECT DISTINCT * FROM ( SELECT - t0.string_col AS string_col + t0.string_col FROM functional_alltypes AS t0 ) AS t1 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e1.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e1.sql index c84bf63f1858c..b0be257b254f0 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e1.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e1.sql @@ -1,19 +1,13 @@ SELECT - * + t0.key1, + t0.key2, + t0.value1 FROM foo_t AS t0 WHERE EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM ( - SELECT - * - FROM bar_t AS t1 - WHERE - ( - t0.key1 = t1.key1 - ) - ) AS t2 - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM bar_t AS t1 + WHERE + t0.key1 = t1.key1 ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e2.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e2.sql index 83416d431936b..f397c2b7251ec 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e2.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_exists/e2.sql @@ -1,23 +1,17 @@ SELECT - * + t0.key1, + t0.key2, + t0.value1 FROM foo_t AS t0 WHERE EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM ( - SELECT - * - FROM bar_t AS t1 - WHERE - ( - ( - t0.key1 = t1.key1 - ) AND ( - t1.key2 = 'foo' - ) - ) - ) AS t2 - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM bar_t AS t1 + WHERE + ( + t0.key1 = t1.key1 + ) AND ( + t1.key2 = 'foo' + ) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_filter_group_by_agg_with_same_name/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_filter_group_by_agg_with_same_name/out.sql index 13e53cf4bbd79..c0ba260a78bb6 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_filter_group_by_agg_with_same_name/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_filter_group_by_agg_with_same_name/out.sql @@ -1,14 +1,13 @@ SELECT - * + t1.int_col, + t1.bigint_col FROM ( SELECT - t0.int_col AS int_col, + t0.int_col, SUM(t0.bigint_col) AS bigint_col FROM t AS t0 GROUP BY 1 ) AS t1 WHERE - ( - t1.bigint_col = CAST(60 AS TINYINT) - ) \ No newline at end of file + t1.bigint_col = CAST(60 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_gh_1045/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_gh_1045/out.sql new file mode 100644 index 0000000000000..b9a81bb4916fc --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_gh_1045/out.sql @@ -0,0 +1,37 @@ +SELECT + t5.t1_id1, + t5.t1_val1, + t10.id3, + t10.val2, + t10.dt, + t10.t3_val2, + t10.id2a, + t10.id2b, + t10.val2_right +FROM ( + SELECT + t0.id1 AS t1_id1, + t0.val1 AS t1_val1 + FROM test1 AS t0 +) AS t5 +LEFT OUTER JOIN ( + SELECT + t7.id3, + t7.val2, + t7.dt, + t7.t3_val2, + t3.id2a, + t3.id2b, + t3.val2 AS val2_right + FROM ( + SELECT + CAST(t1.id3 AS BIGINT) AS id3, + t1.val2, + t1.dt, + CAST(t1.id3 AS BIGINT) AS t3_val2 + FROM test3 AS t1 + ) AS t7 + INNER JOIN test2 AS t3 + ON t3.id2b = t7.id3 +) AS t10 + ON t5.t1_id1 = t10.id2a \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/isnull/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/isnull/out.sql index 96dd80efc156e..d06c0383bb09e 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/isnull/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/isnull/out.sql @@ -1 +1,3 @@ -t0.double_col IS NULL AS tmp \ No newline at end of file +SELECT + t0.double_col IS NULL AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/notnull/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/notnull/out.sql index b25cb9418af6f..f33c3466083a8 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/notnull/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_isnull_notnull/notnull/out.sql @@ -1 +1,3 @@ -t0.double_col IS NOT NULL AS tmp \ No newline at end of file +SELECT + NOT t0.double_col IS NULL AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_join_just_materialized/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_join_just_materialized/out.sql index 7d32758ef61c3..28ef4cadbb22e 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_join_just_materialized/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_join_just_materialized/out.sql @@ -1,21 +1,21 @@ SELECT - t0.n_nationkey AS n_nationkey, - t0.n_name AS n_name, - t0.n_regionkey AS n_regionkey, - t0.n_comment AS n_comment, - t1.r_regionkey AS r_regionkey, - t1.r_name AS r_name, - t1.r_comment AS r_comment, - t2.c_custkey AS c_custkey, - t2.c_name AS c_name, - t2.c_address AS c_address, - t2.c_nationkey AS c_nationkey, - t2.c_phone AS c_phone, - t2.c_acctbal AS c_acctbal, - t2.c_mktsegment AS c_mktsegment, - t2.c_comment AS c_comment -FROM tpch_nation AS t0 -INNER JOIN tpch_region AS t1 - ON t0.n_regionkey = t1.r_regionkey -INNER JOIN tpch_customer AS t2 - ON t0.n_nationkey = t2.c_nationkey \ No newline at end of file + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment, + t4.r_regionkey, + t4.r_name, + t4.r_comment, + t5.c_custkey, + t5.c_name, + t5.c_address, + t5.c_nationkey, + t5.c_phone, + t5.c_acctbal, + t5.c_mktsegment, + t5.c_comment +FROM tpch_nation AS t3 +INNER JOIN tpch_region AS t4 + ON t3.n_regionkey = t4.r_regionkey +INNER JOIN tpch_customer AS t5 + ON t3.n_nationkey = t5.c_nationkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_joins/inner/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/inner/out.sql new file mode 100644 index 0000000000000..9289a835e37ab --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/inner/out.sql @@ -0,0 +1,11 @@ +SELECT + t2.r_regionkey, + t2.r_name, + t2.r_comment, + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment +FROM tpch_region AS t2 +INNER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_joins/inner_select/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/inner_select/out.sql new file mode 100644 index 0000000000000..38534295064fa --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/inner_select/out.sql @@ -0,0 +1,8 @@ +SELECT + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment +FROM tpch_region AS t2 +INNER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_joins/left/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/left/out.sql new file mode 100644 index 0000000000000..7048d19d0ba42 --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/left/out.sql @@ -0,0 +1,11 @@ +SELECT + t2.r_regionkey, + t2.r_name, + t2.r_comment, + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment +FROM tpch_region AS t2 +LEFT OUTER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_joins/left_select/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/left_select/out.sql new file mode 100644 index 0000000000000..26c408b5be1a2 --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/left_select/out.sql @@ -0,0 +1,8 @@ +SELECT + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment +FROM tpch_region AS t2 +LEFT OUTER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_joins/outer/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/outer/out.sql new file mode 100644 index 0000000000000..f14ac5c0d92e5 --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/outer/out.sql @@ -0,0 +1,11 @@ +SELECT + t2.r_regionkey, + t2.r_name, + t2.r_comment, + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment +FROM tpch_region AS t2 +FULL OUTER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_joins/outer_select/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/outer_select/out.sql new file mode 100644 index 0000000000000..1b339a3f247bc --- /dev/null +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_joins/outer_select/out.sql @@ -0,0 +1,8 @@ +SELECT + t3.n_nationkey, + t3.n_name, + t3.n_regionkey, + t3.n_comment +FROM tpch_region AS t2 +FULL OUTER JOIN tpch_nation AS t3 + ON t2.r_regionkey = t3.n_regionkey \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_limit_filter/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_limit_filter/out.sql index ec694656a01b6..31e87b57f3eac 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_limit_filter/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_limit_filter/out.sql @@ -1,8 +1,9 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) + t0.f > CAST(0 AS TINYINT) LIMIT 10 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_limit_subquery/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_limit_subquery/out.sql index 431ba054f9f98..ab4dd6df71588 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_limit_subquery/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_limit_subquery/out.sql @@ -1,5 +1,8 @@ SELECT - * + t1.c, + t1.f, + t1.foo_id, + t1.bar_id FROM ( SELECT * @@ -7,6 +10,4 @@ FROM ( LIMIT 10 ) AS t1 WHERE - ( - t1.f > CAST(0 AS TINYINT) - ) \ No newline at end of file + t1.f > CAST(0 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/decompiled.py b/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/decompiled.py index 27d91a4d745ae..593c3faf221fe 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/decompiled.py +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/decompiled.py @@ -9,7 +9,9 @@ name="star2", schema={"foo_id": "string", "value1": "float64", "value3": "float64"} ) agg = star1.aggregate([star1.f.sum().name("total")], by=[star1.foo_id]) -joinchain = agg.inner_join(star2, agg.foo_id == star2.foo_id) +joinchain = agg.inner_join(star2, agg.foo_id == star2.foo_id).select( + agg.foo_id, agg.total, star2.value1 +) f = joinchain.filter(joinchain.total > 100) result = f.order_by(f.total.desc()) diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/out.sql index 3b947354fb103..b6c7dab919698 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_lower_projection_sort_key/out.sql @@ -1,28 +1,24 @@ SELECT - * + t6.foo_id, + t6.total, + t6.value1 FROM ( SELECT - * + t4.foo_id, + t4.total, + t2.value1 FROM ( SELECT - t2.foo_id AS foo_id, - t2.total AS total, - t1.value1 AS value1 - FROM ( - SELECT - t0.foo_id AS foo_id, - SUM(t0.f) AS total - FROM star1 AS t0 - GROUP BY - 1 - ) AS t2 - INNER JOIN star2 AS t1 - ON t2.foo_id = t1.foo_id + t0.foo_id, + SUM(t0.f) AS total + FROM star1 AS t0 + GROUP BY + 1 ) AS t4 - WHERE - ( - t4.total > CAST(100 AS TINYINT) - ) -) AS t5 + INNER JOIN star2 AS t2 + ON t4.foo_id = t2.foo_id +) AS t6 +WHERE + t6.total > CAST(100 AS TINYINT) ORDER BY - t5.total DESC \ No newline at end of file + t6.total DESC \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_multi_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_multi_join/out.sql index 0a2d70812c521..d9c97bc180ca2 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_multi_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_multi_join/out.sql @@ -1,20 +1,20 @@ SELECT - t0.x1 AS x1, - t0.y1 AS y1, - t1.x2 AS x2, - t6.x3 AS x3, - t6.y2 AS y2, - t6.x4 AS x4 -FROM t1 AS t0 -INNER JOIN t2 AS t1 - ON t0.x1 = t1.x2 + t4.x1, + t4.y1, + t5.x2, + t11.x3, + t11.y2, + t11.x4 +FROM t1 AS t4 +INNER JOIN t2 AS t5 + ON t4.x1 = t5.x2 INNER JOIN ( SELECT - t2.x3 AS x3, - t2.y2 AS y2, - t3.x4 AS x4 - FROM t3 AS t2 - INNER JOIN t4 AS t3 - ON t2.x3 = t3.x4 -) AS t6 - ON t0.y1 = t6.y2 \ No newline at end of file + t6.x3, + t6.y2, + t7.x4 + FROM t3 AS t6 + INNER JOIN t4 AS t7 + ON t6.x3 = t7.x4 +) AS t11 + ON t4.y1 = t11.y2 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_mutate_filter_join_no_cross_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_mutate_filter_join_no_cross_join/out.sql index 28adfeef19524..82946b9a13bc0 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_mutate_filter_join_no_cross_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_mutate_filter_join_no_cross_join/out.sql @@ -1,11 +1,5 @@ SELECT - t1.person_id AS person_id -FROM ( - SELECT - * - FROM person AS t0 - WHERE - ( - CAST(400 AS SMALLINT) <= CAST(40 AS TINYINT) - ) -) AS t1 \ No newline at end of file + t0.person_id +FROM person AS t0 +WHERE + CAST(400 AS SMALLINT) <= CAST(40 AS TINYINT) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_negate/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_negate/out.sql index 812bef8825b82..3ea20ad88c569 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_negate/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_negate/out.sql @@ -1,3 +1,5 @@ -NOT ( - t0.double_col > CAST(0 AS TINYINT) -) AS tmp \ No newline at end of file +SELECT + NOT ( + t0.double_col > CAST(0 AS TINYINT) + ) AS tmp +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_no_cart_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_no_cart_join/out.sql index d27c92e5a7a9c..580263e1f156e 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_no_cart_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_no_cart_join/out.sql @@ -1,24 +1,25 @@ SELECT - * + t7.ancestor_node_sort_order, + t7.n FROM ( SELECT - t4.ancestor_node_sort_order AS ancestor_node_sort_order, + t6.ancestor_node_sort_order, CAST(1 AS TINYINT) AS n FROM ( SELECT - t0.product_id AS product_id, - t2.ancestor_level_name AS ancestor_level_name, - t2.ancestor_level_number AS ancestor_level_number, - t2.ancestor_node_sort_order AS ancestor_node_sort_order, - t2.descendant_node_natural_key AS descendant_node_natural_key, - t2.product_level_name AS product_level_name - FROM facts AS t0 + t2.product_id, + t4.ancestor_level_name, + t4.ancestor_level_number, + t4.ancestor_node_sort_order, + t4.descendant_node_natural_key, + t4.product_level_name + FROM facts AS t2 INNER JOIN ( SELECT - t1.ancestor_level_name AS ancestor_level_name, - t1.ancestor_level_number AS ancestor_level_number, - t1.ancestor_node_sort_order AS ancestor_node_sort_order, - t1.descendant_node_natural_key AS descendant_node_natural_key, + t1.ancestor_level_name, + t1.ancestor_level_number, + t1.ancestor_node_sort_order, + t1.descendant_node_natural_key, CONCAT( LPAD('-', ( t1.ancestor_level_number - CAST(1 AS TINYINT) @@ -26,11 +27,11 @@ FROM ( t1.ancestor_level_name ) AS product_level_name FROM products AS t1 - ) AS t2 - ON t0.product_id = t2.descendant_node_natural_key - ) AS t4 + ) AS t4 + ON t2.product_id = t4.descendant_node_natural_key + ) AS t6 GROUP BY 1 -) AS t5 +) AS t7 ORDER BY - t5.ancestor_node_sort_order ASC \ No newline at end of file + t7.ancestor_node_sort_order ASC \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_no_cartesian_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_no_cartesian_join/out.sql index 60077ed03a096..a3df1de479ac6 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_no_cartesian_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_no_cartesian_join/out.sql @@ -1,51 +1,61 @@ SELECT - t9.customer_id AS customer_id, - t9.first_name AS first_name, - t9.last_name AS last_name, - t9.first_order AS first_order, - t9.most_recent_order AS most_recent_order, - t9.number_of_orders AS number_of_orders, - t11.total_amount AS customer_lifetime_value + t15.customer_id, + t15.first_name, + t15.last_name, + t15.first_order, + t15.most_recent_order, + t15.number_of_orders, + t13.total_amount AS customer_lifetime_value FROM ( SELECT - t0.customer_id AS customer_id, - t0.first_name AS first_name, - t0.last_name AS last_name, - t5.first_order AS first_order, - t5.most_recent_order AS most_recent_order, - t5.number_of_orders AS number_of_orders - FROM customers AS t0 - LEFT OUTER JOIN ( + t12.customer_id, + t12.first_name, + t12.last_name, + t12.first_order, + t12.most_recent_order, + t12.number_of_orders + FROM ( SELECT - t1.customer_id AS customer_id, - MIN(t1.order_date) AS first_order, - MAX(t1.order_date) AS most_recent_order, - COUNT(t1.order_id) AS number_of_orders - FROM orders AS t1 - GROUP BY - 1 - ) AS t5 - ON t0.customer_id = t5.customer_id -) AS t9 + t3.customer_id, + t3.first_name, + t3.last_name, + t8.customer_id AS customer_id_right, + t8.first_order, + t8.most_recent_order, + t8.number_of_orders + FROM customers AS t3 + LEFT OUTER JOIN ( + SELECT + t2.customer_id, + MIN(t2.order_date) AS first_order, + MAX(t2.order_date) AS most_recent_order, + COUNT(t2.order_id) AS number_of_orders + FROM orders AS t2 + GROUP BY + 1 + ) AS t8 + ON t3.customer_id = t8.customer_id + ) AS t12 +) AS t15 LEFT OUTER JOIN ( SELECT - t7.customer_id AS customer_id, - SUM(t7.amount) AS total_amount + t9.customer_id, + SUM(t9.amount) AS total_amount FROM ( SELECT - t2.payment_id AS payment_id, - t2.order_id AS order_id, - t2.payment_method AS payment_method, - t2.amount AS amount, - t3.order_id AS order_id_right, - t3.customer_id AS customer_id, - t3.order_date AS order_date, - t3.status AS status - FROM payments AS t2 - LEFT OUTER JOIN orders AS t3 - ON t2.order_id = t3.order_id - ) AS t7 + t4.payment_id, + t4.order_id, + t4.payment_method, + t4.amount, + t5.order_id AS order_id_right, + t5.customer_id, + t5.order_date, + t5.status + FROM payments AS t4 + LEFT OUTER JOIN orders AS t5 + ON t4.order_id = t5.order_id + ) AS t9 GROUP BY 1 -) AS t11 - ON t9.customer_id = t11.customer_id \ No newline at end of file +) AS t13 + ON t15.customer_id = t13.customer_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_no_cross_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_no_cross_join/out.sql index 0fe7408ed8c4a..fc3f08afa72b0 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_no_cross_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_no_cross_join/out.sql @@ -1,16 +1,16 @@ SELECT - t0.id AS id, - t0.personal AS personal, - t0.family AS family, - t1.taken AS taken, - t1.person AS person, - t1.quant AS quant, - t1.reading AS reading, - t2.id AS id_right, - t2.site AS site, - t2.dated AS dated -FROM person AS t0 -INNER JOIN survey AS t1 - ON t0.id = t1.person -INNER JOIN visited AS t2 - ON t2.id = t1.taken \ No newline at end of file + t3.id, + t3.personal, + t3.family, + t4.taken, + t4.person, + t4.quant, + t4.reading, + t5.id AS id_right, + t5.site, + t5.dated +FROM person AS t3 +INNER JOIN survey AS t4 + ON t3.id = t4.person +INNER JOIN visited AS t5 + ON t5.id = t4.taken \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_not_exists/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_not_exists/out.sql index 7c62bce20d7f8..548a1efef2ec7 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_not_exists/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_not_exists/out.sql @@ -1,21 +1,15 @@ SELECT - * + t0.key1, + t0.key2, + t0.value1 FROM foo_t AS t0 WHERE NOT ( EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM ( - SELECT - * - FROM bar_t AS t1 - WHERE - ( - t0.key1 = t1.key1 - ) - ) AS t2 - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM bar_t AS t1 + WHERE + t0.key1 = t1.key1 ) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/column/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/column/out.sql index a401619ae2d82..bb666f269b2a8 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/column/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/column/out.sql @@ -1,5 +1,8 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 ORDER BY t0.f ASC \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/random/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/random/out.sql index bd2fd25215ee9..356b091282c5e 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/random/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_order_by/random/out.sql @@ -1,5 +1,8 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 ORDER BY RANDOM() ASC \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_order_by_expr/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_order_by_expr/out.sql index 51532051bd3f3..99a46813f6527 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_order_by_expr/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_order_by_expr/out.sql @@ -1,13 +1,8 @@ SELECT - * -FROM ( - SELECT - * - FROM t AS t0 - WHERE - ( - t0.a = CAST(1 AS TINYINT) - ) -) AS t1 + t0.a, + t0.b +FROM t AS t0 +WHERE + t0.a = CAST(1 AS TINYINT) ORDER BY - CONCAT(t1.b, 'a') ASC \ No newline at end of file + CONCAT(t0.b, 'a') ASC \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_searched_case/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_searched_case/out.sql index ae63fb4838b3f..31c40c343501e 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_searched_case/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_searched_case/out.sql @@ -1,7 +1,9 @@ -CASE - WHEN t0.f > CAST(0 AS TINYINT) - THEN t0.d * CAST(2 AS TINYINT) - WHEN t0.c < CAST(0 AS TINYINT) - THEN t0.a * CAST(2 AS TINYINT) - ELSE CAST(NULL AS BIGINT) -END AS tmp \ No newline at end of file +SELECT + CASE + WHEN t0.f > CAST(0 AS TINYINT) + THEN t0.d * CAST(2 AS TINYINT) + WHEN t0.c < CAST(0 AS TINYINT) + THEN t0.a * CAST(2 AS TINYINT) + ELSE CAST(NULL AS BIGINT) + END AS tmp +FROM alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/anti.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/anti.sql index 3e0c659089b25..c598c1264a74d 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/anti.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/anti.sql @@ -1,21 +1,25 @@ SELECT - * + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE NOT ( EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM ( - SELECT - * - FROM functional_alltypes AS t1 - WHERE - ( - t0.string_col = t1.string_col - ) - ) AS t2 - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM functional_alltypes AS t1 + WHERE + t0.string_col = t1.string_col ) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/semi.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/semi.sql index 0f4cb117f736a..16089afced58f 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/semi.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_in_not_exists/semi.sql @@ -1,19 +1,23 @@ SELECT - * + t0.id, + t0.bool_col, + t0.tinyint_col, + t0.smallint_col, + t0.int_col, + t0.bigint_col, + t0.float_col, + t0.double_col, + t0.date_string_col, + t0.string_col, + t0.timestamp_col, + t0.year, + t0.month FROM functional_alltypes AS t0 WHERE EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM ( - SELECT - * - FROM functional_alltypes AS t1 - WHERE - ( - t0.string_col = t1.string_col - ) - ) AS t2 - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM functional_alltypes AS t1 + WHERE + t0.string_col = t1.string_col ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_join/out.sql index de06d3805e28e..e9c93029c6372 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_self_reference_join/out.sql @@ -1,8 +1,8 @@ SELECT - t0.c AS c, - t0.f AS f, - t0.foo_id AS foo_id, - t0.bar_id AS bar_id -FROM star1 AS t0 -INNER JOIN star1 AS t1 - ON t0.foo_id = t1.bar_id \ No newline at end of file + t1.c, + t1.f, + t1.foo_id, + t1.bar_id +FROM star1 AS t1 +INNER JOIN star1 AS t3 + ON t1.foo_id = t3.bar_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_simple_case/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_simple_case/out.sql index 7dfc00dcf0634..3575c8d6e653b 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_simple_case/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_simple_case/out.sql @@ -1 +1,3 @@ -CASE t0.g WHEN 'foo' THEN 'bar' WHEN 'baz' THEN 'qux' ELSE 'default' END AS tmp \ No newline at end of file +SELECT + CASE t0.g WHEN 'foo' THEN 'bar' WHEN 'baz' THEN 'qux' ELSE 'default' END AS tmp +FROM alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_sort_aggregation_translation_failure/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_sort_aggregation_translation_failure/out.sql index 0f520487cbb8d..e8f9420b42633 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_sort_aggregation_translation_failure/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_sort_aggregation_translation_failure/out.sql @@ -1,8 +1,9 @@ SELECT - * + t1.string_col, + t1.foo FROM ( SELECT - t0.string_col AS string_col, + t0.string_col, MAX(t0.double_col) AS foo FROM functional_alltypes AS t0 GROUP BY diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_subquery_aliased/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_subquery_aliased/out.sql index ab9ad36231709..e0f8941f35272 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_subquery_aliased/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_subquery_aliased/out.sql @@ -1,14 +1,14 @@ SELECT - t2.foo_id AS foo_id, - t2.total AS total, - t1.value1 AS value1 + t4.foo_id, + t4.total, + t2.value1 FROM ( SELECT - t0.foo_id AS foo_id, + t0.foo_id, SUM(t0.f) AS total FROM star1 AS t0 GROUP BY 1 -) AS t2 -INNER JOIN star2 AS t1 - ON t2.foo_id = t1.foo_id \ No newline at end of file +) AS t4 +INNER JOIN star2 AS t2 + ON t4.foo_id = t2.foo_id \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery/out.sql index 3ded1e24f7321..0b1767f7a7409 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery/out.sql @@ -1,19 +1,21 @@ SELECT - * + t0.job, + t0.dept_id, + t0.year, + t0.y FROM foo AS t0 WHERE - ( - t0.y > ( + t0.y > ( + SELECT + AVG(t2.y) AS "Mean(y)" + FROM ( SELECT - AVG(t2.y) AS "Mean(y)" - FROM ( - SELECT - * - FROM foo AS t1 - WHERE - ( - t0.dept_id = t1.dept_id - ) - ) AS t2 - ) + t1.job, + t1.dept_id, + t1.year, + t1.y + FROM foo AS t1 + WHERE + t1.dept_id = t1.dept_id + ) AS t2 ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery_with_join/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery_with_join/out.sql index 631fc089852e4..9f3f24cd76eb3 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery_with_join/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_where_correlated_subquery_with_join/out.sql @@ -1,33 +1,31 @@ SELECT - * + t9.p_partkey, + t9.ps_supplycost FROM ( SELECT - t0.p_partkey AS p_partkey, - t1.ps_supplycost AS ps_supplycost - FROM part AS t0 - INNER JOIN partsupp AS t1 - ON t0.p_partkey = t1.ps_partkey -) AS t5 + t3.p_partkey, + t4.ps_supplycost + FROM part AS t3 + INNER JOIN partsupp AS t4 + ON t3.p_partkey = t4.ps_partkey +) AS t9 WHERE - ( - t5.ps_supplycost = ( + t9.ps_supplycost = ( + SELECT + MIN(t11.ps_supplycost) AS "Min(ps_supplycost)" + FROM ( SELECT - MIN(t7.ps_supplycost) AS "Min(ps_supplycost)" + t10.ps_partkey, + t10.ps_supplycost FROM ( SELECT - * - FROM ( - SELECT - t1.ps_partkey AS ps_partkey, - t1.ps_supplycost AS ps_supplycost - FROM partsupp AS t1 - INNER JOIN supplier AS t2 - ON t2.s_suppkey = t1.ps_suppkey - ) AS t6 - WHERE - ( - t6.ps_partkey = t5.p_partkey - ) - ) AS t7 - ) + t5.ps_partkey, + t5.ps_supplycost + FROM partsupp AS t5 + INNER JOIN supplier AS t6 + ON t6.s_suppkey = t5.ps_suppkey + ) AS t10 + WHERE + t10.ps_partkey = t9.p_partkey + ) AS t11 ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_where_simple_comparisons/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_where_simple_comparisons/out.sql index 2c8cebaa0a08d..e1914ac959bd9 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_where_simple_comparisons/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_where_simple_comparisons/out.sql @@ -1,11 +1,10 @@ SELECT - * + t0.c, + t0.f, + t0.foo_id, + t0.bar_id FROM star1 AS t0 WHERE - ( - t0.f > CAST(0 AS TINYINT) - ) AND ( - t0.c < ( - t0.f * CAST(2 AS TINYINT) - ) + t0.f > CAST(0 AS TINYINT) AND t0.c < ( + t0.f * CAST(2 AS TINYINT) ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_sql/test_where_uncorrelated_subquery/out.sql b/ibis/backends/tests/sql/snapshots/test_sql/test_where_uncorrelated_subquery/out.sql index 5240818910ca0..d64e69ba38949 100644 --- a/ibis/backends/tests/sql/snapshots/test_sql/test_where_uncorrelated_subquery/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_sql/test_where_uncorrelated_subquery/out.sql @@ -1,9 +1,12 @@ SELECT - * + t0.job, + t0.dept_id, + t0.year, + t0.y FROM foo AS t0 WHERE - t0.job IN (( + t0.job IN ( SELECT - t1.job AS job + t1.job FROM bar AS t1 - )) \ No newline at end of file + ) \ No newline at end of file diff --git a/ibis/backends/tests/sql/test_compiler.py b/ibis/backends/tests/sql/test_compiler.py index ec7b264ffbf3a..bc789dba86ba8 100644 --- a/ibis/backends/tests/sql/test_compiler.py +++ b/ibis/backends/tests/sql/test_compiler.py @@ -5,7 +5,6 @@ import pytest import ibis - from ibis.backends.tests.sql.conftest import to_sql from ibis.tests.util import assert_decompile_roundtrip, schemas_eq @@ -206,7 +205,7 @@ def test_subquery_where_location(snapshot): .aggregate(foo=lambda t: t.float_col.sum()) .foo.count() ) - out = Compiler.to_sql(expr, params={param: "20140101"}) + out = to_sql(expr, params={param: "20140101"}) snapshot.assert_match(out, "out.sql") # params get different auto incremented counter identifiers assert_decompile_roundtrip(expr, snapshot, eq=schemas_eq) diff --git a/ibis/backends/tests/sql/test_select_sql.py b/ibis/backends/tests/sql/test_select_sql.py index bca97afebb728..2ffaad9120f26 100644 --- a/ibis/backends/tests/sql/test_select_sql.py +++ b/ibis/backends/tests/sql/test_select_sql.py @@ -6,7 +6,7 @@ import ibis from ibis import _ from ibis.backends.tests.sql.conftest import to_sql -from ibis.tests.util import assert_decompile_roundtrip +from ibis.tests.util import assert_decompile_roundtrip, schemas_eq pytestmark = pytest.mark.duckdb @@ -35,7 +35,9 @@ id="limit_then_filter", ), param(lambda star1, **_: star1.count(), id="aggregate_table_count_metric"), - param(lambda star1, **_: star1.view(), id="self_reference_simple"), + # TODO: this is automatically simplified to `t`, so it's probably not a + # useful test to roundtrip *just* a call to view + # param(lambda star1, **_: star1.view(), id="self_reference_simple"), param(lambda t, **_: t, id="test_physical_table_reference_translate"), ], ) @@ -48,11 +50,7 @@ def test_select_sql(alltypes, star1, expr_fn, snapshot): def test_nameless_table(snapshot): # Generate a unique table name when we haven't passed on nameless = ibis.table([("key", "string")]) - assert to_sql(nameless) == f"SELECT t0.*\nFROM {nameless.op().name} t0" - - expr = ibis.table([("key", "string")], name="baz") - snapshot.assert_match(to_sql(expr), "out.sql") - assert_decompile_roundtrip(expr, snapshot) + assert nameless.op().name is not None def test_simple_joins(star1, star2, snapshot): @@ -248,19 +246,11 @@ def test_fuse_projections(snapshot): def test_projection_filter_fuse(projection_fuse_filter, snapshot): expr1, expr2, expr3 = projection_fuse_filter - sql1 = Compiler.to_sql(expr1) - sql2 = Compiler.to_sql(expr2) + sql1 = ibis.to_sql(expr1) + sql2 = ibis.to_sql(expr2) assert sql1 == sql2 - # ideally sql1 == sql3 but the projection logic has been a mess for a long - # time and causes bugs like - # - # https://github.com/ibis-project/ibis/issues/4003 - # - # so we're conservative in fusing projections and filters - # - # even though it may seem obvious what to do, it's not snapshot.assert_match(to_sql(expr3), "out.sql") @@ -427,15 +417,14 @@ def test_scalar_subquery_different_table(foo, bar, snapshot): snapshot.assert_match(to_sql(expr), "out.sql") -# TODO(kszucs): should do snapshot testing instead -# def test_exists_subquery_repr(t1, t2): -# # GH #660 +def test_exists_subquery(t1, t2, snapshot): + # GH #660 -# cond = t1.key1 == t2.key1 -# expr = t1[cond.any()] -# stmt = get_query(expr) + cond = t1.key1 == t2.key1 + expr = t1[cond.any()] -# repr(stmt.where[0]) + snapshot.assert_match(to_sql(expr), "out.sql") + assert repr(expr) def test_filter_inside_exists(snapshot): @@ -523,10 +512,6 @@ def test_join_filtered_tables_no_pushdown(snapshot): joined = tbl_a_filter.left_join(tbl_b_filter, ["year", "month", "day"]) result = joined[tbl_a_filter.value_a, tbl_b_filter.value_b] - join_op = result.op().table - assert join_op.left == tbl_a_filter.op() - assert join_op.right == tbl_b_filter.op() - snapshot.assert_match(to_sql(result), "out.sql") diff --git a/ibis/backends/tests/sql/test_sql.py b/ibis/backends/tests/sql/test_sql.py index ac4d07876d7e9..d4bb8fe8033e2 100644 --- a/ibis/backends/tests/sql/test_sql.py +++ b/ibis/backends/tests/sql/test_sql.py @@ -141,10 +141,7 @@ def test_named_expr(functional_alltypes, snapshot): ], ids=["inner", "left", "outer", "inner_select", "left_select", "outer_select"], ) -def test_joins(tpch_region, tpch_nation, expr_fn, snapshot): - region = tpch_region - nation = tpch_nation - +def test_joins(region, nation, expr_fn, snapshot): expr = expr_fn(region, nation) snapshot.assert_match(to_sql(expr), "out.sql") @@ -160,15 +157,12 @@ def test_join_just_materialized(nation, region, customer, snapshot): snapshot.assert_match(to_sql(joined), "out.sql") -def test_full_outer_join(tpch_region, tpch_nation): +def test_full_outer_join(region, nation): """Testing full outer join separately due to previous issue with outer join resulting in left outer join (issue #1773)""" - region = tpch_region - nation = tpch_nation - predicate = region.r_regionkey == nation.n_regionkey joined = region.outer_join(nation, predicate) - joined_sql_str = str(joined.compile()) + joined_sql_str = to_sql(joined) assert "full" in joined_sql_str.lower() assert "left" not in joined_sql_str.lower() diff --git a/ibis/backends/tests/test_aggregation.py b/ibis/backends/tests/test_aggregation.py index 0bb706f521e69..13ba75b6d2d4a 100644 --- a/ibis/backends/tests/test_aggregation.py +++ b/ibis/backends/tests/test_aggregation.py @@ -48,11 +48,6 @@ except ImportError: PolarsInvalidOperationError = None -try: - from snowflake.connector.errors import ProgrammingError as SnowflakeProgrammingError -except ImportError: - SnowflakeProgrammingError = None - @reduction(input_type=[dt.double], output_type=dt.double) def mean_udf(s): @@ -764,7 +759,16 @@ def mean_and_std(v): id="collect", marks=[ pytest.mark.notimpl( - ["impala", "mysql", "sqlite", "mssql", "druid", "oracle", "exasol"], + [ + "impala", + "mysql", + "sqlite", + "datafusion", + "mssql", + "druid", + "oracle", + "exasol", + ], raises=com.OperationNotDefinedError, ), pytest.mark.broken( @@ -847,7 +851,7 @@ def test_reduction_ops( id="cond", marks=[ pytest.mark.notyet( - ["mysql"], + ["snowflake", "mysql"], raises=com.UnsupportedOperationError, reason="backend does not support filtered count distinct with more than one column", ), @@ -1008,7 +1012,7 @@ def test_quantile( id="covar_pop", marks=[ pytest.mark.notimpl( - ["dask", "polars", "druid"], + ["dask", "pandas", "polars", "druid"], raises=com.OperationNotDefinedError, ), pytest.mark.notyet( @@ -1023,7 +1027,7 @@ def test_quantile( id="covar_samp", marks=[ pytest.mark.notimpl( - ["dask", "polars", "druid"], + ["dask", "pandas", "polars", "druid"], raises=com.OperationNotDefinedError, ), pytest.mark.notyet( @@ -1038,7 +1042,7 @@ def test_quantile( id="corr_pop", marks=[ pytest.mark.notimpl( - ["dask", "druid"], + ["dask", "pandas", "druid"], raises=com.OperationNotDefinedError, ), pytest.mark.notyet( @@ -1063,7 +1067,7 @@ def test_quantile( id="corr_samp", marks=[ pytest.mark.notimpl( - ["dask", "druid"], + ["dask", "pandas", "druid"], raises=com.OperationNotDefinedError, ), pytest.mark.notyet( @@ -1081,7 +1085,7 @@ def test_quantile( reason="Correlation with how='sample' is not supported.", ), pytest.mark.notyet( - ["trino", "postgres", "oracle"], + ["trino", "postgres", "duckdb", "snowflake", "oracle"], raises=ValueError, reason="XXXXSQLExprTranslator only implements population correlation coefficient", ), @@ -1097,7 +1101,7 @@ def test_quantile( id="covar_pop_bool", marks=[ pytest.mark.notimpl( - ["dask", "polars", "druid"], + ["dask", "pandas", "polars", "druid"], raises=com.OperationNotDefinedError, ), pytest.mark.notyet( @@ -1116,7 +1120,7 @@ def test_quantile( id="corr_pop_bool", marks=[ pytest.mark.notimpl( - ["dask", "druid"], + ["dask", "pandas", "druid"], raises=com.OperationNotDefinedError, ), pytest.mark.notyet( @@ -1639,17 +1643,16 @@ def test_grouped_case(backend, con): ["datafusion", "mssql", "polars", "exasol"], raises=com.OperationNotDefinedError ) @pytest.mark.broken( - ["dask"], + ["dask", "pandas"], reason="Dask and Pandas do not windowize this operation correctly", raises=AssertionError, ) @pytest.mark.notyet(["impala", "flink"], raises=com.UnsupportedOperationError) @pytest.mark.notyet(["clickhouse"], raises=ClickhouseDatabaseError) -@pytest.mark.notyet(["druid", "trino"], raises=sa.exc.ProgrammingError) -@pytest.mark.notyet(["snowflake"], raises=SnowflakeProgrammingError) -@pytest.mark.notyet("mysql", raises=sa.exc.NotSupportedError) -@pytest.mark.notyet("oracle", raises=sa.exc.DatabaseError) -@pytest.mark.notyet("pyspark", raises=PysparkAnalysisException) +@pytest.mark.notyet(["druid", "trino", "snowflake"], raises=sa.exc.ProgrammingError) +@pytest.mark.notyet(["mysql"], raises=sa.exc.NotSupportedError) +@pytest.mark.notyet(["oracle"], raises=sa.exc.DatabaseError) +@pytest.mark.notyet(["pyspark"], raises=PysparkAnalysisException) def test_group_concat_over_window(backend, con): input_df = pd.DataFrame( { diff --git a/ibis/backends/tests/test_api.py b/ibis/backends/tests/test_api.py index 0b4d5ad070076..903bbff3ff394 100644 --- a/ibis/backends/tests/test_api.py +++ b/ibis/backends/tests/test_api.py @@ -119,7 +119,7 @@ def test_limit_chain(alltypes, expr_fn): "expr_fn", [ param(lambda t: t, id="alltypes table"), - param(lambda t: t.join(t.view(), t.id == t.view().int_col), id="self join"), + param(lambda t: t.join(t.view(), [("id", "int_col")]), id="self join"), ], ) def test_unbind(alltypes, expr_fn): diff --git a/ibis/backends/tests/test_array.py b/ibis/backends/tests/test_array.py index edfba96d9de84..5d07da9e3abf1 100644 --- a/ibis/backends/tests/test_array.py +++ b/ibis/backends/tests/test_array.py @@ -133,6 +133,7 @@ def test_array_concat_variadic(con): # Issues #2370 +@pytest.mark.notimpl(["datafusion"], raises=BaseException) @pytest.mark.notimpl(["flink"], raises=com.OperationNotDefinedError) @pytest.mark.notyet( ["postgres", "trino"], @@ -181,7 +182,7 @@ def test_np_array_literal(con): @pytest.mark.parametrize("idx", range(3)) -@pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl(["polars", "datafusion"], raises=com.OperationNotDefinedError) def test_array_index(con, idx): arr = [1, 2, 3] expr = ibis.literal(arr) @@ -482,7 +483,7 @@ def test_array_filter(backend, con, input, output): @builtin_array @pytest.mark.notimpl( - ["mssql", "polars", "postgres"], + ["mssql", "pandas", "polars", "postgres"], raises=com.OperationNotDefinedError, ) @pytest.mark.notimpl(["dask"], raises=com.OperationNotDefinedError) diff --git a/ibis/backends/tests/test_benchmarks.py b/ibis/backends/tests/test_benchmarks.py index 9c23b1fc09b63..0305b4fcd6b14 100644 --- a/ibis/backends/tests/test_benchmarks.py +++ b/ibis/backends/tests/test_benchmarks.py @@ -717,7 +717,6 @@ def test_repr_join(benchmark, customers, orders, orders_items, products): @pytest.mark.parametrize("overwrite", [True, False], ids=["overwrite", "no_overwrite"]) def test_insert_duckdb(benchmark, overwrite, tmp_path): pytest.importorskip("duckdb") - pytest.importorskip("duckdb_engine") n_rows = int(1e4) table_name = "t" @@ -806,7 +805,6 @@ def test_duckdb_to_pyarrow(benchmark, sql, ddb) -> None: def test_ibis_duckdb_to_pyarrow(benchmark, sql, ddb) -> None: pytest.importorskip("duckdb") - pytest.importorskip("duckdb_engine") con = ibis.duckdb.connect(ddb, read_only=True) @@ -876,7 +874,6 @@ def test_big_join_expr(benchmark, src, diff): def test_big_join_execute(benchmark, nrels): pytest.importorskip("duckdb") - pytest.importorskip("duckdb_engine") con = ibis.duckdb.connect() diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index dc9d74caa01b1..f1f9ec4a18542 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -311,12 +311,17 @@ def test_rename_table(con, temp_table, temp_table_orig): assert temp_table_orig not in con.list_tables() -@mark.notimpl(["polars", "druid"]) +@mark.notimpl(["datafusion", "polars", "druid"]) @mark.never(["impala", "pyspark"], reason="No non-nullable datatypes") @mark.notyet( ["trino"], reason="trino doesn't support NOT NULL in its in-memory catalog" ) -@mark.broken(["flink"], reason="shows not nullable column as nullable") +@mark.broken(["snowflake"], reason="snowflake shows not nullable column as nullable") +@pytest.mark.notimpl( + ["flink"], + raises=com.IbisError, + reason="`tbl_properties` is required when creating table with schema", +) def test_nullable_input_output(con, temp_table): sch = ibis.schema( [("foo", "int64"), ("bar", dt.int64(nullable=False)), ("baz", "boolean")] @@ -899,12 +904,10 @@ def test_self_join_memory_table(backend, con, monkeypatch): t = ibis.memtable({"x": [1, 2], "y": [2, 1], "z": ["a", "b"]}) t_view = t.view() expr = t.join(t_view, t.x == t_view.y).select("x", "y", "z", "z_right") - result = con.execute(expr).sort_values("x").reset_index(drop=True) expected = pd.DataFrame( {"x": [1, 2], "y": [2, 1], "z": ["a", "b"], "z_right": ["b", "a"]} ) - backend.assert_frame_equal(result, expected) @@ -931,9 +934,16 @@ def test_create_from_in_memory_table(con, temp_table, arg, func, monkeypatch): @pytest.mark.usefixtures("backend") def test_default_backend_option(monkeypatch): - monkeypatch.setattr(ibis.options, "default_backend", ibis.pandas) + pytest.importorskip("duckdb") + + # verify that there's nothing already set + assert ibis.options.default_backend is None + + # patch in duckdb + monkeypatch.setattr(ibis.options, "default_backend", ibis.duckdb) + backend = ibis.config._default_backend() - assert backend.name == "pandas" + assert backend.name == "duckdb" # backend is used to ensure that this test runs in CI in the setting @@ -1418,7 +1428,7 @@ def gen_test_name(con: BaseBackend) -> str: @mark.notimpl( - ["polars"], + ["datafusion", "polars"], raises=NotImplementedError, reason="overwriting not implemented in ibis for this backend", ) diff --git a/ibis/backends/tests/test_examples.py b/ibis/backends/tests/test_examples.py index d57836056ae0b..5af4348affdfc 100644 --- a/ibis/backends/tests/test_examples.py +++ b/ibis/backends/tests/test_examples.py @@ -13,7 +13,7 @@ (LINUX or MACOS) and SANDBOXED, reason="nix on linux cannot download duckdb extensions or data due to sandboxing", ) -@pytest.mark.notimpl(["dask", "pyspark", "flink", "exasol"]) +@pytest.mark.notimpl(["dask", "datafusion", "exasol", "pyspark"]) @pytest.mark.notyet(["clickhouse", "druid", "impala", "mssql", "trino"]) @pytest.mark.parametrize( ("example", "columns"), diff --git a/ibis/backends/tests/test_export.py b/ibis/backends/tests/test_export.py index cb04a531507cd..09711ecc04171 100644 --- a/ibis/backends/tests/test_export.py +++ b/ibis/backends/tests/test_export.py @@ -30,12 +30,6 @@ DuckDBNotImplementedException = DuckDBParserException = None -try: - from snowflake.connector.errors import ProgrammingError as SnowflakeProgrammingError -except ImportError: - SnowflakeProgrammingError = None - - limit = [ param( 42, @@ -153,7 +147,7 @@ def test_column_to_pyarrow_table_schema(awards_players): assert array.type == pa.string() or array.type == pa.large_string() -@pytest.mark.notimpl(["dask", "datafusion", "flink"]) +@pytest.mark.notimpl(["pandas", "dask", "datafusion", "flink"]) @pytest.mark.notyet( ["clickhouse"], raises=AssertionError, @@ -168,7 +162,7 @@ def test_table_pyarrow_batch_chunk_size(awards_players): util.consume(batch_reader) -@pytest.mark.notimpl(["dask", "datafusion", "flink"]) +@pytest.mark.notimpl(["pandas", "dask", "datafusion", "flink"]) @pytest.mark.notyet( ["clickhouse"], raises=AssertionError, @@ -371,8 +365,10 @@ def test_table_to_csv_writer_kwargs(delimiter, tmp_path, awards_players): marks=[ pytest.mark.notyet(["impala"], reason="precision not supported"), pytest.mark.notyet(["duckdb"], reason="precision is out of range"), - pytest.mark.notyet(["druid", "trino"], raises=sa.exc.ProgrammingError), - pytest.mark.notyet(["snowflake"], raises=SnowflakeProgrammingError), + pytest.mark.notyet( + ["druid", "mssql", "snowflake", "trino"], + raises=sa.exc.ProgrammingError, + ), pytest.mark.notyet(["oracle"], raises=sa.exc.DatabaseError), pytest.mark.notyet(["mysql"], raises=sa.exc.OperationalError), pytest.mark.notyet( @@ -403,6 +399,7 @@ def test_to_pyarrow_decimal(backend, dtype, pyarrow_dtype): "mysql", "oracle", "postgres", + "snowflake", "sqlite", "bigquery", "dask", @@ -414,11 +411,6 @@ def test_to_pyarrow_decimal(backend, dtype, pyarrow_dtype): reason="read_delta not yet implemented", ) @pytest.mark.notyet(["clickhouse"], raises=Exception) -@pytest.mark.notyet( - ["snowflake"], - raises=Exception, - reason="deltalake doesn't support nanosecond timestamps", -) @pytest.mark.notyet(["mssql", "pandas"], raises=PyDeltaTableError) @pytest.mark.notyet( ["druid"], diff --git a/ibis/backends/tests/test_generic.py b/ibis/backends/tests/test_generic.py index d560d1aed14e6..0d4f7bb69c03f 100644 --- a/ibis/backends/tests/test_generic.py +++ b/ibis/backends/tests/test_generic.py @@ -48,12 +48,6 @@ except ImportError: ExaQueryError = None -try: - from snowflake.connector.errors import ProgrammingError as SnowflakeProgrammingError -except ImportError: - SnowflakeProgrammingError = None - - NULL_BACKEND_TYPES = { "bigquery": "NULL", "clickhouse": "Nullable(Nothing)", @@ -168,7 +162,6 @@ def test_isna(backend, alltypes, col, filt): [ "bigquery", "clickhouse", - "datafusion", "duckdb", "impala", "postgres", @@ -221,7 +214,9 @@ def test_coalesce(con, expr, expected): # TODO(dask) - identicalTo - #2553 -@pytest.mark.notimpl(["clickhouse", "dask", "pyspark", "mssql", "druid", "exasol"]) +@pytest.mark.notimpl( + ["clickhouse", "datafusion", "dask", "pyspark", "mssql", "druid", "exasol"] +) def test_identical_to(backend, alltypes, sorted_df): sorted_alltypes = alltypes.order_by("id") df = sorted_df @@ -641,7 +636,7 @@ def test_isin_notin(backend, alltypes, df, ibis_op, pandas_op): reason="dask doesn't support Series as isin/notin argument", raises=NotImplementedError, ) -@pytest.mark.notimpl(["druid"]) +@pytest.mark.notimpl(["datafusion", "druid"]) @pytest.mark.parametrize( ("ibis_op", "pandas_op"), [ @@ -659,13 +654,11 @@ def test_isin_notin(backend, alltypes, df, ibis_op, pandas_op): _.string_col.notin(_.string_col), lambda df: ~df.string_col.isin(df.string_col), id="notin_col", - marks=[pytest.mark.notimpl(["datafusion"])], ), param( (_.bigint_col + 1).notin(_.string_col.length() + 1), lambda df: ~(df.bigint_col.add(1)).isin(df.string_col.str.len().add(1)), id="notin_expr", - marks=[pytest.mark.notimpl(["datafusion"])], ), ], ) @@ -782,7 +775,8 @@ def test_select_filter_select(backend, alltypes, df): backend.assert_series_equal(result, expected) -@pytest.mark.broken(["mssql"], raises=sa.exc.OperationalError) +@pytest.mark.notimpl(["datafusion"], raises=com.OperationNotDefinedError) +@pytest.mark.broken(["mssql"], raises=sa.exc.ProgrammingError) def test_between(backend, alltypes, df): expr = alltypes.double_col.between(5, 10) result = expr.execute().rename("double_col") @@ -903,7 +897,7 @@ def test_isin_uncorrelated( @pytest.mark.broken(["polars"], reason="incorrect answer") -@pytest.mark.notimpl(["pyspark", "druid", "exasol"]) +@pytest.mark.notimpl(["datafusion", "pyspark", "druid", "exasol"]) @pytest.mark.notyet(["dask"], reason="not supported by the backend") def test_isin_uncorrelated_filter( backend, batting, awards_players, batting_df, awards_players_df @@ -1016,8 +1010,13 @@ def test_memtable_column_naming_mismatch(backend, con, monkeypatch, df, columns) ibis.memtable(df, columns=columns) +@pytest.mark.xfail( + raises=com.IntegrityError, reason="inner join convenience not implemented" +) @pytest.mark.notimpl( - ["dask", "pandas", "polars"], raises=NotImplementedError, reason="not a SQL backend" + ["dask", "datafusion", "pandas", "polars"], + raises=NotImplementedError, + reason="not a SQL backend", ) @pytest.mark.notimpl( ["pyspark"], reason="pyspark doesn't generate SQL", raises=NotImplementedError @@ -1274,6 +1273,7 @@ def test_hash_consistent(backend, alltypes): "pandas", "dask", "bigquery", + "datafusion", "druid", "impala", "mssql", @@ -1281,9 +1281,9 @@ def test_hash_consistent(backend, alltypes): "oracle", "postgres", "pyspark", + "snowflake", "sqlite", "exasol", - "snowflake", ] ) @pytest.mark.parametrize( @@ -1334,9 +1334,7 @@ def test_hash_consistent(backend, alltypes): raises=sa.exc.ProgrammingError, reason="raises TrinoUserError", ), - pytest.mark.broken( - ["polars", "datafusion"], reason="this cast is allowed" - ), + pytest.mark.broken(["polars"], reason="casts to 1672531200000000000"), ], ), param( @@ -1351,7 +1349,6 @@ def test_hash_consistent(backend, alltypes): reason="raises TrinoUserError", ), pytest.mark.broken(["polars"], reason="casts to 1672531200000000000"), - pytest.mark.broken(["datafusion"], reason="casts to 1672531200000000"), ], ), ], @@ -1373,9 +1370,9 @@ def test_try_cast_expected(con, from_val, to_type, expected): "oracle", "postgres", "pyspark", + "snowflake", "sqlite", "exasol", - "snowflake", ] ) def test_try_cast_table(backend, con): @@ -1403,9 +1400,9 @@ def test_try_cast_table(backend, con): "oracle", "postgres", "pyspark", + "snowflake", "sqlite", "exasol", - "snowflake", ] ) @pytest.mark.parametrize( @@ -1571,15 +1568,10 @@ def test_static_table_slice(backend, slc, expected_count_fn): ids=str, ) @pytest.mark.notyet( - ["mysql", "trino"], + ["mysql", "snowflake", "trino"], raises=sa.exc.ProgrammingError, reason="backend doesn't support dynamic limit/offset", ) -@pytest.mark.notyet( - ["snowflake"], - raises=SnowflakeProgrammingError, - reason="backend doesn't support dynamic limit/offset", -) @pytest.mark.notimpl( ["mssql"], raises=sa.exc.CompileError, @@ -1624,7 +1616,7 @@ def test_dynamic_table_slice(backend, slc, expected_count_fn): @pytest.mark.notyet( - ["mysql", "trino"], + ["mysql", "snowflake", "trino"], raises=sa.exc.ProgrammingError, reason="backend doesn't support dynamic limit/offset", ) @@ -1632,11 +1624,6 @@ def test_dynamic_table_slice(backend, slc, expected_count_fn): ["exasol"], raises=sa.exc.CompileError, ) -@pytest.mark.notyet( - ["snowflake"], - raises=SnowflakeProgrammingError, - reason="backend doesn't support dynamic limit/offset", -) @pytest.mark.notyet( ["clickhouse"], raises=ClickhouseDriverDatabaseError, diff --git a/ibis/backends/tests/test_interactive.py b/ibis/backends/tests/test_interactive.py index 111be16de5ee8..8014ab7f1fa20 100644 --- a/ibis/backends/tests/test_interactive.py +++ b/ibis/backends/tests/test_interactive.py @@ -15,93 +15,80 @@ import pytest +import ibis from ibis import config -def test_interactive_execute_on_repr(con): - table = con.table("functional_alltypes") - expr = table.bigint_col.sum() - with config.option_context("interactive", True): - repr(expr) +@pytest.fixture +def queries(monkeypatch): + queries = [] + monkeypatch.setattr(ibis.options, "verbose", True) + monkeypatch.setattr(ibis.options, "verbose_log", queries.append) + monkeypatch.setattr(ibis.options, "interactive", True) + return queries + - assert len(con.executed_queries) > 0 +@pytest.fixture(scope="module") +def table(con): + return con.table("functional_alltypes") -def test_repr_png_is_none_in_interactive(con): - table = con.table("functional_alltypes") +def test_interactive_execute_on_repr(table, queries, snapshot): + repr(table.bigint_col.sum()) + snapshot.assert_match(queries[0], "out.sql") + +def test_repr_png_is_none_in_interactive(table): with config.option_context("interactive", True): assert table._repr_png_() is None -def test_repr_png_is_not_none_in_not_interactive(con): +def test_repr_png_is_not_none_in_not_interactive(table): pytest.importorskip("ibis.expr.visualize") - table = con.table("functional_alltypes") - with config.option_context("interactive", False), config.option_context( "graphviz_repr", True ): assert table._repr_png_() is not None -def test_default_limit(con, snapshot): - table = con.table("functional_alltypes").select("id", "bool_col") - - with config.option_context("interactive", True): - repr(table) - - snapshot.assert_match(con.executed_queries[0], "out.sql") - +def test_default_limit(table, snapshot, queries): + repr(table.select("id", "bool_col")) -def test_respect_set_limit(con, snapshot): - table = con.table("functional_alltypes").select("id", "bool_col").limit(10) + snapshot.assert_match(queries[0], "out.sql") - with config.option_context("interactive", True): - repr(table) - snapshot.assert_match(con.executed_queries[0], "out.sql") +def test_respect_set_limit(table, snapshot, queries): + repr(table.select("id", "bool_col").limit(10)) + snapshot.assert_match(queries[0], "out.sql") -def test_disable_query_limit(con, snapshot): - table = con.table("functional_alltypes").select("id", "bool_col") - with config.option_context("interactive", True): - with config.option_context("sql.default_limit", None): - repr(table) +def test_disable_query_limit(table, snapshot, queries): + assert ibis.options.sql.default_limit is None - snapshot.assert_match(con.executed_queries[0], "out.sql") + with config.option_context("sql.default_limit", 10): + assert ibis.options.sql.default_limit == 10 + repr(table.select("id", "bool_col")) + snapshot.assert_match(queries[0], "out.sql") -def test_interactive_non_compilable_repr_not_fail(con): - # #170 - table = con.table("functional_alltypes") - expr = table.string_col.topk(3) +def test_interactive_non_compilable_repr_does_not_fail(table): + """https://github.com/ibis-project/ibis/issues/170""" + repr(table.string_col.topk(3)) - # it works! - with config.option_context("interactive", True): - repr(expr) +def test_histogram_repr_no_query_execute(table, queries): + tier = table.double_col.histogram(10).name("bucket") + expr = table.group_by(tier).size() + expr._repr() -def test_histogram_repr_no_query_execute(con): - t = con.table("functional_alltypes") - tier = t.double_col.histogram(10).name("bucket") - expr = t.group_by(tier).size() - with config.option_context("interactive", True): - expr._repr() - assert con.executed_queries == [] - + assert not queries -def test_compile_no_execute(con): - t = con.table("functional_alltypes") - t.double_col.sum().compile() - assert con.executed_queries == [] +def test_isin_rule_suppressed_exception_repr_not_fail(table): + bool_clause = table["string_col"].notin(["1", "4", "7"]) + expr = table[bool_clause]["string_col"].value_counts() -def test_isin_rule_suppressed_exception_repr_not_fail(con): - with config.option_context("interactive", True): - t = con.table("functional_alltypes") - bool_clause = t["string_col"].notin(["1", "4", "7"]) - expr = t[bool_clause]["string_col"].value_counts() - repr(expr) + repr(expr) diff --git a/ibis/backends/tests/test_join.py b/ibis/backends/tests/test_join.py index 43eaf33ade7ff..09d4dade0991a 100644 --- a/ibis/backends/tests/test_join.py +++ b/ibis/backends/tests/test_join.py @@ -299,7 +299,7 @@ def test_join_with_pandas_non_null_typed_columns(batting, awards_players): reason="polars doesn't support join predicates", ) @pytest.mark.notimpl( - ["dask"], + ["dask", "pandas"], raises=TypeError, reason="dask and pandas don't support join predicates", ) diff --git a/ibis/backends/tests/test_numeric.py b/ibis/backends/tests/test_numeric.py index 3d85d988f3ce4..cbc04a1d95346 100644 --- a/ibis/backends/tests/test_numeric.py +++ b/ibis/backends/tests/test_numeric.py @@ -62,12 +62,6 @@ ExaQueryError = None -try: - from snowflake.connector.errors import ProgrammingError as SnowflakeProgrammingError -except ImportError: - SnowflakeProgrammingError = None - - @pytest.mark.parametrize( ("expr", "expected_types"), [ @@ -283,7 +277,7 @@ def test_numeric_literal(con, backend, expr, expected_types): # TODO(krzysztof-kwitt): Should we unify it? { "bigquery": decimal.Decimal("1.1"), - "snowflake": decimal.Decimal("1.1"), + "snowflake": "1.1", "sqlite": 1.1, "trino": 1.1, "dask": decimal.Decimal("1.1"), @@ -300,7 +294,7 @@ def test_numeric_literal(con, backend, expr, expected_types): }, { "bigquery": "NUMERIC", - "snowflake": "DECIMAL", + "snowflake": "VARCHAR", "sqlite": "real", "trino": "decimal(2,1)", "duckdb": "DECIMAL(18,3)", @@ -335,7 +329,7 @@ def test_numeric_literal(con, backend, expr, expected_types): # TODO(krzysztof-kwitt): Should we unify it? { "bigquery": decimal.Decimal("1.1"), - "snowflake": decimal.Decimal("1.1"), + "snowflake": "1.100000000", "sqlite": 1.1, "trino": 1.1, "duckdb": decimal.Decimal("1.100000000"), @@ -354,7 +348,7 @@ def test_numeric_literal(con, backend, expr, expected_types): { "bigquery": "NUMERIC", "clickhouse": "Decimal(38, 9)", - "snowflake": "DECIMAL", + "snowflake": "VARCHAR", "sqlite": "real", "trino": "decimal(2,1)", "duckdb": "DECIMAL(38,9)", @@ -384,6 +378,7 @@ def test_numeric_literal(con, backend, expr, expected_types): # TODO(krzysztof-kwitt): Should we unify it? { "bigquery": decimal.Decimal("1.1"), + "snowflake": "1.10000000000000000000000000000000000000", "sqlite": 1.1, "trino": 1.1, "dask": decimal.Decimal("1.1"), @@ -401,6 +396,7 @@ def test_numeric_literal(con, backend, expr, expected_types): { "bigquery": "BIGNUMERIC", "clickhouse": "Decimal(76, 38)", + "snowflake": "VARCHAR", "sqlite": "real", "trino": "decimal(2,1)", "duckdb": "DECIMAL(18,3)", @@ -430,11 +426,6 @@ def test_numeric_literal(con, backend, expr, expected_types): "The precision can be up to 38 in Flink", raises=ValueError, ), - pytest.mark.broken( - ["snowflake"], - "Invalid number precision: 76. Must be between 0 and 38.", - raises=SnowflakeProgrammingError, - ), ], id="decimal-big", ), @@ -443,6 +434,7 @@ def test_numeric_literal(con, backend, expr, expected_types): # TODO(krzysztof-kwitt): Should we unify it? { "bigquery": float("inf"), + "snowflake": "Infinity", "sqlite": float("inf"), "postgres": float("nan"), "pandas": decimal.Decimal("Infinity"), @@ -453,6 +445,7 @@ def test_numeric_literal(con, backend, expr, expected_types): }, { "bigquery": "FLOAT64", + "snowflake": "VARCHAR", "sqlite": "real", "trino": "decimal(2,1)", "postgres": "numeric", @@ -472,11 +465,6 @@ def test_numeric_literal(con, backend, expr, expected_types): "query_id=20230128_024107_01084_y8zm3)", raises=sa.exc.ProgrammingError, ), - pytest.mark.broken( - ["snowflake"], - "snowflake.connector.errors.ProgrammingError: 100038 (22018): Numeric value 'Infinity' is not recognized", - raises=SnowflakeProgrammingError, - ), pytest.mark.broken( ["pyspark"], "An error occurred while calling z:org.apache.spark.sql.functions.lit.", @@ -523,6 +511,7 @@ def test_numeric_literal(con, backend, expr, expected_types): # TODO(krzysztof-kwitt): Should we unify it? { "bigquery": float("-inf"), + "snowflake": "-Infinity", "sqlite": float("-inf"), "postgres": float("nan"), "pandas": decimal.Decimal("-Infinity"), @@ -533,6 +522,7 @@ def test_numeric_literal(con, backend, expr, expected_types): }, { "bigquery": "FLOAT64", + "snowflake": "VARCHAR", "sqlite": "real", "trino": "decimal(2,1)", "postgres": "numeric", @@ -552,11 +542,6 @@ def test_numeric_literal(con, backend, expr, expected_types): "query_id=20230128_024107_01084_y8zm3)", raises=sa.exc.ProgrammingError, ), - pytest.mark.broken( - ["snowflake"], - "snowflake.connector.errors.ProgrammingError: 100038 (22018): Numeric value '-Infinity' is not recognized", - raises=SnowflakeProgrammingError, - ), pytest.mark.broken( ["pyspark"], "An error occurred while calling z:org.apache.spark.sql.functions.lit.", @@ -603,6 +588,7 @@ def test_numeric_literal(con, backend, expr, expected_types): # TODO(krzysztof-kwitt): Should we unify it? { "bigquery": float("nan"), + "snowflake": "NaN", "sqlite": None, "postgres": float("nan"), "pandas": decimal.Decimal("NaN"), @@ -613,6 +599,7 @@ def test_numeric_literal(con, backend, expr, expected_types): }, { "bigquery": "FLOAT64", + "snowflake": "VARCHAR", "sqlite": "null", "trino": "decimal(2,1)", "postgres": "numeric", @@ -632,11 +619,6 @@ def test_numeric_literal(con, backend, expr, expected_types): "query_id=20230128_024107_01084_y8zm3)", raises=sa.exc.ProgrammingError, ), - pytest.mark.broken( - ["snowflake"], - "snowflake.connector.errors.ProgrammingError: 100038 (22018): Numeric value 'NaN' is not recognized", - raises=SnowflakeProgrammingError, - ), pytest.mark.broken( ["pyspark"], "An error occurred while calling z:org.apache.spark.sql.functions.lit.", @@ -656,6 +638,14 @@ def test_numeric_literal(con, backend, expr, expected_types): "[SQL: SELECT %(param_1)s AS [Decimal('NaN')]]", raises=(sa.exc.ProgrammingError, KeyError), ), + pytest.mark.broken( + ["mssql"], + "(pydruid.db.exceptions.ProgrammingError) Plan validation failed " + "(org.apache.calcite.tools.ValidationException): " + "org.apache.calcite.runtime.CalciteContextException: From line 1, column 8 to line 1, column 10: Column 'NaN' not found in any table" + "[SQL: SELECT NaN AS \"Decimal('NaN')\"]", + raises=sa.exc.ProgrammingError, + ), pytest.mark.broken( ["druid"], "(pydruid.db.exceptions.ProgrammingError) Plan validation failed " @@ -796,14 +786,28 @@ def test_decimal_literal(con, backend, expr, expected_types, expected_result): param( operator.methodcaller("isnan"), np.isnan, - marks=pytest.mark.notimpl(["exasol"], raises=com.OperationNotDefinedError), + marks=[ + pytest.mark.notimpl( + ["exasol"], + raises=com.OperationNotDefinedError, + ), + ], id="isnan", ), param( operator.methodcaller("isinf"), np.isinf, id="isinf", - marks=pytest.mark.notimpl(["exasol"], raises=com.OperationNotDefinedError), + marks=[ + pytest.mark.notimpl( + ["exasol"], + raises=com.OperationNotDefinedError, + ), + pytest.mark.notimpl( + ["datafusion"], + raises=com.OperationNotDefinedError, + ), + ], ), ], ) @@ -1427,7 +1431,7 @@ def test_floating_mod(backend, alltypes, df): ) @pytest.mark.notyet(["mssql"], raises=(sa.exc.OperationalError, sa.exc.DataError)) @pytest.mark.notyet(["postgres"], raises=sa.exc.DataError) -@pytest.mark.notyet(["snowflake"], raises=SnowflakeProgrammingError) +@pytest.mark.notyet(["snowflake"], raises=sa.exc.ProgrammingError) @pytest.mark.notimpl(["exasol"], raises=(sa.exc.DBAPIError, com.IbisTypeError)) def test_divide_by_zero(backend, alltypes, df, column, denominator): expr = alltypes[column] / denominator @@ -1476,7 +1480,6 @@ def test_divide_by_zero(backend, alltypes, df, column, denominator): "pyspark", "polars", "flink", - "snowflake", ], reason="Not SQLAlchemy backends", ) @@ -1577,8 +1580,7 @@ def test_random(con): @pytest.mark.notimpl(["datafusion"], raises=com.OperationNotDefinedError) def test_clip(backend, alltypes, df, ibis_func, pandas_func): result = ibis_func(alltypes.int_col).execute() - raw_expected = pandas_func(df.int_col) - expected = raw_expected.astype(result.dtype) + expected = pandas_func(df.int_col).astype(result.dtype) # Names won't match in the PySpark backend since PySpark # gives 'tmp' name when executing a Column backend.assert_series_equal(result, expected, check_names=False) diff --git a/ibis/backends/tests/test_param.py b/ibis/backends/tests/test_param.py index 158405a149bac..36d2ee89c43d8 100644 --- a/ibis/backends/tests/test_param.py +++ b/ibis/backends/tests/test_param.py @@ -46,7 +46,7 @@ def test_floating_scalar_parameter(backend, alltypes, df, column, raw_value): ("start_string", "end_string"), [("2009-03-01", "2010-07-03"), ("2014-12-01", "2017-01-05")], ) -@pytest.mark.notimpl(["mssql", "trino", "druid"]) +@pytest.mark.notimpl(["datafusion", "mssql", "trino", "druid"]) @pytest.mark.broken(["oracle"], raises=sa.exc.DatabaseError) def test_date_scalar_parameter(backend, alltypes, start_string, end_string): start, end = ibis.param(dt.date), ibis.param(dt.date) @@ -69,7 +69,9 @@ def test_timestamp_accepts_date_literals(alltypes): assert expr.compile(params=params) is not None -@pytest.mark.notimpl(["dask", "impala", "pyspark", "druid", "oracle", "exasol"]) +@pytest.mark.notimpl( + ["dask", "impala", "pandas", "pyspark", "druid", "oracle", "exasol"] +) @pytest.mark.never( ["mysql", "sqlite", "mssql"], reason="backend will never implement array types" ) diff --git a/ibis/backends/tests/test_sql.py b/ibis/backends/tests/test_sql.py index bbc3f023410e2..9aaa5a66ec349 100644 --- a/ibis/backends/tests/test_sql.py +++ b/ibis/backends/tests/test_sql.py @@ -44,7 +44,8 @@ reason="Not a SQL backend", ) no_sql_extraction = pytest.mark.notimpl( - ["pyspark", "polars"], reason="Not clear how to extract SQL from the backend" + ["datafusion", "pyspark", "polars"], + reason="Not clear how to extract SQL from the backend", ) @@ -66,7 +67,9 @@ def test_literal(backend, expr): assert ibis.to_sql(expr, dialect=backend.name()) -@pytest.mark.never(["pandas", "dask", "polars", "pyspark"], reason="not SQL") +@pytest.mark.never( + ["pandas", "dask", "datafusion", "polars", "pyspark"], reason="not SQL" +) @pytest.mark.xfail_version( mssql=["sqlalchemy>=2"], reason="sqlalchemy 2 prefixes literals with `N`" ) @@ -92,6 +95,9 @@ def test_group_by_has_index(backend, snapshot): snapshot.assert_match(sql, "out.sql") +@pytest.mark.xfail( + raises=exc.IntegrityError, reason="inner join convenience not implemented" +) @pytest.mark.never(["pandas", "dask", "polars", "pyspark"], reason="not SQL") def test_cte_refs_in_topo_order(backend, snapshot): mr0 = ibis.table(schema=ibis.schema(dict(key="int")), name="leaf") @@ -105,7 +111,9 @@ def test_cte_refs_in_topo_order(backend, snapshot): snapshot.assert_match(sql, "out.sql") -@pytest.mark.never(["pandas", "dask", "polars", "pyspark"], reason="not SQL") +@pytest.mark.never( + ["pandas", "dask", "datafusion", "polars", "pyspark"], reason="not SQL" +) def test_isin_bug(con, snapshot): t = ibis.table(dict(x="int"), name="t") good = t[t.x > 2].x @@ -114,7 +122,7 @@ def test_isin_bug(con, snapshot): @pytest.mark.never( - ["pandas", "dask", "polars", "pyspark"], + ["pandas", "dask", "datafusion", "polars", "pyspark"], reason="not SQL", raises=NotImplementedError, ) @@ -122,7 +130,7 @@ def test_isin_bug(con, snapshot): ["sqlite", "mysql", "druid", "impala", "mssql"], reason="no unnest support upstream" ) @pytest.mark.notimpl( - ["oracle", "flink", "datafusion"], + ["oracle", "flink"], reason="unnest not yet implemented", raises=exc.OperationNotDefinedError, ) diff --git a/ibis/backends/tests/test_string.py b/ibis/backends/tests/test_string.py index 4c2271e1d9549..0d90d9a6e4ba0 100644 --- a/ibis/backends/tests/test_string.py +++ b/ibis/backends/tests/test_string.py @@ -142,7 +142,9 @@ def uses_java_re(t): lambda t: t.string_col.str.contains("6.*"), id="like", marks=[ - pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError), + pytest.mark.notimpl( + ["datafusion", "polars"], raises=com.OperationNotDefinedError + ), pytest.mark.broken( ["mssql"], reason="mssql doesn't allow like outside of filters", @@ -155,7 +157,9 @@ def uses_java_re(t): lambda t: t.string_col.str.contains("6%"), id="complex_like_escape", marks=[ - pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError), + pytest.mark.notimpl( + ["datafusion", "polars"], raises=com.OperationNotDefinedError + ), pytest.mark.broken( ["mssql"], reason="mssql doesn't allow like outside of filters", @@ -168,7 +172,9 @@ def uses_java_re(t): lambda t: t.string_col.str.contains("6%.*"), id="complex_like_escape_match", marks=[ - pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError), + pytest.mark.notimpl( + ["datafusion", "polars"], raises=com.OperationNotDefinedError + ), pytest.mark.broken( ["mssql"], reason="mssql doesn't allow like outside of filters", @@ -182,7 +188,8 @@ def uses_java_re(t): id="ilike", marks=[ pytest.mark.notimpl( - ["pyspark", "polars"], raises=com.OperationNotDefinedError + ["datafusion", "pyspark", "polars"], + raises=com.OperationNotDefinedError, ), pytest.mark.broken( ["mssql"], @@ -773,6 +780,7 @@ def uses_java_re(t): marks=pytest.mark.notimpl( [ "dask", + "datafusion", "impala", "mysql", "sqlite", diff --git a/ibis/backends/tests/test_temporal.py b/ibis/backends/tests/test_temporal.py index 8a686fa695bce..51f45e1a2278e 100644 --- a/ibis/backends/tests/test_temporal.py +++ b/ibis/backends/tests/test_temporal.py @@ -66,12 +66,6 @@ except ImportError: Py4JJavaError = None -try: - from snowflake.connector.errors import ProgrammingError as SnowflakeProgrammingError -except ImportError: - SnowflakeProgrammingError = None - - try: from pyexasol.exceptions import ExaQueryError except ImportError: @@ -83,34 +77,6 @@ IllegalArgumentException = None -def day_name(obj: pd.core.indexes.accessors.DatetimeProperties | pd.Timestamp) -> str: - """Backwards compatible name-of-day getting function. - - Returns - ------- - str - The name of the day corresponding to `obj` - """ - try: - return obj.day_name() - except AttributeError: - return obj.weekday_name - - -def day_name(obj: pd.core.indexes.accessors.DatetimeProperties | pd.Timestamp) -> str: - """Backwards compatible name-of-day getting function. - - Returns - ------- - str - The name of the day corresponding to `obj` - """ - try: - return obj.day_name() - except AttributeError: - return obj.weekday_name - - @pytest.mark.parametrize("attr", ["year", "month", "day"]) @pytest.mark.parametrize( "expr_fn", @@ -724,7 +690,10 @@ def test_timestamp_truncate(backend, alltypes, df, unit): @pytest.mark.broken( ["polars", "druid"], reason="snaps to the UNIX epoch", raises=AssertionError ) -@pytest.mark.notimpl(["oracle"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl( + ["datafusion", "oracle"], + raises=com.OperationNotDefinedError, +) @pytest.mark.broken( ["druid"], raises=AttributeError, @@ -1092,6 +1061,7 @@ def convert_to_offset(x): "dask", "impala", "mysql", + "pandas", "postgres", "snowflake", "sqlite", @@ -1694,6 +1664,12 @@ def test_interval_add_cast_column(backend, alltypes, df): ), "%Y%m%d", marks=[ + pytest.mark.notimpl( + [ + "pandas", + ], + raises=com.OperationNotDefinedError, + ), pytest.mark.notimpl( [ "pyspark", @@ -1702,7 +1678,10 @@ def test_interval_add_cast_column(backend, alltypes, df): reason="'StringConcat' object has no attribute 'value'", ), pytest.mark.notimpl( - ["postgres"], + [ + "postgres", + "snowflake", + ], raises=AttributeError, reason="Neither 'concat' object nor 'Comparator' object has an attribute 'value'", ), @@ -1809,7 +1788,7 @@ def test_strftime(backend, alltypes, df, expr_fn, pandas_pattern): reason="PySpark backend does not support timestamp from unix time with unit us. Supported unit is s.", ), pytest.mark.notimpl( - ["mssql", "clickhouse", "duckdb"], + ["duckdb", "mssql", "clickhouse"], raises=com.UnsupportedOperationError, reason="`us` unit is not supported!", ), @@ -1826,12 +1805,12 @@ def test_strftime(backend, alltypes, df, expr_fn, pandas_pattern): pytest.mark.notimpl( ["pyspark"], raises=com.UnsupportedArgumentError, - reason="PySpark backend does not support timestamp from unix time with unit ns. Supported unit is s.", + reason="PySpark backend does not support timestamp from unix time with unit ms. Supported unit is s.", ), pytest.mark.notimpl( ["duckdb", "mssql", "clickhouse"], raises=com.UnsupportedOperationError, - reason="`ns` unit is not supported!", + reason="`ms` unit is not supported!", ), pytest.mark.notimpl( ["flink"], @@ -1884,7 +1863,7 @@ def test_integer_to_timestamp(backend, con, unit): "(snowflake.connector.errors.ProgrammingError) 100096 (22007): " "Can't parse '11/01/10' as timestamp with format '%m/%d/%y'" ), - raises=SnowflakeProgrammingError, + raises=sa.exc.ProgrammingError, ), pytest.mark.never( ["flink"], @@ -2108,7 +2087,10 @@ def test_now_from_projection(alltypes): } -@pytest.mark.notimpl(["pandas", "dask", "pyspark"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl( + ["pandas", "datafusion", "dask", "pyspark"], + raises=com.OperationNotDefinedError, +) @pytest.mark.notimpl( ["druid"], raises=sa.exc.ProgrammingError, reason="SQL parse failed" ) @@ -2150,7 +2132,10 @@ def test_date_literal(con, backend): } -@pytest.mark.notimpl(["pandas", "dask", "pyspark"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl( + ["pandas", "datafusion", "dask", "pyspark"], + raises=com.OperationNotDefinedError, +) @pytest.mark.notimpl( ["druid"], raises=sa.exc.ProgrammingError, @@ -2184,7 +2169,8 @@ def test_timestamp_literal(con, backend): @pytest.mark.notimpl( - ["pandas", "mysql", "dask", "pyspark"], raises=com.OperationNotDefinedError + ["pandas", "datafusion", "mysql", "dask", "pyspark"], + raises=com.OperationNotDefinedError, ) @pytest.mark.notimpl( ["mysql"], @@ -2300,12 +2286,14 @@ def test_time_literal(con, backend): @pytest.mark.broken( ["sqlite"], raises=AssertionError, reason="SQLite returns Timedelta from execution" ) -@pytest.mark.notimpl(["dask"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl( + ["dask", "datafusion", "pandas"], raises=com.OperationNotDefinedError +) @pytest.mark.notyet(["oracle"], raises=sa.exc.DatabaseError) @pytest.mark.parametrize( "microsecond", [ - param(0, id="second"), + 0, param( 561021, marks=[ @@ -2328,9 +2316,9 @@ def test_time_literal(con, backend): ), ), ], - id="subsecond", ), ], + ids=["second", "subsecond"], ) @pytest.mark.notimpl(["exasol"], raises=ExaQueryError) def test_extract_time_from_timestamp(con, microsecond): @@ -2356,8 +2344,9 @@ def test_extract_time_from_timestamp(con, microsecond): @pytest.mark.broken( ["snowflake"], - "interval literal is not supported in this form.", - raises=SnowflakeProgrammingError, + "(snowflake.connector.errors.ProgrammingError) 001007 (22023): SQL compilation error:" + "invalid type [CAST(INTERVAL_LITERAL('second', '1') AS VARIANT)] for parameter 'TO_VARIANT'", + raises=sa.exc.ProgrammingError, ) @pytest.mark.broken( ["druid"], @@ -2418,7 +2407,10 @@ def test_interval_literal(con, backend): assert con.execute(expr.typeof()) == INTERVAL_BACKEND_TYPES[backend_name] -@pytest.mark.notimpl(["pandas", "dask", "pyspark"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl( + ["pandas", "datafusion", "dask", "pyspark"], + raises=com.OperationNotDefinedError, +) @pytest.mark.broken( ["mysql"], raises=sa.exc.ProgrammingError, @@ -2448,7 +2440,10 @@ def test_date_column_from_ymd(backend, con, alltypes, df): backend.assert_series_equal(golden, result.timestamp_col) -@pytest.mark.notimpl(["pandas", "dask", "pyspark"], raises=com.OperationNotDefinedError) +@pytest.mark.notimpl( + ["pandas", "datafusion", "dask", "pyspark"], + raises=com.OperationNotDefinedError, +) @pytest.mark.broken( ["druid"], raises=AttributeError, @@ -2877,7 +2872,7 @@ def test_delta(con, start, end, unit, expected): ), pytest.mark.notimpl( ["snowflake"], - raises=SnowflakeProgrammingError, + raises=sa.exc.ProgrammingError, reason="snowflake doesn't support sub-second interval precision", ), pytest.mark.notimpl( diff --git a/ibis/backends/tests/test_window.py b/ibis/backends/tests/test_window.py index d1fa1ee11d3ab..6293a2b8dbb0e 100644 --- a/ibis/backends/tests/test_window.py +++ b/ibis/backends/tests/test_window.py @@ -54,12 +54,6 @@ GoogleBadRequest = None -try: - from snowflake.connector.errors import ProgrammingError as SnowflakeProgrammingError -except ImportError: - SnowflakeProgrammingError = None - - # adapted from https://gist.github.com/xmnlab/2c1f93df1a6c6bde4e32c8579117e9cc def pandas_ntile(x, bucket: int): """Divide values into a number of buckets. @@ -117,6 +111,11 @@ def calc_zscore(s): id="lag", marks=[ pytest.mark.notimpl(["dask"], raises=NotImplementedError), + pytest.mark.broken( + ["datafusion"], + raises=Exception, + reason="Exception: Internal error: Expects default value to have Int64 type.", + ), pytest.mark.notimpl(["flink"], raises=Py4JJavaError), ], ), @@ -130,6 +129,11 @@ def calc_zscore(s): reason="upstream is broken; returns all nulls", raises=AssertionError, ), + pytest.mark.broken( + ["datafusion"], + reason="Exception: Internal error: Expects default value to have Int64 type.", + raises=BaseException, + ), pytest.mark.notimpl(["dask"], raises=NotImplementedError), pytest.mark.notimpl(["flink"], raises=Py4JJavaError), ], @@ -460,6 +464,7 @@ def test_ungrouped_bounded_expanding_window( ) @pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError) @pytest.mark.notimpl(["dask"], raises=NotImplementedError) +@pytest.mark.notimpl(["pandas"], raises=AssertionError) @pytest.mark.notimpl(["flink"], raises=com.UnsupportedOperationError) def test_grouped_bounded_following_window(backend, alltypes, df, preceding, following): window = ibis.window( @@ -621,7 +626,6 @@ def test_grouped_unbounded_window( # 1) Grouped # 2) Ordered if `ordered` is True df = df.sort_values("id") if ordered else df - expected = df.assign(val=expected_fn(df.groupby("string_col"))) expected = expected.set_index("id").sort_index() @@ -638,7 +642,7 @@ def test_grouped_unbounded_window( ], ) @pytest.mark.broken(["snowflake"], raises=AssertionError) -@pytest.mark.broken(["dask", "mssql"], raises=AssertionError) +@pytest.mark.broken(["dask", "pandas", "mssql"], raises=AssertionError) @pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError) @pytest.mark.notimpl(["flink"], raises=com.UnsupportedOperationError) def test_simple_ungrouped_unbound_following_window( @@ -694,6 +698,7 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): True, id="ordered-mean", marks=[ + pytest.mark.broken(["pandas"], raises=AssertionError), pytest.mark.notimpl( ["dask"], raises=NotImplementedError, @@ -763,6 +768,7 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): ], raises=com.OperationNotDefinedError, ), + pytest.mark.broken(["pandas"], raises=AssertionError), pytest.mark.broken( ["dask"], raises=ValueError, @@ -805,6 +811,13 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): lambda df: df.float_col.shift(1), True, id="ordered-lag", + marks=[ + pytest.mark.broken( + ["datafusion"], + raises=Exception, + reason="Exception: Internal error: Expects default value to have Int64 type.", + ), + ], ), param( lambda t, win: t.float_col.lag().over(win), @@ -818,6 +831,11 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): raises=AssertionError, ), pytest.mark.broken(["oracle"], raises=AssertionError), + pytest.mark.broken( + ["datafusion"], + raises=Exception, + reason="Exception: Internal error: Expects default value to have Int64 type.", + ), pytest.mark.notimpl( ["pyspark"], raises=AnalysisException, @@ -833,7 +851,7 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): pytest.mark.notyet( ["snowflake"], reason="backend requires ordering", - raises=SnowflakeProgrammingError, + raises=sa.exc.ProgrammingError, ), ], ), @@ -842,6 +860,13 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): lambda df: df.float_col.shift(-1), True, id="ordered-lead", + marks=[ + pytest.mark.broken( + ["datafusion"], + raises=Exception, + reason="Exception: Internal error: Expects default value to have Int64 type.", + ), + ], ), param( lambda t, win: t.float_col.lead().over(win), @@ -857,6 +882,11 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): ), raises=AssertionError, ), + pytest.mark.broken( + ["datafusion"], + raises=Exception, + reason="Exception: Internal error: Expects default value to have Int64 type.", + ), pytest.mark.broken(["oracle"], raises=AssertionError), pytest.mark.notimpl( ["pyspark"], @@ -873,7 +903,7 @@ def test_simple_ungrouped_window_with_scalar_order_by(alltypes): pytest.mark.notyet( ["snowflake"], reason="backend requires ordering", - raises=SnowflakeProgrammingError, + raises=sa.exc.ProgrammingError, ), ], ), @@ -974,11 +1004,7 @@ def test_ungrouped_unbounded_window( @pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError) -@pytest.mark.notimpl( - ["snowflake"], - raises=SnowflakeProgrammingError, - reason="snowflake doesn't support sliding range windows", -) +@pytest.mark.notimpl(["snowflake"], raises=sa.exc.ProgrammingError) @pytest.mark.notimpl( ["impala"], raises=HiveServer2Error, reason="limited RANGE support" ) @@ -1070,6 +1096,11 @@ def test_percent_rank_whole_table_no_order_by(backend, alltypes, df): @pytest.mark.broken( ["pandas"], reason="pandas returns incorrect results", raises=AssertionError ) +@pytest.mark.broken( + ["datafusion"], + reason="Exception: External error: Internal error: Expects default value to have Int64 type", + raises=Exception, +) def test_grouped_ordered_window_coalesce(backend, alltypes, df): t = alltypes expr = ( @@ -1104,6 +1135,11 @@ def agg(df): @pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError) +@pytest.mark.broken( + ["datafusion"], + raises=Exception, + reason="Exception: Internal error: Expects default value to have Int64 type.", +) def test_mutate_window_filter(backend, alltypes): t = alltypes win = ibis.window(order_by=[t.id]) diff --git a/ibis/backends/tests/tpch/snapshots/test_h01/test_tpc_h01/duckdb/h01.sql b/ibis/backends/tests/tpch/snapshots/test_h01/test_tpc_h01/duckdb/h01.sql index 31b9d111cde61..953b4dfeefc4f 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h01/test_tpc_h01/duckdb/h01.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h01/test_tpc_h01/duckdb/h01.sql @@ -1,18 +1,18 @@ SELECT - t2.l_returnflag AS l_returnflag, - t2.l_linestatus AS l_linestatus, - t2.sum_qty AS sum_qty, - t2.sum_base_price AS sum_base_price, - t2.sum_disc_price AS sum_disc_price, - t2.sum_charge AS sum_charge, - t2.avg_qty AS avg_qty, - t2.avg_price AS avg_price, - t2.avg_disc AS avg_disc, - t2.count_order AS count_order + t2.l_returnflag, + t2.l_linestatus, + t2.sum_qty, + t2.sum_base_price, + t2.sum_disc_price, + t2.sum_charge, + t2.avg_qty, + t2.avg_price, + t2.avg_disc, + t2.count_order FROM ( SELECT - t1.l_returnflag AS l_returnflag, - t1.l_linestatus AS l_linestatus, + t1.l_returnflag, + t1.l_linestatus, SUM(t1.l_quantity) AS sum_qty, SUM(t1.l_extendedprice) AS sum_base_price, SUM(t1.l_extendedprice * ( @@ -33,22 +33,22 @@ FROM ( COUNT(*) AS count_order FROM ( SELECT - t0.l_orderkey AS l_orderkey, - t0.l_partkey AS l_partkey, - t0.l_suppkey AS l_suppkey, - t0.l_linenumber AS l_linenumber, - t0.l_quantity AS l_quantity, - t0.l_extendedprice AS l_extendedprice, - t0.l_discount AS l_discount, - t0.l_tax AS l_tax, - t0.l_returnflag AS l_returnflag, - t0.l_linestatus AS l_linestatus, - t0.l_shipdate AS l_shipdate, - t0.l_commitdate AS l_commitdate, - t0.l_receiptdate AS l_receiptdate, - t0.l_shipinstruct AS l_shipinstruct, - t0.l_shipmode AS l_shipmode, - t0.l_comment AS l_comment + t0.l_orderkey, + t0.l_partkey, + t0.l_suppkey, + t0.l_linenumber, + t0.l_quantity, + t0.l_extendedprice, + t0.l_discount, + t0.l_tax, + t0.l_returnflag, + t0.l_linestatus, + t0.l_shipdate, + t0.l_commitdate, + t0.l_receiptdate, + t0.l_shipinstruct, + t0.l_shipmode, + t0.l_comment FROM lineitem AS t0 WHERE t0.l_shipdate <= MAKE_DATE(1998, 9, 2) diff --git a/ibis/backends/tests/tpch/snapshots/test_h02/test_tpc_h02/duckdb/h02.sql b/ibis/backends/tests/tpch/snapshots/test_h02/test_tpc_h02/duckdb/h02.sql index b8ea068fcd7ba..9fa0195c56bb1 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h02/test_tpc_h02/duckdb/h02.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h02/test_tpc_h02/duckdb/h02.sql @@ -1,116 +1,116 @@ SELECT - t19.s_acctbal AS s_acctbal, - t19.s_name AS s_name, - t19.n_name AS n_name, - t19.p_partkey AS p_partkey, - t19.p_mfgr AS p_mfgr, - t19.s_address AS s_address, - t19.s_phone AS s_phone, - t19.s_comment AS s_comment + t21.s_acctbal, + t21.s_name, + t21.n_name, + t21.p_partkey, + t21.p_mfgr, + t21.s_address, + t21.s_phone, + t21.s_comment FROM ( SELECT - t0.p_partkey AS p_partkey, - t0.p_name AS p_name, - t0.p_mfgr AS p_mfgr, - t0.p_brand AS p_brand, - t0.p_type AS p_type, - t0.p_size AS p_size, - t0.p_container AS p_container, - t0.p_retailprice AS p_retailprice, - t0.p_comment AS p_comment, - t5.ps_partkey AS ps_partkey, - t5.ps_suppkey AS ps_suppkey, - t5.ps_availqty AS ps_availqty, - t5.ps_supplycost AS ps_supplycost, - t5.ps_comment AS ps_comment, - t6.s_suppkey AS s_suppkey, - t6.s_name AS s_name, - t6.s_address AS s_address, - t6.s_nationkey AS s_nationkey, - t6.s_phone AS s_phone, - t6.s_acctbal AS s_acctbal, - t6.s_comment AS s_comment, - t8.n_nationkey AS n_nationkey, - t8.n_name AS n_name, - t8.n_regionkey AS n_regionkey, - t8.n_comment AS n_comment, - t10.r_regionkey AS r_regionkey, - t10.r_name AS r_name, - t10.r_comment AS r_comment - FROM part AS t0 - INNER JOIN partsupp AS t5 - ON t0.p_partkey = t5.ps_partkey - INNER JOIN supplier AS t6 - ON t6.s_suppkey = t5.ps_suppkey - INNER JOIN nation AS t8 - ON t6.s_nationkey = t8.n_nationkey - INNER JOIN region AS t10 - ON t8.n_regionkey = t10.r_regionkey -) AS t19 + t5.p_partkey, + t5.p_name, + t5.p_mfgr, + t5.p_brand, + t5.p_type, + t5.p_size, + t5.p_container, + t5.p_retailprice, + t5.p_comment, + t6.ps_partkey, + t6.ps_suppkey, + t6.ps_availqty, + t6.ps_supplycost, + t6.ps_comment, + t8.s_suppkey, + t8.s_name, + t8.s_address, + t8.s_nationkey, + t8.s_phone, + t8.s_acctbal, + t8.s_comment, + t10.n_nationkey, + t10.n_name, + t10.n_regionkey, + t10.n_comment, + t12.r_regionkey, + t12.r_name, + t12.r_comment + FROM part AS t5 + INNER JOIN partsupp AS t6 + ON t5.p_partkey = t6.ps_partkey + INNER JOIN supplier AS t8 + ON t8.s_suppkey = t6.ps_suppkey + INNER JOIN nation AS t10 + ON t8.s_nationkey = t10.n_nationkey + INNER JOIN region AS t12 + ON t10.n_regionkey = t12.r_regionkey +) AS t21 WHERE - t19.p_size = CAST(15 AS TINYINT) - AND t19.p_type LIKE '%BRASS' - AND t19.r_name = 'EUROPE' - AND t19.ps_supplycost = ( + t21.p_size = CAST(15 AS TINYINT) + AND t21.p_type LIKE '%BRASS' + AND t21.r_name = 'EUROPE' + AND t21.ps_supplycost = ( SELECT - MIN(t21.ps_supplycost) AS "Min(ps_supplycost)" + MIN(t23.ps_supplycost) AS "Min(ps_supplycost)" FROM ( SELECT - t20.ps_partkey AS ps_partkey, - t20.ps_suppkey AS ps_suppkey, - t20.ps_availqty AS ps_availqty, - t20.ps_supplycost AS ps_supplycost, - t20.ps_comment AS ps_comment, - t20.s_suppkey AS s_suppkey, - t20.s_name AS s_name, - t20.s_address AS s_address, - t20.s_nationkey AS s_nationkey, - t20.s_phone AS s_phone, - t20.s_acctbal AS s_acctbal, - t20.s_comment AS s_comment, - t20.n_nationkey AS n_nationkey, - t20.n_name AS n_name, - t20.n_regionkey AS n_regionkey, - t20.n_comment AS n_comment, - t20.r_regionkey AS r_regionkey, - t20.r_name AS r_name, - t20.r_comment AS r_comment + t22.ps_partkey, + t22.ps_suppkey, + t22.ps_availqty, + t22.ps_supplycost, + t22.ps_comment, + t22.s_suppkey, + t22.s_name, + t22.s_address, + t22.s_nationkey, + t22.s_phone, + t22.s_acctbal, + t22.s_comment, + t22.n_nationkey, + t22.n_name, + t22.n_regionkey, + t22.n_comment, + t22.r_regionkey, + t22.r_name, + t22.r_comment FROM ( SELECT - t1.ps_partkey AS ps_partkey, - t1.ps_suppkey AS ps_suppkey, - t1.ps_availqty AS ps_availqty, - t1.ps_supplycost AS ps_supplycost, - t1.ps_comment AS ps_comment, - t7.s_suppkey AS s_suppkey, - t7.s_name AS s_name, - t7.s_address AS s_address, - t7.s_nationkey AS s_nationkey, - t7.s_phone AS s_phone, - t7.s_acctbal AS s_acctbal, - t7.s_comment AS s_comment, - t9.n_nationkey AS n_nationkey, - t9.n_name AS n_name, - t9.n_regionkey AS n_regionkey, - t9.n_comment AS n_comment, - t11.r_regionkey AS r_regionkey, - t11.r_name AS r_name, - t11.r_comment AS r_comment - FROM partsupp AS t1 - INNER JOIN supplier AS t7 - ON t7.s_suppkey = t1.ps_suppkey - INNER JOIN nation AS t9 - ON t7.s_nationkey = t9.n_nationkey - INNER JOIN region AS t11 - ON t9.n_regionkey = t11.r_regionkey - ) AS t20 + t7.ps_partkey, + t7.ps_suppkey, + t7.ps_availqty, + t7.ps_supplycost, + t7.ps_comment, + t9.s_suppkey, + t9.s_name, + t9.s_address, + t9.s_nationkey, + t9.s_phone, + t9.s_acctbal, + t9.s_comment, + t11.n_nationkey, + t11.n_name, + t11.n_regionkey, + t11.n_comment, + t13.r_regionkey, + t13.r_name, + t13.r_comment + FROM partsupp AS t7 + INNER JOIN supplier AS t9 + ON t9.s_suppkey = t7.ps_suppkey + INNER JOIN nation AS t11 + ON t9.s_nationkey = t11.n_nationkey + INNER JOIN region AS t13 + ON t11.n_regionkey = t13.r_regionkey + ) AS t22 WHERE - t20.r_name = 'EUROPE' AND t19.p_partkey = t20.ps_partkey - ) AS t21 + t22.r_name = 'EUROPE' AND t21.p_partkey = t22.ps_partkey + ) AS t23 ) ORDER BY - t19.s_acctbal DESC, - t19.n_name ASC, - t19.s_name ASC, - t19.p_partkey ASC + t21.s_acctbal DESC, + t21.n_name ASC, + t21.s_name ASC, + t21.p_partkey ASC LIMIT 100 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h03/test_tpc_h03/duckdb/h03.sql b/ibis/backends/tests/tpch/snapshots/test_h03/test_tpc_h03/duckdb/h03.sql index 90c48b774ef5d..adb97afaf7f1f 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h03/test_tpc_h03/duckdb/h03.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h03/test_tpc_h03/duckdb/h03.sql @@ -1,103 +1,103 @@ SELECT - t9.l_orderkey AS l_orderkey, - t9.revenue AS revenue, - t9.o_orderdate AS o_orderdate, - t9.o_shippriority AS o_shippriority + t10.l_orderkey, + t10.revenue, + t10.o_orderdate, + t10.o_shippriority FROM ( SELECT - t8.l_orderkey AS l_orderkey, - t8.o_orderdate AS o_orderdate, - t8.o_shippriority AS o_shippriority, - SUM(t8.l_extendedprice * ( - CAST(1 AS TINYINT) - t8.l_discount + t9.l_orderkey, + t9.o_orderdate, + t9.o_shippriority, + SUM(t9.l_extendedprice * ( + CAST(1 AS TINYINT) - t9.l_discount )) AS revenue FROM ( SELECT - t7.c_custkey AS c_custkey, - t7.c_name AS c_name, - t7.c_address AS c_address, - t7.c_nationkey AS c_nationkey, - t7.c_phone AS c_phone, - t7.c_acctbal AS c_acctbal, - t7.c_mktsegment AS c_mktsegment, - t7.c_comment AS c_comment, - t7.o_orderkey AS o_orderkey, - t7.o_custkey AS o_custkey, - t7.o_orderstatus AS o_orderstatus, - t7.o_totalprice AS o_totalprice, - t7.o_orderdate AS o_orderdate, - t7.o_orderpriority AS o_orderpriority, - t7.o_clerk AS o_clerk, - t7.o_shippriority AS o_shippriority, - t7.o_comment AS o_comment, - t7.l_orderkey AS l_orderkey, - t7.l_partkey AS l_partkey, - t7.l_suppkey AS l_suppkey, - t7.l_linenumber AS l_linenumber, - t7.l_quantity AS l_quantity, - t7.l_extendedprice AS l_extendedprice, - t7.l_discount AS l_discount, - t7.l_tax AS l_tax, - t7.l_returnflag AS l_returnflag, - t7.l_linestatus AS l_linestatus, - t7.l_shipdate AS l_shipdate, - t7.l_commitdate AS l_commitdate, - t7.l_receiptdate AS l_receiptdate, - t7.l_shipinstruct AS l_shipinstruct, - t7.l_shipmode AS l_shipmode, - t7.l_comment AS l_comment + t8.c_custkey, + t8.c_name, + t8.c_address, + t8.c_nationkey, + t8.c_phone, + t8.c_acctbal, + t8.c_mktsegment, + t8.c_comment, + t8.o_orderkey, + t8.o_custkey, + t8.o_orderstatus, + t8.o_totalprice, + t8.o_orderdate, + t8.o_orderpriority, + t8.o_clerk, + t8.o_shippriority, + t8.o_comment, + t8.l_orderkey, + t8.l_partkey, + t8.l_suppkey, + t8.l_linenumber, + t8.l_quantity, + t8.l_extendedprice, + t8.l_discount, + t8.l_tax, + t8.l_returnflag, + t8.l_linestatus, + t8.l_shipdate, + t8.l_commitdate, + t8.l_receiptdate, + t8.l_shipinstruct, + t8.l_shipmode, + t8.l_comment FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t3.o_orderkey AS o_orderkey, - t3.o_custkey AS o_custkey, - t3.o_orderstatus AS o_orderstatus, - t3.o_totalprice AS o_totalprice, - t3.o_orderdate AS o_orderdate, - t3.o_orderpriority AS o_orderpriority, - t3.o_clerk AS o_clerk, - t3.o_shippriority AS o_shippriority, - t3.o_comment AS o_comment, - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment - FROM customer AS t0 - INNER JOIN orders AS t3 - ON t0.c_custkey = t3.o_custkey - INNER JOIN lineitem AS t4 - ON t4.l_orderkey = t3.o_orderkey - ) AS t7 + t3.c_custkey, + t3.c_name, + t3.c_address, + t3.c_nationkey, + t3.c_phone, + t3.c_acctbal, + t3.c_mktsegment, + t3.c_comment, + t4.o_orderkey, + t4.o_custkey, + t4.o_orderstatus, + t4.o_totalprice, + t4.o_orderdate, + t4.o_orderpriority, + t4.o_clerk, + t4.o_shippriority, + t4.o_comment, + t5.l_orderkey, + t5.l_partkey, + t5.l_suppkey, + t5.l_linenumber, + t5.l_quantity, + t5.l_extendedprice, + t5.l_discount, + t5.l_tax, + t5.l_returnflag, + t5.l_linestatus, + t5.l_shipdate, + t5.l_commitdate, + t5.l_receiptdate, + t5.l_shipinstruct, + t5.l_shipmode, + t5.l_comment + FROM customer AS t3 + INNER JOIN orders AS t4 + ON t3.c_custkey = t4.o_custkey + INNER JOIN lineitem AS t5 + ON t5.l_orderkey = t4.o_orderkey + ) AS t8 WHERE - t7.c_mktsegment = 'BUILDING' - AND t7.o_orderdate < MAKE_DATE(1995, 3, 15) - AND t7.l_shipdate > MAKE_DATE(1995, 3, 15) - ) AS t8 + t8.c_mktsegment = 'BUILDING' + AND t8.o_orderdate < MAKE_DATE(1995, 3, 15) + AND t8.l_shipdate > MAKE_DATE(1995, 3, 15) + ) AS t9 GROUP BY 1, 2, 3 -) AS t9 +) AS t10 ORDER BY - t9.revenue DESC, - t9.o_orderdate ASC + t10.revenue DESC, + t10.o_orderdate ASC LIMIT 10 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h04/test_tpc_h04/duckdb/h04.sql b/ibis/backends/tests/tpch/snapshots/test_h04/test_tpc_h04/duckdb/h04.sql index f56cd81b6401b..77ba19f9cc076 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h04/test_tpc_h04/duckdb/h04.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h04/test_tpc_h04/duckdb/h04.sql @@ -1,35 +1,33 @@ SELECT - t4.o_orderpriority AS o_orderpriority, - t4.order_count AS order_count + t4.o_orderpriority, + t4.order_count FROM ( SELECT - t3.o_orderpriority AS o_orderpriority, + t3.o_orderpriority, COUNT(*) AS order_count FROM ( SELECT - t0.o_orderkey AS o_orderkey, - t0.o_custkey AS o_custkey, - t0.o_orderstatus AS o_orderstatus, - t0.o_totalprice AS o_totalprice, - t0.o_orderdate AS o_orderdate, - t0.o_orderpriority AS o_orderpriority, - t0.o_clerk AS o_clerk, - t0.o_shippriority AS o_shippriority, - t0.o_comment AS o_comment + t0.o_orderkey, + t0.o_custkey, + t0.o_orderstatus, + t0.o_totalprice, + t0.o_orderdate, + t0.o_orderpriority, + t0.o_clerk, + t0.o_shippriority, + t0.o_comment FROM orders AS t0 WHERE EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM lineitem AS t1 - WHERE - ( - t1.l_orderkey = t0.o_orderkey - ) AND ( - t1.l_commitdate < t1.l_receiptdate - ) - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM lineitem AS t1 + WHERE + ( + t1.l_orderkey = t0.o_orderkey + ) AND ( + t1.l_commitdate < t1.l_receiptdate + ) ) AND t0.o_orderdate >= MAKE_DATE(1993, 7, 1) AND t0.o_orderdate < MAKE_DATE(1993, 10, 1) diff --git a/ibis/backends/tests/tpch/snapshots/test_h05/test_tpc_h05/duckdb/h05.sql b/ibis/backends/tests/tpch/snapshots/test_h05/test_tpc_h05/duckdb/h05.sql index 6fed94b3b38c0..ae3bbac7941f3 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h05/test_tpc_h05/duckdb/h05.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h05/test_tpc_h05/duckdb/h05.sql @@ -1,129 +1,129 @@ SELECT - t18.n_name AS n_name, - t18.revenue AS revenue + t19.n_name, + t19.revenue FROM ( SELECT - t17.n_name AS n_name, - SUM(t17.l_extendedprice * ( - CAST(1 AS TINYINT) - t17.l_discount + t18.n_name, + SUM(t18.l_extendedprice * ( + CAST(1 AS TINYINT) - t18.l_discount )) AS revenue FROM ( SELECT - t16.c_custkey AS c_custkey, - t16.c_name AS c_name, - t16.c_address AS c_address, - t16.c_nationkey AS c_nationkey, - t16.c_phone AS c_phone, - t16.c_acctbal AS c_acctbal, - t16.c_mktsegment AS c_mktsegment, - t16.c_comment AS c_comment, - t16.o_orderkey AS o_orderkey, - t16.o_custkey AS o_custkey, - t16.o_orderstatus AS o_orderstatus, - t16.o_totalprice AS o_totalprice, - t16.o_orderdate AS o_orderdate, - t16.o_orderpriority AS o_orderpriority, - t16.o_clerk AS o_clerk, - t16.o_shippriority AS o_shippriority, - t16.o_comment AS o_comment, - t16.l_orderkey AS l_orderkey, - t16.l_partkey AS l_partkey, - t16.l_suppkey AS l_suppkey, - t16.l_linenumber AS l_linenumber, - t16.l_quantity AS l_quantity, - t16.l_extendedprice AS l_extendedprice, - t16.l_discount AS l_discount, - t16.l_tax AS l_tax, - t16.l_returnflag AS l_returnflag, - t16.l_linestatus AS l_linestatus, - t16.l_shipdate AS l_shipdate, - t16.l_commitdate AS l_commitdate, - t16.l_receiptdate AS l_receiptdate, - t16.l_shipinstruct AS l_shipinstruct, - t16.l_shipmode AS l_shipmode, - t16.l_comment AS l_comment, - t16.s_suppkey AS s_suppkey, - t16.s_name AS s_name, - t16.s_address AS s_address, - t16.s_nationkey AS s_nationkey, - t16.s_phone AS s_phone, - t16.s_acctbal AS s_acctbal, - t16.s_comment AS s_comment, - t16.n_nationkey AS n_nationkey, - t16.n_name AS n_name, - t16.n_regionkey AS n_regionkey, - t16.n_comment AS n_comment, - t16.r_regionkey AS r_regionkey, - t16.r_name AS r_name, - t16.r_comment AS r_comment + t17.c_custkey, + t17.c_name, + t17.c_address, + t17.c_nationkey, + t17.c_phone, + t17.c_acctbal, + t17.c_mktsegment, + t17.c_comment, + t17.o_orderkey, + t17.o_custkey, + t17.o_orderstatus, + t17.o_totalprice, + t17.o_orderdate, + t17.o_orderpriority, + t17.o_clerk, + t17.o_shippriority, + t17.o_comment, + t17.l_orderkey, + t17.l_partkey, + t17.l_suppkey, + t17.l_linenumber, + t17.l_quantity, + t17.l_extendedprice, + t17.l_discount, + t17.l_tax, + t17.l_returnflag, + t17.l_linestatus, + t17.l_shipdate, + t17.l_commitdate, + t17.l_receiptdate, + t17.l_shipinstruct, + t17.l_shipmode, + t17.l_comment, + t17.s_suppkey, + t17.s_name, + t17.s_address, + t17.s_nationkey, + t17.s_phone, + t17.s_acctbal, + t17.s_comment, + t17.n_nationkey, + t17.n_name, + t17.n_regionkey, + t17.n_comment, + t17.r_regionkey, + t17.r_name, + t17.r_comment FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t6.o_orderkey AS o_orderkey, - t6.o_custkey AS o_custkey, - t6.o_orderstatus AS o_orderstatus, - t6.o_totalprice AS o_totalprice, - t6.o_orderdate AS o_orderdate, - t6.o_orderpriority AS o_orderpriority, - t6.o_clerk AS o_clerk, - t6.o_shippriority AS o_shippriority, - t6.o_comment AS o_comment, - t7.l_orderkey AS l_orderkey, - t7.l_partkey AS l_partkey, - t7.l_suppkey AS l_suppkey, - t7.l_linenumber AS l_linenumber, - t7.l_quantity AS l_quantity, - t7.l_extendedprice AS l_extendedprice, - t7.l_discount AS l_discount, - t7.l_tax AS l_tax, - t7.l_returnflag AS l_returnflag, - t7.l_linestatus AS l_linestatus, - t7.l_shipdate AS l_shipdate, - t7.l_commitdate AS l_commitdate, - t7.l_receiptdate AS l_receiptdate, - t7.l_shipinstruct AS l_shipinstruct, - t7.l_shipmode AS l_shipmode, - t7.l_comment AS l_comment, - t8.s_suppkey AS s_suppkey, - t8.s_name AS s_name, - t8.s_address AS s_address, - t8.s_nationkey AS s_nationkey, - t8.s_phone AS s_phone, - t8.s_acctbal AS s_acctbal, - t8.s_comment AS s_comment, - t9.n_nationkey AS n_nationkey, - t9.n_name AS n_name, - t9.n_regionkey AS n_regionkey, - t9.n_comment AS n_comment, - t10.r_regionkey AS r_regionkey, - t10.r_name AS r_name, - t10.r_comment AS r_comment - FROM customer AS t0 - INNER JOIN orders AS t6 - ON t0.c_custkey = t6.o_custkey - INNER JOIN lineitem AS t7 - ON t7.l_orderkey = t6.o_orderkey - INNER JOIN supplier AS t8 - ON t7.l_suppkey = t8.s_suppkey - INNER JOIN nation AS t9 - ON t0.c_nationkey = t8.s_nationkey AND t8.s_nationkey = t9.n_nationkey - INNER JOIN region AS t10 - ON t9.n_regionkey = t10.r_regionkey - ) AS t16 + t6.c_custkey, + t6.c_name, + t6.c_address, + t6.c_nationkey, + t6.c_phone, + t6.c_acctbal, + t6.c_mktsegment, + t6.c_comment, + t7.o_orderkey, + t7.o_custkey, + t7.o_orderstatus, + t7.o_totalprice, + t7.o_orderdate, + t7.o_orderpriority, + t7.o_clerk, + t7.o_shippriority, + t7.o_comment, + t8.l_orderkey, + t8.l_partkey, + t8.l_suppkey, + t8.l_linenumber, + t8.l_quantity, + t8.l_extendedprice, + t8.l_discount, + t8.l_tax, + t8.l_returnflag, + t8.l_linestatus, + t8.l_shipdate, + t8.l_commitdate, + t8.l_receiptdate, + t8.l_shipinstruct, + t8.l_shipmode, + t8.l_comment, + t9.s_suppkey, + t9.s_name, + t9.s_address, + t9.s_nationkey, + t9.s_phone, + t9.s_acctbal, + t9.s_comment, + t10.n_nationkey, + t10.n_name, + t10.n_regionkey, + t10.n_comment, + t11.r_regionkey, + t11.r_name, + t11.r_comment + FROM customer AS t6 + INNER JOIN orders AS t7 + ON t6.c_custkey = t7.o_custkey + INNER JOIN lineitem AS t8 + ON t8.l_orderkey = t7.o_orderkey + INNER JOIN supplier AS t9 + ON t8.l_suppkey = t9.s_suppkey + INNER JOIN nation AS t10 + ON t6.c_nationkey = t9.s_nationkey AND t9.s_nationkey = t10.n_nationkey + INNER JOIN region AS t11 + ON t10.n_regionkey = t11.r_regionkey + ) AS t17 WHERE - t16.r_name = 'ASIA' - AND t16.o_orderdate >= MAKE_DATE(1994, 1, 1) - AND t16.o_orderdate < MAKE_DATE(1995, 1, 1) - ) AS t17 + t17.r_name = 'ASIA' + AND t17.o_orderdate >= MAKE_DATE(1994, 1, 1) + AND t17.o_orderdate < MAKE_DATE(1995, 1, 1) + ) AS t18 GROUP BY 1 -) AS t18 +) AS t19 ORDER BY - t18.revenue DESC \ No newline at end of file + t19.revenue DESC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h06/test_tpc_h06/duckdb/h06.sql b/ibis/backends/tests/tpch/snapshots/test_h06/test_tpc_h06/duckdb/h06.sql index 6bf7c29188d7f..eea01a0277a6a 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h06/test_tpc_h06/duckdb/h06.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h06/test_tpc_h06/duckdb/h06.sql @@ -2,22 +2,22 @@ SELECT SUM(t1.l_extendedprice * t1.l_discount) AS revenue FROM ( SELECT - t0.l_orderkey AS l_orderkey, - t0.l_partkey AS l_partkey, - t0.l_suppkey AS l_suppkey, - t0.l_linenumber AS l_linenumber, - t0.l_quantity AS l_quantity, - t0.l_extendedprice AS l_extendedprice, - t0.l_discount AS l_discount, - t0.l_tax AS l_tax, - t0.l_returnflag AS l_returnflag, - t0.l_linestatus AS l_linestatus, - t0.l_shipdate AS l_shipdate, - t0.l_commitdate AS l_commitdate, - t0.l_receiptdate AS l_receiptdate, - t0.l_shipinstruct AS l_shipinstruct, - t0.l_shipmode AS l_shipmode, - t0.l_comment AS l_comment + t0.l_orderkey, + t0.l_partkey, + t0.l_suppkey, + t0.l_linenumber, + t0.l_quantity, + t0.l_extendedprice, + t0.l_discount, + t0.l_tax, + t0.l_returnflag, + t0.l_linestatus, + t0.l_shipdate, + t0.l_commitdate, + t0.l_receiptdate, + t0.l_shipinstruct, + t0.l_shipmode, + t0.l_comment FROM lineitem AS t0 WHERE t0.l_shipdate >= MAKE_DATE(1994, 1, 1) diff --git a/ibis/backends/tests/tpch/snapshots/test_h07/test_tpc_h07/duckdb/h07.sql b/ibis/backends/tests/tpch/snapshots/test_h07/test_tpc_h07/duckdb/h07.sql index 171bbd4b75d86..35411472de9a0 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h07/test_tpc_h07/duckdb/h07.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h07/test_tpc_h07/duckdb/h07.sql @@ -1,51 +1,71 @@ -WITH t0 AS ( - SELECT - t6.n_name AS supp_nation, - t7.n_name AS cust_nation, - t3.l_shipdate AS l_shipdate, - t3.l_extendedprice AS l_extendedprice, - t3.l_discount AS l_discount, - CAST(EXTRACT(year FROM t3.l_shipdate) AS SMALLINT) AS l_year, - t3.l_extendedprice * ( - CAST(1 AS TINYINT) - t3.l_discount - ) AS volume - FROM main.supplier AS t2 - JOIN main.lineitem AS t3 - ON t2.s_suppkey = t3.l_suppkey - JOIN main.orders AS t4 - ON t4.o_orderkey = t3.l_orderkey - JOIN main.customer AS t5 - ON t5.c_custkey = t4.o_custkey - JOIN main.nation AS t6 - ON t2.s_nationkey = t6.n_nationkey - JOIN main.nation AS t7 - ON t5.c_nationkey = t7.n_nationkey -) SELECT - t1.supp_nation, - t1.cust_nation, - t1.l_year, - t1.revenue + t19.supp_nation, + t19.cust_nation, + t19.l_year, + t19.revenue FROM ( SELECT - t0.supp_nation AS supp_nation, - t0.cust_nation AS cust_nation, - t0.l_year AS l_year, - SUM(t0.volume) AS revenue - FROM t0 - WHERE - ( - t0.cust_nation = 'FRANCE' AND t0.supp_nation = 'GERMANY' - OR t0.cust_nation = 'GERMANY' - AND t0.supp_nation = 'FRANCE' - ) - AND t0.l_shipdate BETWEEN MAKE_DATE(1995, 1, 1) AND MAKE_DATE(1996, 12, 31) + t18.supp_nation, + t18.cust_nation, + t18.l_year, + SUM(t18.volume) AS revenue + FROM ( + SELECT + t17.supp_nation, + t17.cust_nation, + t17.l_shipdate, + t17.l_extendedprice, + t17.l_discount, + t17.l_year, + t17.volume + FROM ( + SELECT + t9.n_name AS supp_nation, + t11.n_name AS cust_nation, + t6.l_shipdate, + t6.l_extendedprice, + t6.l_discount, + EXTRACT('year' FROM t6.l_shipdate) AS l_year, + t6.l_extendedprice * ( + CAST(1 AS TINYINT) - t6.l_discount + ) AS volume + FROM supplier AS t5 + INNER JOIN lineitem AS t6 + ON t5.s_suppkey = t6.l_suppkey + INNER JOIN orders AS t7 + ON t7.o_orderkey = t6.l_orderkey + INNER JOIN customer AS t8 + ON t8.c_custkey = t7.o_custkey + INNER JOIN nation AS t9 + ON t5.s_nationkey = t9.n_nationkey + INNER JOIN nation AS t11 + ON t8.c_nationkey = t11.n_nationkey + ) AS t17 + WHERE + ( + ( + ( + t17.cust_nation = 'FRANCE' + ) AND ( + t17.supp_nation = 'GERMANY' + ) + ) + OR ( + ( + t17.cust_nation = 'GERMANY' + ) AND ( + t17.supp_nation = 'FRANCE' + ) + ) + ) + AND t17.l_shipdate BETWEEN MAKE_DATE(1995, 1, 1) AND MAKE_DATE(1996, 12, 31) + ) AS t18 GROUP BY 1, 2, 3 -) AS t1 +) AS t19 ORDER BY - t1.supp_nation ASC, - t1.cust_nation ASC, - t1.l_year ASC \ No newline at end of file + t19.supp_nation ASC, + t19.cust_nation ASC, + t19.l_year ASC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h08/test_tpc_h08/duckdb/h08.sql b/ibis/backends/tests/tpch/snapshots/test_h08/test_tpc_h08/duckdb/h08.sql index e588d3e1466fd..97b1be133851c 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h08/test_tpc_h08/duckdb/h08.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h08/test_tpc_h08/duckdb/h08.sql @@ -1,52 +1,52 @@ SELECT - t23.o_year AS o_year, - t23.mkt_share AS mkt_share + t25.o_year, + t25.mkt_share FROM ( SELECT - t22.o_year AS o_year, - SUM(t22.nation_volume) / SUM(t22.volume) AS mkt_share + t24.o_year, + SUM(t24.nation_volume) / SUM(t24.volume) AS mkt_share FROM ( SELECT - t21.o_year AS o_year, - t21.volume AS volume, - t21.nation AS nation, - t21.r_name AS r_name, - t21.o_orderdate AS o_orderdate, - t21.p_type AS p_type, - CASE WHEN t21.nation = 'BRAZIL' THEN t21.volume ELSE CAST(0 AS TINYINT) END AS nation_volume + t23.o_year, + t23.volume, + t23.nation, + t23.r_name, + t23.o_orderdate, + t23.p_type, + CASE WHEN t23.nation = 'BRAZIL' THEN t23.volume ELSE CAST(0 AS TINYINT) END AS nation_volume FROM ( SELECT - EXTRACT('year' FROM t9.o_orderdate) AS o_year, - t7.l_extendedprice * ( - CAST(1 AS TINYINT) - t7.l_discount + EXTRACT('year' FROM t10.o_orderdate) AS o_year, + t8.l_extendedprice * ( + CAST(1 AS TINYINT) - t8.l_discount ) AS volume, - t12.n_name AS nation, - t13.r_name AS r_name, - t9.o_orderdate AS o_orderdate, - t0.p_type AS p_type - FROM part AS t0 - INNER JOIN lineitem AS t7 - ON t0.p_partkey = t7.l_partkey - INNER JOIN supplier AS t8 - ON t8.s_suppkey = t7.l_suppkey - INNER JOIN orders AS t9 - ON t7.l_orderkey = t9.o_orderkey - INNER JOIN customer AS t10 - ON t9.o_custkey = t10.c_custkey - INNER JOIN nation AS t11 - ON t10.c_nationkey = t11.n_nationkey - INNER JOIN region AS t13 - ON t11.n_regionkey = t13.r_regionkey + t15.n_name AS nation, + t14.r_name, + t10.o_orderdate, + t7.p_type + FROM part AS t7 + INNER JOIN lineitem AS t8 + ON t7.p_partkey = t8.l_partkey + INNER JOIN supplier AS t9 + ON t9.s_suppkey = t8.l_suppkey + INNER JOIN orders AS t10 + ON t8.l_orderkey = t10.o_orderkey + INNER JOIN customer AS t11 + ON t10.o_custkey = t11.c_custkey INNER JOIN nation AS t12 - ON t8.s_nationkey = t12.n_nationkey - ) AS t21 + ON t11.c_nationkey = t12.n_nationkey + INNER JOIN region AS t14 + ON t12.n_regionkey = t14.r_regionkey + INNER JOIN nation AS t15 + ON t9.s_nationkey = t15.n_nationkey + ) AS t23 WHERE - t21.r_name = 'AMERICA' - AND t21.o_orderdate BETWEEN MAKE_DATE(1995, 1, 1) AND MAKE_DATE(1996, 12, 31) - AND t21.p_type = 'ECONOMY ANODIZED STEEL' - ) AS t22 + t23.r_name = 'AMERICA' + AND t23.o_orderdate BETWEEN MAKE_DATE(1995, 1, 1) AND MAKE_DATE(1996, 12, 31) + AND t23.p_type = 'ECONOMY ANODIZED STEEL' + ) AS t24 GROUP BY 1 -) AS t23 +) AS t25 ORDER BY - t23.o_year ASC \ No newline at end of file + t25.o_year ASC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h09/test_tpc_h09/duckdb/h09.sql b/ibis/backends/tests/tpch/snapshots/test_h09/test_tpc_h09/duckdb/h09.sql index 1b3de4b3fb5b5..21489f03313d6 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h09/test_tpc_h09/duckdb/h09.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h09/test_tpc_h09/duckdb/h09.sql @@ -1,49 +1,49 @@ SELECT - t18.nation AS nation, - t18.o_year AS o_year, - t18.sum_profit AS sum_profit + t19.nation, + t19.o_year, + t19.sum_profit FROM ( SELECT - t17.nation AS nation, - t17.o_year AS o_year, - SUM(t17.amount) AS sum_profit + t18.nation, + t18.o_year, + SUM(t18.amount) AS sum_profit FROM ( SELECT - t16.amount AS amount, - t16.o_year AS o_year, - t16.nation AS nation, - t16.p_name AS p_name + t17.amount, + t17.o_year, + t17.nation, + t17.p_name FROM ( SELECT ( - t0.l_extendedprice * ( - CAST(1 AS TINYINT) - t0.l_discount + t6.l_extendedprice * ( + CAST(1 AS TINYINT) - t6.l_discount ) ) - ( - t7.ps_supplycost * t0.l_quantity + t8.ps_supplycost * t6.l_quantity ) AS amount, - EXTRACT('year' FROM t9.o_orderdate) AS o_year, - t10.n_name AS nation, - t8.p_name AS p_name - FROM lineitem AS t0 - INNER JOIN supplier AS t6 - ON t6.s_suppkey = t0.l_suppkey - INNER JOIN partsupp AS t7 - ON t7.ps_suppkey = t0.l_suppkey AND t7.ps_partkey = t0.l_partkey - INNER JOIN part AS t8 - ON t8.p_partkey = t0.l_partkey - INNER JOIN orders AS t9 - ON t9.o_orderkey = t0.l_orderkey - INNER JOIN nation AS t10 - ON t6.s_nationkey = t10.n_nationkey - ) AS t16 + EXTRACT('year' FROM t10.o_orderdate) AS o_year, + t11.n_name AS nation, + t9.p_name + FROM lineitem AS t6 + INNER JOIN supplier AS t7 + ON t7.s_suppkey = t6.l_suppkey + INNER JOIN partsupp AS t8 + ON t8.ps_suppkey = t6.l_suppkey AND t8.ps_partkey = t6.l_partkey + INNER JOIN part AS t9 + ON t9.p_partkey = t6.l_partkey + INNER JOIN orders AS t10 + ON t10.o_orderkey = t6.l_orderkey + INNER JOIN nation AS t11 + ON t7.s_nationkey = t11.n_nationkey + ) AS t17 WHERE - t16.p_name LIKE '%green%' - ) AS t17 + t17.p_name LIKE '%green%' + ) AS t18 GROUP BY 1, 2 -) AS t18 +) AS t19 ORDER BY - t18.nation ASC, - t18.o_year DESC \ No newline at end of file + t19.nation ASC, + t19.o_year DESC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h10/test_tpc_h10/duckdb/h10.sql b/ibis/backends/tests/tpch/snapshots/test_h10/test_tpc_h10/duckdb/h10.sql index 9fd9b9eec3662..a08b8198283b6 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h10/test_tpc_h10/duckdb/h10.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h10/test_tpc_h10/duckdb/h10.sql @@ -1,115 +1,115 @@ SELECT - t12.c_custkey AS c_custkey, - t12.c_name AS c_name, - t12.revenue AS revenue, - t12.c_acctbal AS c_acctbal, - t12.n_name AS n_name, - t12.c_address AS c_address, - t12.c_phone AS c_phone, - t12.c_comment AS c_comment + t13.c_custkey, + t13.c_name, + t13.revenue, + t13.c_acctbal, + t13.n_name, + t13.c_address, + t13.c_phone, + t13.c_comment FROM ( SELECT - t11.c_custkey AS c_custkey, - t11.c_name AS c_name, - t11.c_acctbal AS c_acctbal, - t11.n_name AS n_name, - t11.c_address AS c_address, - t11.c_phone AS c_phone, - t11.c_comment AS c_comment, - SUM(t11.l_extendedprice * ( - CAST(1 AS TINYINT) - t11.l_discount + t12.c_custkey, + t12.c_name, + t12.c_acctbal, + t12.n_name, + t12.c_address, + t12.c_phone, + t12.c_comment, + SUM(t12.l_extendedprice * ( + CAST(1 AS TINYINT) - t12.l_discount )) AS revenue FROM ( SELECT - t10.c_custkey AS c_custkey, - t10.c_name AS c_name, - t10.c_address AS c_address, - t10.c_nationkey AS c_nationkey, - t10.c_phone AS c_phone, - t10.c_acctbal AS c_acctbal, - t10.c_mktsegment AS c_mktsegment, - t10.c_comment AS c_comment, - t10.o_orderkey AS o_orderkey, - t10.o_custkey AS o_custkey, - t10.o_orderstatus AS o_orderstatus, - t10.o_totalprice AS o_totalprice, - t10.o_orderdate AS o_orderdate, - t10.o_orderpriority AS o_orderpriority, - t10.o_clerk AS o_clerk, - t10.o_shippriority AS o_shippriority, - t10.o_comment AS o_comment, - t10.l_orderkey AS l_orderkey, - t10.l_partkey AS l_partkey, - t10.l_suppkey AS l_suppkey, - t10.l_linenumber AS l_linenumber, - t10.l_quantity AS l_quantity, - t10.l_extendedprice AS l_extendedprice, - t10.l_discount AS l_discount, - t10.l_tax AS l_tax, - t10.l_returnflag AS l_returnflag, - t10.l_linestatus AS l_linestatus, - t10.l_shipdate AS l_shipdate, - t10.l_commitdate AS l_commitdate, - t10.l_receiptdate AS l_receiptdate, - t10.l_shipinstruct AS l_shipinstruct, - t10.l_shipmode AS l_shipmode, - t10.l_comment AS l_comment, - t10.n_nationkey AS n_nationkey, - t10.n_name AS n_name, - t10.n_regionkey AS n_regionkey, - t10.n_comment AS n_comment + t11.c_custkey, + t11.c_name, + t11.c_address, + t11.c_nationkey, + t11.c_phone, + t11.c_acctbal, + t11.c_mktsegment, + t11.c_comment, + t11.o_orderkey, + t11.o_custkey, + t11.o_orderstatus, + t11.o_totalprice, + t11.o_orderdate, + t11.o_orderpriority, + t11.o_clerk, + t11.o_shippriority, + t11.o_comment, + t11.l_orderkey, + t11.l_partkey, + t11.l_suppkey, + t11.l_linenumber, + t11.l_quantity, + t11.l_extendedprice, + t11.l_discount, + t11.l_tax, + t11.l_returnflag, + t11.l_linestatus, + t11.l_shipdate, + t11.l_commitdate, + t11.l_receiptdate, + t11.l_shipinstruct, + t11.l_shipmode, + t11.l_comment, + t11.n_nationkey, + t11.n_name, + t11.n_regionkey, + t11.n_comment FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t4.o_orderkey AS o_orderkey, - t4.o_custkey AS o_custkey, - t4.o_orderstatus AS o_orderstatus, - t4.o_totalprice AS o_totalprice, - t4.o_orderdate AS o_orderdate, - t4.o_orderpriority AS o_orderpriority, - t4.o_clerk AS o_clerk, - t4.o_shippriority AS o_shippriority, - t4.o_comment AS o_comment, - t5.l_orderkey AS l_orderkey, - t5.l_partkey AS l_partkey, - t5.l_suppkey AS l_suppkey, - t5.l_linenumber AS l_linenumber, - t5.l_quantity AS l_quantity, - t5.l_extendedprice AS l_extendedprice, - t5.l_discount AS l_discount, - t5.l_tax AS l_tax, - t5.l_returnflag AS l_returnflag, - t5.l_linestatus AS l_linestatus, - t5.l_shipdate AS l_shipdate, - t5.l_commitdate AS l_commitdate, - t5.l_receiptdate AS l_receiptdate, - t5.l_shipinstruct AS l_shipinstruct, - t5.l_shipmode AS l_shipmode, - t5.l_comment AS l_comment, - t6.n_nationkey AS n_nationkey, - t6.n_name AS n_name, - t6.n_regionkey AS n_regionkey, - t6.n_comment AS n_comment - FROM customer AS t0 - INNER JOIN orders AS t4 - ON t0.c_custkey = t4.o_custkey - INNER JOIN lineitem AS t5 - ON t5.l_orderkey = t4.o_orderkey - INNER JOIN nation AS t6 - ON t0.c_nationkey = t6.n_nationkey - ) AS t10 + t4.c_custkey, + t4.c_name, + t4.c_address, + t4.c_nationkey, + t4.c_phone, + t4.c_acctbal, + t4.c_mktsegment, + t4.c_comment, + t5.o_orderkey, + t5.o_custkey, + t5.o_orderstatus, + t5.o_totalprice, + t5.o_orderdate, + t5.o_orderpriority, + t5.o_clerk, + t5.o_shippriority, + t5.o_comment, + t6.l_orderkey, + t6.l_partkey, + t6.l_suppkey, + t6.l_linenumber, + t6.l_quantity, + t6.l_extendedprice, + t6.l_discount, + t6.l_tax, + t6.l_returnflag, + t6.l_linestatus, + t6.l_shipdate, + t6.l_commitdate, + t6.l_receiptdate, + t6.l_shipinstruct, + t6.l_shipmode, + t6.l_comment, + t7.n_nationkey, + t7.n_name, + t7.n_regionkey, + t7.n_comment + FROM customer AS t4 + INNER JOIN orders AS t5 + ON t4.c_custkey = t5.o_custkey + INNER JOIN lineitem AS t6 + ON t6.l_orderkey = t5.o_orderkey + INNER JOIN nation AS t7 + ON t4.c_nationkey = t7.n_nationkey + ) AS t11 WHERE - t10.o_orderdate >= MAKE_DATE(1993, 10, 1) - AND t10.o_orderdate < MAKE_DATE(1994, 1, 1) - AND t10.l_returnflag = 'R' - ) AS t11 + t11.o_orderdate >= MAKE_DATE(1993, 10, 1) + AND t11.o_orderdate < MAKE_DATE(1994, 1, 1) + AND t11.l_returnflag = 'R' + ) AS t12 GROUP BY 1, 2, @@ -118,7 +118,7 @@ FROM ( 5, 6, 7 -) AS t12 +) AS t13 ORDER BY - t12.revenue DESC + t13.revenue DESC LIMIT 20 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h11/test_tpc_h11/duckdb/h11.sql b/ibis/backends/tests/tpch/snapshots/test_h11/test_tpc_h11/duckdb/h11.sql index e78e350dc9a94..c5d401180d419 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h11/test_tpc_h11/duckdb/h11.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h11/test_tpc_h11/duckdb/h11.sql @@ -1,109 +1,109 @@ SELECT - t15.ps_partkey AS ps_partkey, - t15.value AS value + t10.ps_partkey, + t10.value FROM ( SELECT - t13.ps_partkey AS ps_partkey, - SUM(t13.ps_supplycost * t13.ps_availqty) AS value + t9.ps_partkey, + SUM(t9.ps_supplycost * t9.ps_availqty) AS value FROM ( SELECT - t11.ps_partkey AS ps_partkey, - t11.ps_suppkey AS ps_suppkey, - t11.ps_availqty AS ps_availqty, - t11.ps_supplycost AS ps_supplycost, - t11.ps_comment AS ps_comment, - t11.s_suppkey AS s_suppkey, - t11.s_name AS s_name, - t11.s_address AS s_address, - t11.s_nationkey AS s_nationkey, - t11.s_phone AS s_phone, - t11.s_acctbal AS s_acctbal, - t11.s_comment AS s_comment, - t11.n_nationkey AS n_nationkey, - t11.n_name AS n_name, - t11.n_regionkey AS n_regionkey, - t11.n_comment AS n_comment + t8.ps_partkey, + t8.ps_suppkey, + t8.ps_availqty, + t8.ps_supplycost, + t8.ps_comment, + t8.s_suppkey, + t8.s_name, + t8.s_address, + t8.s_nationkey, + t8.s_phone, + t8.s_acctbal, + t8.s_comment, + t8.n_nationkey, + t8.n_name, + t8.n_regionkey, + t8.n_comment FROM ( SELECT - t0.ps_partkey AS ps_partkey, - t0.ps_suppkey AS ps_suppkey, - t0.ps_availqty AS ps_availqty, - t0.ps_supplycost AS ps_supplycost, - t0.ps_comment AS ps_comment, - t3.s_suppkey AS s_suppkey, - t3.s_name AS s_name, - t3.s_address AS s_address, - t3.s_nationkey AS s_nationkey, - t3.s_phone AS s_phone, - t3.s_acctbal AS s_acctbal, - t3.s_comment AS s_comment, - t5.n_nationkey AS n_nationkey, - t5.n_name AS n_name, - t5.n_regionkey AS n_regionkey, - t5.n_comment AS n_comment - FROM partsupp AS t0 - INNER JOIN supplier AS t3 - ON t0.ps_suppkey = t3.s_suppkey + t3.ps_partkey, + t3.ps_suppkey, + t3.ps_availqty, + t3.ps_supplycost, + t3.ps_comment, + t4.s_suppkey, + t4.s_name, + t4.s_address, + t4.s_nationkey, + t4.s_phone, + t4.s_acctbal, + t4.s_comment, + t5.n_nationkey, + t5.n_name, + t5.n_regionkey, + t5.n_comment + FROM partsupp AS t3 + INNER JOIN supplier AS t4 + ON t3.ps_suppkey = t4.s_suppkey INNER JOIN nation AS t5 - ON t5.n_nationkey = t3.s_nationkey - ) AS t11 + ON t5.n_nationkey = t4.s_nationkey + ) AS t8 WHERE - t11.n_name = 'GERMANY' - ) AS t13 + t8.n_name = 'GERMANY' + ) AS t9 GROUP BY 1 -) AS t15 +) AS t10 WHERE - t15.value > ( + t10.value > ( ( SELECT - SUM(t14.ps_supplycost * t14.ps_availqty) AS "Sum(Multiply(ps_supplycost, ps_availqty))" + SUM(t9.ps_supplycost * t9.ps_availqty) AS "Sum(Multiply(ps_supplycost, ps_availqty))" FROM ( SELECT - t12.ps_partkey AS ps_partkey, - t12.ps_suppkey AS ps_suppkey, - t12.ps_availqty AS ps_availqty, - t12.ps_supplycost AS ps_supplycost, - t12.ps_comment AS ps_comment, - t12.s_suppkey AS s_suppkey, - t12.s_name AS s_name, - t12.s_address AS s_address, - t12.s_nationkey AS s_nationkey, - t12.s_phone AS s_phone, - t12.s_acctbal AS s_acctbal, - t12.s_comment AS s_comment, - t12.n_nationkey AS n_nationkey, - t12.n_name AS n_name, - t12.n_regionkey AS n_regionkey, - t12.n_comment AS n_comment + t8.ps_partkey, + t8.ps_suppkey, + t8.ps_availqty, + t8.ps_supplycost, + t8.ps_comment, + t8.s_suppkey, + t8.s_name, + t8.s_address, + t8.s_nationkey, + t8.s_phone, + t8.s_acctbal, + t8.s_comment, + t8.n_nationkey, + t8.n_name, + t8.n_regionkey, + t8.n_comment FROM ( SELECT - t0.ps_partkey AS ps_partkey, - t0.ps_suppkey AS ps_suppkey, - t0.ps_availqty AS ps_availqty, - t0.ps_supplycost AS ps_supplycost, - t0.ps_comment AS ps_comment, - t4.s_suppkey AS s_suppkey, - t4.s_name AS s_name, - t4.s_address AS s_address, - t4.s_nationkey AS s_nationkey, - t4.s_phone AS s_phone, - t4.s_acctbal AS s_acctbal, - t4.s_comment AS s_comment, - t6.n_nationkey AS n_nationkey, - t6.n_name AS n_name, - t6.n_regionkey AS n_regionkey, - t6.n_comment AS n_comment - FROM partsupp AS t0 + t3.ps_partkey, + t3.ps_suppkey, + t3.ps_availqty, + t3.ps_supplycost, + t3.ps_comment, + t4.s_suppkey, + t4.s_name, + t4.s_address, + t4.s_nationkey, + t4.s_phone, + t4.s_acctbal, + t4.s_comment, + t5.n_nationkey, + t5.n_name, + t5.n_regionkey, + t5.n_comment + FROM partsupp AS t3 INNER JOIN supplier AS t4 - ON t0.ps_suppkey = t4.s_suppkey - INNER JOIN nation AS t6 - ON t6.n_nationkey = t4.s_nationkey - ) AS t12 + ON t3.ps_suppkey = t4.s_suppkey + INNER JOIN nation AS t5 + ON t5.n_nationkey = t4.s_nationkey + ) AS t8 WHERE - t12.n_name = 'GERMANY' - ) AS t14 + t8.n_name = 'GERMANY' + ) AS t9 ) * CAST(0.0001 AS DOUBLE) ) ORDER BY - t15.value DESC \ No newline at end of file + t10.value DESC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h12/test_tpc_h12/duckdb/h12.sql b/ibis/backends/tests/tpch/snapshots/test_h12/test_tpc_h12/duckdb/h12.sql index 5dd65a2837f06..1b0c38b528aa5 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h12/test_tpc_h12/duckdb/h12.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h12/test_tpc_h12/duckdb/h12.sql @@ -1,12 +1,12 @@ SELECT - t6.l_shipmode AS l_shipmode, - t6.high_line_count AS high_line_count, - t6.low_line_count AS low_line_count + t7.l_shipmode, + t7.high_line_count, + t7.low_line_count FROM ( SELECT - t5.l_shipmode AS l_shipmode, + t6.l_shipmode, SUM( - CASE t5.o_orderpriority + CASE t6.o_orderpriority WHEN '1-URGENT' THEN CAST(1 AS TINYINT) WHEN '2-HIGH' @@ -15,7 +15,7 @@ FROM ( END ) AS high_line_count, SUM( - CASE t5.o_orderpriority + CASE t6.o_orderpriority WHEN '1-URGENT' THEN CAST(0 AS TINYINT) WHEN '2-HIGH' @@ -25,71 +25,71 @@ FROM ( ) AS low_line_count FROM ( SELECT - t4.o_orderkey AS o_orderkey, - t4.o_custkey AS o_custkey, - t4.o_orderstatus AS o_orderstatus, - t4.o_totalprice AS o_totalprice, - t4.o_orderdate AS o_orderdate, - t4.o_orderpriority AS o_orderpriority, - t4.o_clerk AS o_clerk, - t4.o_shippriority AS o_shippriority, - t4.o_comment AS o_comment, - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment + t5.o_orderkey, + t5.o_custkey, + t5.o_orderstatus, + t5.o_totalprice, + t5.o_orderdate, + t5.o_orderpriority, + t5.o_clerk, + t5.o_shippriority, + t5.o_comment, + t5.l_orderkey, + t5.l_partkey, + t5.l_suppkey, + t5.l_linenumber, + t5.l_quantity, + t5.l_extendedprice, + t5.l_discount, + t5.l_tax, + t5.l_returnflag, + t5.l_linestatus, + t5.l_shipdate, + t5.l_commitdate, + t5.l_receiptdate, + t5.l_shipinstruct, + t5.l_shipmode, + t5.l_comment FROM ( SELECT - t0.o_orderkey AS o_orderkey, - t0.o_custkey AS o_custkey, - t0.o_orderstatus AS o_orderstatus, - t0.o_totalprice AS o_totalprice, - t0.o_orderdate AS o_orderdate, - t0.o_orderpriority AS o_orderpriority, - t0.o_clerk AS o_clerk, - t0.o_shippriority AS o_shippriority, - t0.o_comment AS o_comment, - t2.l_orderkey AS l_orderkey, - t2.l_partkey AS l_partkey, - t2.l_suppkey AS l_suppkey, - t2.l_linenumber AS l_linenumber, - t2.l_quantity AS l_quantity, - t2.l_extendedprice AS l_extendedprice, - t2.l_discount AS l_discount, - t2.l_tax AS l_tax, - t2.l_returnflag AS l_returnflag, - t2.l_linestatus AS l_linestatus, - t2.l_shipdate AS l_shipdate, - t2.l_commitdate AS l_commitdate, - t2.l_receiptdate AS l_receiptdate, - t2.l_shipinstruct AS l_shipinstruct, - t2.l_shipmode AS l_shipmode, - t2.l_comment AS l_comment - FROM orders AS t0 - INNER JOIN lineitem AS t2 - ON t0.o_orderkey = t2.l_orderkey - ) AS t4 + t2.o_orderkey, + t2.o_custkey, + t2.o_orderstatus, + t2.o_totalprice, + t2.o_orderdate, + t2.o_orderpriority, + t2.o_clerk, + t2.o_shippriority, + t2.o_comment, + t3.l_orderkey, + t3.l_partkey, + t3.l_suppkey, + t3.l_linenumber, + t3.l_quantity, + t3.l_extendedprice, + t3.l_discount, + t3.l_tax, + t3.l_returnflag, + t3.l_linestatus, + t3.l_shipdate, + t3.l_commitdate, + t3.l_receiptdate, + t3.l_shipinstruct, + t3.l_shipmode, + t3.l_comment + FROM orders AS t2 + INNER JOIN lineitem AS t3 + ON t2.o_orderkey = t3.l_orderkey + ) AS t5 WHERE - t4.l_shipmode IN ('MAIL', 'SHIP') - AND t4.l_commitdate < t4.l_receiptdate - AND t4.l_shipdate < t4.l_commitdate - AND t4.l_receiptdate >= MAKE_DATE(1994, 1, 1) - AND t4.l_receiptdate < MAKE_DATE(1995, 1, 1) - ) AS t5 + t5.l_shipmode IN ('MAIL', 'SHIP') + AND t5.l_commitdate < t5.l_receiptdate + AND t5.l_shipdate < t5.l_commitdate + AND t5.l_receiptdate >= MAKE_DATE(1994, 1, 1) + AND t5.l_receiptdate < MAKE_DATE(1995, 1, 1) + ) AS t6 GROUP BY 1 -) AS t6 +) AS t7 ORDER BY - t6.l_shipmode ASC \ No newline at end of file + t7.l_shipmode ASC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h13/test_tpc_h13/duckdb/h13.sql b/ibis/backends/tests/tpch/snapshots/test_h13/test_tpc_h13/duckdb/h13.sql index 72657a2846097..58270b87504b6 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h13/test_tpc_h13/duckdb/h13.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h13/test_tpc_h13/duckdb/h13.sql @@ -1,45 +1,45 @@ SELECT - t6.c_count AS c_count, - t6.custdist AS custdist + t7.c_count, + t7.custdist FROM ( SELECT - t5.c_count AS c_count, + t6.c_count, COUNT(*) AS custdist FROM ( SELECT - t4.c_custkey AS c_custkey, - COUNT(t4.o_orderkey) AS c_count + t5.c_custkey, + COUNT(t5.o_orderkey) AS c_count FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t2.o_orderkey AS o_orderkey, - t2.o_custkey AS o_custkey, - t2.o_orderstatus AS o_orderstatus, - t2.o_totalprice AS o_totalprice, - t2.o_orderdate AS o_orderdate, - t2.o_orderpriority AS o_orderpriority, - t2.o_clerk AS o_clerk, - t2.o_shippriority AS o_shippriority, - t2.o_comment AS o_comment - FROM customer AS t0 - LEFT OUTER JOIN orders AS t2 - ON t0.c_custkey = t2.o_custkey AND NOT ( - t2.o_comment LIKE '%special%requests%' + t2.c_custkey, + t2.c_name, + t2.c_address, + t2.c_nationkey, + t2.c_phone, + t2.c_acctbal, + t2.c_mktsegment, + t2.c_comment, + t3.o_orderkey, + t3.o_custkey, + t3.o_orderstatus, + t3.o_totalprice, + t3.o_orderdate, + t3.o_orderpriority, + t3.o_clerk, + t3.o_shippriority, + t3.o_comment + FROM customer AS t2 + LEFT OUTER JOIN orders AS t3 + ON t2.c_custkey = t3.o_custkey AND NOT ( + t3.o_comment LIKE '%special%requests%' ) - ) AS t4 + ) AS t5 GROUP BY 1 - ) AS t5 + ) AS t6 GROUP BY 1 -) AS t6 +) AS t7 ORDER BY - t6.custdist DESC, - t6.c_count DESC \ No newline at end of file + t7.custdist DESC, + t7.c_count DESC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h14/test_tpc_h14/duckdb/h14.sql b/ibis/backends/tests/tpch/snapshots/test_h14/test_tpc_h14/duckdb/h14.sql index dc27f6c655504..42d6dbe835b4a 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h14/test_tpc_h14/duckdb/h14.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h14/test_tpc_h14/duckdb/h14.sql @@ -2,74 +2,74 @@ SELECT ( SUM( CASE - WHEN t5.p_type LIKE 'PROMO%' - THEN t5.l_extendedprice * ( - CAST(1 AS TINYINT) - t5.l_discount + WHEN t6.p_type LIKE 'PROMO%' + THEN t6.l_extendedprice * ( + CAST(1 AS TINYINT) - t6.l_discount ) ELSE CAST(0 AS TINYINT) END ) * CAST(100 AS TINYINT) - ) / SUM(t5.l_extendedprice * ( - CAST(1 AS TINYINT) - t5.l_discount + ) / SUM(t6.l_extendedprice * ( + CAST(1 AS TINYINT) - t6.l_discount )) AS promo_revenue FROM ( SELECT - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment, - t4.p_partkey AS p_partkey, - t4.p_name AS p_name, - t4.p_mfgr AS p_mfgr, - t4.p_brand AS p_brand, - t4.p_type AS p_type, - t4.p_size AS p_size, - t4.p_container AS p_container, - t4.p_retailprice AS p_retailprice, - t4.p_comment AS p_comment + t5.l_orderkey, + t5.l_partkey, + t5.l_suppkey, + t5.l_linenumber, + t5.l_quantity, + t5.l_extendedprice, + t5.l_discount, + t5.l_tax, + t5.l_returnflag, + t5.l_linestatus, + t5.l_shipdate, + t5.l_commitdate, + t5.l_receiptdate, + t5.l_shipinstruct, + t5.l_shipmode, + t5.l_comment, + t5.p_partkey, + t5.p_name, + t5.p_mfgr, + t5.p_brand, + t5.p_type, + t5.p_size, + t5.p_container, + t5.p_retailprice, + t5.p_comment FROM ( SELECT - t0.l_orderkey AS l_orderkey, - t0.l_partkey AS l_partkey, - t0.l_suppkey AS l_suppkey, - t0.l_linenumber AS l_linenumber, - t0.l_quantity AS l_quantity, - t0.l_extendedprice AS l_extendedprice, - t0.l_discount AS l_discount, - t0.l_tax AS l_tax, - t0.l_returnflag AS l_returnflag, - t0.l_linestatus AS l_linestatus, - t0.l_shipdate AS l_shipdate, - t0.l_commitdate AS l_commitdate, - t0.l_receiptdate AS l_receiptdate, - t0.l_shipinstruct AS l_shipinstruct, - t0.l_shipmode AS l_shipmode, - t0.l_comment AS l_comment, - t2.p_partkey AS p_partkey, - t2.p_name AS p_name, - t2.p_mfgr AS p_mfgr, - t2.p_brand AS p_brand, - t2.p_type AS p_type, - t2.p_size AS p_size, - t2.p_container AS p_container, - t2.p_retailprice AS p_retailprice, - t2.p_comment AS p_comment - FROM lineitem AS t0 - INNER JOIN part AS t2 - ON t0.l_partkey = t2.p_partkey - ) AS t4 + t2.l_orderkey, + t2.l_partkey, + t2.l_suppkey, + t2.l_linenumber, + t2.l_quantity, + t2.l_extendedprice, + t2.l_discount, + t2.l_tax, + t2.l_returnflag, + t2.l_linestatus, + t2.l_shipdate, + t2.l_commitdate, + t2.l_receiptdate, + t2.l_shipinstruct, + t2.l_shipmode, + t2.l_comment, + t3.p_partkey, + t3.p_name, + t3.p_mfgr, + t3.p_brand, + t3.p_type, + t3.p_size, + t3.p_container, + t3.p_retailprice, + t3.p_comment + FROM lineitem AS t2 + INNER JOIN part AS t3 + ON t2.l_partkey = t3.p_partkey + ) AS t5 WHERE - t4.l_shipdate >= MAKE_DATE(1995, 9, 1) AND t4.l_shipdate < MAKE_DATE(1995, 10, 1) -) AS t5 \ No newline at end of file + t5.l_shipdate >= MAKE_DATE(1995, 9, 1) AND t5.l_shipdate < MAKE_DATE(1995, 10, 1) +) AS t6 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h15/test_tpc_h15/duckdb/h15.sql b/ibis/backends/tests/tpch/snapshots/test_h15/test_tpc_h15/duckdb/h15.sql index fc6c924aca222..afad257dc2f2a 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h15/test_tpc_h15/duckdb/h15.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h15/test_tpc_h15/duckdb/h15.sql @@ -1,103 +1,103 @@ SELECT - t6.s_suppkey AS s_suppkey, - t6.s_name AS s_name, - t6.s_address AS s_address, - t6.s_phone AS s_phone, - t6.total_revenue AS total_revenue + t7.s_suppkey, + t7.s_name, + t7.s_address, + t7.s_phone, + t7.total_revenue FROM ( SELECT - t0.s_suppkey AS s_suppkey, - t0.s_name AS s_name, - t0.s_address AS s_address, - t0.s_nationkey AS s_nationkey, - t0.s_phone AS s_phone, - t0.s_acctbal AS s_acctbal, - t0.s_comment AS s_comment, - t4.l_suppkey AS l_suppkey, - t4.total_revenue AS total_revenue - FROM supplier AS t0 + t2.s_suppkey, + t2.s_name, + t2.s_address, + t2.s_nationkey, + t2.s_phone, + t2.s_acctbal, + t2.s_comment, + t5.l_suppkey, + t5.total_revenue + FROM supplier AS t2 INNER JOIN ( SELECT - t2.l_suppkey AS l_suppkey, - SUM(t2.l_extendedprice * ( - CAST(1 AS TINYINT) - t2.l_discount + t3.l_suppkey, + SUM(t3.l_extendedprice * ( + CAST(1 AS TINYINT) - t3.l_discount )) AS total_revenue FROM ( SELECT - t1.l_orderkey AS l_orderkey, - t1.l_partkey AS l_partkey, - t1.l_suppkey AS l_suppkey, - t1.l_linenumber AS l_linenumber, - t1.l_quantity AS l_quantity, - t1.l_extendedprice AS l_extendedprice, - t1.l_discount AS l_discount, - t1.l_tax AS l_tax, - t1.l_returnflag AS l_returnflag, - t1.l_linestatus AS l_linestatus, - t1.l_shipdate AS l_shipdate, - t1.l_commitdate AS l_commitdate, - t1.l_receiptdate AS l_receiptdate, - t1.l_shipinstruct AS l_shipinstruct, - t1.l_shipmode AS l_shipmode, - t1.l_comment AS l_comment + t1.l_orderkey, + t1.l_partkey, + t1.l_suppkey, + t1.l_linenumber, + t1.l_quantity, + t1.l_extendedprice, + t1.l_discount, + t1.l_tax, + t1.l_returnflag, + t1.l_linestatus, + t1.l_shipdate, + t1.l_commitdate, + t1.l_receiptdate, + t1.l_shipinstruct, + t1.l_shipmode, + t1.l_comment FROM lineitem AS t1 WHERE t1.l_shipdate >= MAKE_DATE(1996, 1, 1) AND t1.l_shipdate < MAKE_DATE(1996, 4, 1) - ) AS t2 + ) AS t3 GROUP BY 1 - ) AS t4 - ON t0.s_suppkey = t4.l_suppkey -) AS t6 + ) AS t5 + ON t2.s_suppkey = t5.l_suppkey +) AS t7 WHERE - t6.total_revenue = ( + t7.total_revenue = ( SELECT - MAX(t6.total_revenue) AS "Max(total_revenue)" + MAX(t7.total_revenue) AS "Max(total_revenue)" FROM ( SELECT - t0.s_suppkey AS s_suppkey, - t0.s_name AS s_name, - t0.s_address AS s_address, - t0.s_nationkey AS s_nationkey, - t0.s_phone AS s_phone, - t0.s_acctbal AS s_acctbal, - t0.s_comment AS s_comment, - t4.l_suppkey AS l_suppkey, - t4.total_revenue AS total_revenue - FROM supplier AS t0 + t2.s_suppkey, + t2.s_name, + t2.s_address, + t2.s_nationkey, + t2.s_phone, + t2.s_acctbal, + t2.s_comment, + t5.l_suppkey, + t5.total_revenue + FROM supplier AS t2 INNER JOIN ( SELECT - t2.l_suppkey AS l_suppkey, - SUM(t2.l_extendedprice * ( - CAST(1 AS TINYINT) - t2.l_discount + t3.l_suppkey, + SUM(t3.l_extendedprice * ( + CAST(1 AS TINYINT) - t3.l_discount )) AS total_revenue FROM ( SELECT - t1.l_orderkey AS l_orderkey, - t1.l_partkey AS l_partkey, - t1.l_suppkey AS l_suppkey, - t1.l_linenumber AS l_linenumber, - t1.l_quantity AS l_quantity, - t1.l_extendedprice AS l_extendedprice, - t1.l_discount AS l_discount, - t1.l_tax AS l_tax, - t1.l_returnflag AS l_returnflag, - t1.l_linestatus AS l_linestatus, - t1.l_shipdate AS l_shipdate, - t1.l_commitdate AS l_commitdate, - t1.l_receiptdate AS l_receiptdate, - t1.l_shipinstruct AS l_shipinstruct, - t1.l_shipmode AS l_shipmode, - t1.l_comment AS l_comment + t1.l_orderkey, + t1.l_partkey, + t1.l_suppkey, + t1.l_linenumber, + t1.l_quantity, + t1.l_extendedprice, + t1.l_discount, + t1.l_tax, + t1.l_returnflag, + t1.l_linestatus, + t1.l_shipdate, + t1.l_commitdate, + t1.l_receiptdate, + t1.l_shipinstruct, + t1.l_shipmode, + t1.l_comment FROM lineitem AS t1 WHERE t1.l_shipdate >= MAKE_DATE(1996, 1, 1) AND t1.l_shipdate < MAKE_DATE(1996, 4, 1) - ) AS t2 + ) AS t3 GROUP BY 1 - ) AS t4 - ON t0.s_suppkey = t4.l_suppkey - ) AS t6 + ) AS t5 + ON t2.s_suppkey = t5.l_suppkey + ) AS t7 ) ORDER BY - t6.s_suppkey ASC \ No newline at end of file + t7.s_suppkey ASC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h16/test_tpc_h16/duckdb/h16.sql b/ibis/backends/tests/tpch/snapshots/test_h16/test_tpc_h16/duckdb/h16.sql index b0634e8a2e278..711276ec20dde 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h16/test_tpc_h16/duckdb/h16.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h16/test_tpc_h16/duckdb/h16.sql @@ -1,73 +1,73 @@ SELECT - t8.p_brand AS p_brand, - t8.p_type AS p_type, - t8.p_size AS p_size, - t8.supplier_cnt AS supplier_cnt + t9.p_brand, + t9.p_type, + t9.p_size, + t9.supplier_cnt FROM ( SELECT - t7.p_brand AS p_brand, - t7.p_type AS p_type, - t7.p_size AS p_size, - COUNT(DISTINCT t7.ps_suppkey) AS supplier_cnt + t8.p_brand, + t8.p_type, + t8.p_size, + COUNT(DISTINCT t8.ps_suppkey) AS supplier_cnt FROM ( SELECT - t6.ps_partkey AS ps_partkey, - t6.ps_suppkey AS ps_suppkey, - t6.ps_availqty AS ps_availqty, - t6.ps_supplycost AS ps_supplycost, - t6.ps_comment AS ps_comment, - t6.p_partkey AS p_partkey, - t6.p_name AS p_name, - t6.p_mfgr AS p_mfgr, - t6.p_brand AS p_brand, - t6.p_type AS p_type, - t6.p_size AS p_size, - t6.p_container AS p_container, - t6.p_retailprice AS p_retailprice, - t6.p_comment AS p_comment + t7.ps_partkey, + t7.ps_suppkey, + t7.ps_availqty, + t7.ps_supplycost, + t7.ps_comment, + t7.p_partkey, + t7.p_name, + t7.p_mfgr, + t7.p_brand, + t7.p_type, + t7.p_size, + t7.p_container, + t7.p_retailprice, + t7.p_comment FROM ( SELECT - t0.ps_partkey AS ps_partkey, - t0.ps_suppkey AS ps_suppkey, - t0.ps_availqty AS ps_availqty, - t0.ps_supplycost AS ps_supplycost, - t0.ps_comment AS ps_comment, - t3.p_partkey AS p_partkey, - t3.p_name AS p_name, - t3.p_mfgr AS p_mfgr, - t3.p_brand AS p_brand, - t3.p_type AS p_type, - t3.p_size AS p_size, - t3.p_container AS p_container, - t3.p_retailprice AS p_retailprice, - t3.p_comment AS p_comment - FROM partsupp AS t0 - INNER JOIN part AS t3 - ON t3.p_partkey = t0.ps_partkey - ) AS t6 + t3.ps_partkey, + t3.ps_suppkey, + t3.ps_availqty, + t3.ps_supplycost, + t3.ps_comment, + t4.p_partkey, + t4.p_name, + t4.p_mfgr, + t4.p_brand, + t4.p_type, + t4.p_size, + t4.p_container, + t4.p_retailprice, + t4.p_comment + FROM partsupp AS t3 + INNER JOIN part AS t4 + ON t4.p_partkey = t3.ps_partkey + ) AS t7 WHERE - t6.p_brand <> 'Brand#45' + t7.p_brand <> 'Brand#45' AND NOT ( - t6.p_type LIKE 'MEDIUM POLISHED%' + t7.p_type LIKE 'MEDIUM POLISHED%' ) - AND t6.p_size IN (CAST(49 AS TINYINT), CAST(14 AS TINYINT), CAST(23 AS TINYINT), CAST(45 AS TINYINT), CAST(19 AS TINYINT), CAST(3 AS TINYINT), CAST(36 AS TINYINT), CAST(9 AS TINYINT)) + AND t7.p_size IN (CAST(49 AS TINYINT), CAST(14 AS TINYINT), CAST(23 AS TINYINT), CAST(45 AS TINYINT), CAST(19 AS TINYINT), CAST(3 AS TINYINT), CAST(36 AS TINYINT), CAST(9 AS TINYINT)) AND NOT ( - t6.ps_suppkey IN (( + t7.ps_suppkey IN ( SELECT - t2.s_suppkey AS s_suppkey + t2.s_suppkey FROM supplier AS t2 WHERE t2.s_comment LIKE '%Customer%Complaints%' - )) + ) ) - ) AS t7 + ) AS t8 GROUP BY 1, 2, 3 -) AS t8 +) AS t9 ORDER BY - t8.supplier_cnt DESC, - t8.p_brand ASC, - t8.p_type ASC, - t8.p_size ASC \ No newline at end of file + t9.supplier_cnt DESC, + t9.p_brand ASC, + t9.p_type ASC, + t9.p_size ASC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h17/test_tpc_h17/duckdb/h17.sql b/ibis/backends/tests/tpch/snapshots/test_h17/test_tpc_h17/duckdb/h17.sql index 959c6e0612ee1..905e5c095d3d0 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h17/test_tpc_h17/duckdb/h17.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h17/test_tpc_h17/duckdb/h17.sql @@ -1,92 +1,92 @@ SELECT - SUM(t7.l_extendedprice) / CAST(7.0 AS DOUBLE) AS avg_yearly + SUM(t8.l_extendedprice) / CAST(7.0 AS DOUBLE) AS avg_yearly FROM ( SELECT - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment, - t4.p_partkey AS p_partkey, - t4.p_name AS p_name, - t4.p_mfgr AS p_mfgr, - t4.p_brand AS p_brand, - t4.p_type AS p_type, - t4.p_size AS p_size, - t4.p_container AS p_container, - t4.p_retailprice AS p_retailprice, - t4.p_comment AS p_comment + t5.l_orderkey, + t5.l_partkey, + t5.l_suppkey, + t5.l_linenumber, + t5.l_quantity, + t5.l_extendedprice, + t5.l_discount, + t5.l_tax, + t5.l_returnflag, + t5.l_linestatus, + t5.l_shipdate, + t5.l_commitdate, + t5.l_receiptdate, + t5.l_shipinstruct, + t5.l_shipmode, + t5.l_comment, + t5.p_partkey, + t5.p_name, + t5.p_mfgr, + t5.p_brand, + t5.p_type, + t5.p_size, + t5.p_container, + t5.p_retailprice, + t5.p_comment FROM ( SELECT - t0.l_orderkey AS l_orderkey, - t0.l_partkey AS l_partkey, - t0.l_suppkey AS l_suppkey, - t0.l_linenumber AS l_linenumber, - t0.l_quantity AS l_quantity, - t0.l_extendedprice AS l_extendedprice, - t0.l_discount AS l_discount, - t0.l_tax AS l_tax, - t0.l_returnflag AS l_returnflag, - t0.l_linestatus AS l_linestatus, - t0.l_shipdate AS l_shipdate, - t0.l_commitdate AS l_commitdate, - t0.l_receiptdate AS l_receiptdate, - t0.l_shipinstruct AS l_shipinstruct, - t0.l_shipmode AS l_shipmode, - t0.l_comment AS l_comment, - t2.p_partkey AS p_partkey, - t2.p_name AS p_name, - t2.p_mfgr AS p_mfgr, - t2.p_brand AS p_brand, - t2.p_type AS p_type, - t2.p_size AS p_size, - t2.p_container AS p_container, - t2.p_retailprice AS p_retailprice, - t2.p_comment AS p_comment - FROM lineitem AS t0 - INNER JOIN part AS t2 - ON t2.p_partkey = t0.l_partkey - ) AS t4 + t2.l_orderkey, + t2.l_partkey, + t2.l_suppkey, + t2.l_linenumber, + t2.l_quantity, + t2.l_extendedprice, + t2.l_discount, + t2.l_tax, + t2.l_returnflag, + t2.l_linestatus, + t2.l_shipdate, + t2.l_commitdate, + t2.l_receiptdate, + t2.l_shipinstruct, + t2.l_shipmode, + t2.l_comment, + t3.p_partkey, + t3.p_name, + t3.p_mfgr, + t3.p_brand, + t3.p_type, + t3.p_size, + t3.p_container, + t3.p_retailprice, + t3.p_comment + FROM lineitem AS t2 + INNER JOIN part AS t3 + ON t3.p_partkey = t2.l_partkey + ) AS t5 WHERE - t4.p_brand = 'Brand#23' - AND t4.p_container = 'MED BOX' - AND t4.l_quantity < ( + t5.p_brand = 'Brand#23' + AND t5.p_container = 'MED BOX' + AND t5.l_quantity < ( ( SELECT - AVG(t5.l_quantity) AS "Mean(l_quantity)" + AVG(t6.l_quantity) AS "Mean(l_quantity)" FROM ( SELECT - t0.l_orderkey AS l_orderkey, - t0.l_partkey AS l_partkey, - t0.l_suppkey AS l_suppkey, - t0.l_linenumber AS l_linenumber, - t0.l_quantity AS l_quantity, - t0.l_extendedprice AS l_extendedprice, - t0.l_discount AS l_discount, - t0.l_tax AS l_tax, - t0.l_returnflag AS l_returnflag, - t0.l_linestatus AS l_linestatus, - t0.l_shipdate AS l_shipdate, - t0.l_commitdate AS l_commitdate, - t0.l_receiptdate AS l_receiptdate, - t0.l_shipinstruct AS l_shipinstruct, - t0.l_shipmode AS l_shipmode, - t0.l_comment AS l_comment + t0.l_orderkey, + t0.l_partkey, + t0.l_suppkey, + t0.l_linenumber, + t0.l_quantity, + t0.l_extendedprice, + t0.l_discount, + t0.l_tax, + t0.l_returnflag, + t0.l_linestatus, + t0.l_shipdate, + t0.l_commitdate, + t0.l_receiptdate, + t0.l_shipinstruct, + t0.l_shipmode, + t0.l_comment FROM lineitem AS t0 WHERE - t0.l_partkey = t4.p_partkey - ) AS t5 + t0.l_partkey = t5.p_partkey + ) AS t6 ) * CAST(0.2 AS DOUBLE) ) -) AS t7 \ No newline at end of file +) AS t8 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h18/test_tpc_h18/duckdb/h18.sql b/ibis/backends/tests/tpch/snapshots/test_h18/test_tpc_h18/duckdb/h18.sql index 621c6423e0378..9d3d4f8210105 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h18/test_tpc_h18/duckdb/h18.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h18/test_tpc_h18/duckdb/h18.sql @@ -1,118 +1,118 @@ SELECT - t11.c_name AS c_name, - t11.c_custkey AS c_custkey, - t11.o_orderkey AS o_orderkey, - t11.o_orderdate AS o_orderdate, - t11.o_totalprice AS o_totalprice, - t11.sum_qty AS sum_qty + t12.c_name, + t12.c_custkey, + t12.o_orderkey, + t12.o_orderdate, + t12.o_totalprice, + t12.sum_qty FROM ( SELECT - t10.c_name AS c_name, - t10.c_custkey AS c_custkey, - t10.o_orderkey AS o_orderkey, - t10.o_orderdate AS o_orderdate, - t10.o_totalprice AS o_totalprice, - SUM(t10.l_quantity) AS sum_qty + t11.c_name, + t11.c_custkey, + t11.o_orderkey, + t11.o_orderdate, + t11.o_totalprice, + SUM(t11.l_quantity) AS sum_qty FROM ( SELECT - t8.c_custkey AS c_custkey, - t8.c_name AS c_name, - t8.c_address AS c_address, - t8.c_nationkey AS c_nationkey, - t8.c_phone AS c_phone, - t8.c_acctbal AS c_acctbal, - t8.c_mktsegment AS c_mktsegment, - t8.c_comment AS c_comment, - t8.o_orderkey AS o_orderkey, - t8.o_custkey AS o_custkey, - t8.o_orderstatus AS o_orderstatus, - t8.o_totalprice AS o_totalprice, - t8.o_orderdate AS o_orderdate, - t8.o_orderpriority AS o_orderpriority, - t8.o_clerk AS o_clerk, - t8.o_shippriority AS o_shippriority, - t8.o_comment AS o_comment, - t8.l_orderkey AS l_orderkey, - t8.l_partkey AS l_partkey, - t8.l_suppkey AS l_suppkey, - t8.l_linenumber AS l_linenumber, - t8.l_quantity AS l_quantity, - t8.l_extendedprice AS l_extendedprice, - t8.l_discount AS l_discount, - t8.l_tax AS l_tax, - t8.l_returnflag AS l_returnflag, - t8.l_linestatus AS l_linestatus, - t8.l_shipdate AS l_shipdate, - t8.l_commitdate AS l_commitdate, - t8.l_receiptdate AS l_receiptdate, - t8.l_shipinstruct AS l_shipinstruct, - t8.l_shipmode AS l_shipmode, - t8.l_comment AS l_comment + t9.c_custkey, + t9.c_name, + t9.c_address, + t9.c_nationkey, + t9.c_phone, + t9.c_acctbal, + t9.c_mktsegment, + t9.c_comment, + t9.o_orderkey, + t9.o_custkey, + t9.o_orderstatus, + t9.o_totalprice, + t9.o_orderdate, + t9.o_orderpriority, + t9.o_clerk, + t9.o_shippriority, + t9.o_comment, + t9.l_orderkey, + t9.l_partkey, + t9.l_suppkey, + t9.l_linenumber, + t9.l_quantity, + t9.l_extendedprice, + t9.l_discount, + t9.l_tax, + t9.l_returnflag, + t9.l_linestatus, + t9.l_shipdate, + t9.l_commitdate, + t9.l_receiptdate, + t9.l_shipinstruct, + t9.l_shipmode, + t9.l_comment FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment, - t3.o_orderkey AS o_orderkey, - t3.o_custkey AS o_custkey, - t3.o_orderstatus AS o_orderstatus, - t3.o_totalprice AS o_totalprice, - t3.o_orderdate AS o_orderdate, - t3.o_orderpriority AS o_orderpriority, - t3.o_clerk AS o_clerk, - t3.o_shippriority AS o_shippriority, - t3.o_comment AS o_comment, - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment - FROM customer AS t0 - INNER JOIN orders AS t3 - ON t0.c_custkey = t3.o_custkey - INNER JOIN lineitem AS t4 - ON t3.o_orderkey = t4.l_orderkey - ) AS t8 + t3.c_custkey, + t3.c_name, + t3.c_address, + t3.c_nationkey, + t3.c_phone, + t3.c_acctbal, + t3.c_mktsegment, + t3.c_comment, + t4.o_orderkey, + t4.o_custkey, + t4.o_orderstatus, + t4.o_totalprice, + t4.o_orderdate, + t4.o_orderpriority, + t4.o_clerk, + t4.o_shippriority, + t4.o_comment, + t5.l_orderkey, + t5.l_partkey, + t5.l_suppkey, + t5.l_linenumber, + t5.l_quantity, + t5.l_extendedprice, + t5.l_discount, + t5.l_tax, + t5.l_returnflag, + t5.l_linestatus, + t5.l_shipdate, + t5.l_commitdate, + t5.l_receiptdate, + t5.l_shipinstruct, + t5.l_shipmode, + t5.l_comment + FROM customer AS t3 + INNER JOIN orders AS t4 + ON t3.c_custkey = t4.o_custkey + INNER JOIN lineitem AS t5 + ON t4.o_orderkey = t5.l_orderkey + ) AS t9 WHERE - t8.o_orderkey IN (( + t9.o_orderkey IN ( SELECT - t5.l_orderkey AS l_orderkey + t6.l_orderkey FROM ( SELECT - t2.l_orderkey AS l_orderkey, + t2.l_orderkey, SUM(t2.l_quantity) AS qty_sum FROM lineitem AS t2 GROUP BY 1 - ) AS t5 + ) AS t6 WHERE - t5.qty_sum > CAST(300 AS SMALLINT) - )) - ) AS t10 + t6.qty_sum > CAST(300 AS SMALLINT) + ) + ) AS t11 GROUP BY 1, 2, 3, 4, 5 -) AS t11 +) AS t12 ORDER BY - t11.o_totalprice DESC, - t11.o_orderdate ASC + t12.o_totalprice DESC, + t12.o_orderdate ASC LIMIT 100 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h19/test_tpc_h19/duckdb/h19.sql b/ibis/backends/tests/tpch/snapshots/test_h19/test_tpc_h19/duckdb/h19.sql index 288021f12b67a..29adca6df1be1 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h19/test_tpc_h19/duckdb/h19.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h19/test_tpc_h19/duckdb/h19.sql @@ -1,65 +1,65 @@ SELECT - SUM(t5.l_extendedprice * ( - CAST(1 AS TINYINT) - t5.l_discount + SUM(t6.l_extendedprice * ( + CAST(1 AS TINYINT) - t6.l_discount )) AS revenue FROM ( SELECT - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment, - t4.p_partkey AS p_partkey, - t4.p_name AS p_name, - t4.p_mfgr AS p_mfgr, - t4.p_brand AS p_brand, - t4.p_type AS p_type, - t4.p_size AS p_size, - t4.p_container AS p_container, - t4.p_retailprice AS p_retailprice, - t4.p_comment AS p_comment + t5.l_orderkey, + t5.l_partkey, + t5.l_suppkey, + t5.l_linenumber, + t5.l_quantity, + t5.l_extendedprice, + t5.l_discount, + t5.l_tax, + t5.l_returnflag, + t5.l_linestatus, + t5.l_shipdate, + t5.l_commitdate, + t5.l_receiptdate, + t5.l_shipinstruct, + t5.l_shipmode, + t5.l_comment, + t5.p_partkey, + t5.p_name, + t5.p_mfgr, + t5.p_brand, + t5.p_type, + t5.p_size, + t5.p_container, + t5.p_retailprice, + t5.p_comment FROM ( SELECT - t0.l_orderkey AS l_orderkey, - t0.l_partkey AS l_partkey, - t0.l_suppkey AS l_suppkey, - t0.l_linenumber AS l_linenumber, - t0.l_quantity AS l_quantity, - t0.l_extendedprice AS l_extendedprice, - t0.l_discount AS l_discount, - t0.l_tax AS l_tax, - t0.l_returnflag AS l_returnflag, - t0.l_linestatus AS l_linestatus, - t0.l_shipdate AS l_shipdate, - t0.l_commitdate AS l_commitdate, - t0.l_receiptdate AS l_receiptdate, - t0.l_shipinstruct AS l_shipinstruct, - t0.l_shipmode AS l_shipmode, - t0.l_comment AS l_comment, - t2.p_partkey AS p_partkey, - t2.p_name AS p_name, - t2.p_mfgr AS p_mfgr, - t2.p_brand AS p_brand, - t2.p_type AS p_type, - t2.p_size AS p_size, - t2.p_container AS p_container, - t2.p_retailprice AS p_retailprice, - t2.p_comment AS p_comment - FROM lineitem AS t0 - INNER JOIN part AS t2 - ON t2.p_partkey = t0.l_partkey - ) AS t4 + t2.l_orderkey, + t2.l_partkey, + t2.l_suppkey, + t2.l_linenumber, + t2.l_quantity, + t2.l_extendedprice, + t2.l_discount, + t2.l_tax, + t2.l_returnflag, + t2.l_linestatus, + t2.l_shipdate, + t2.l_commitdate, + t2.l_receiptdate, + t2.l_shipinstruct, + t2.l_shipmode, + t2.l_comment, + t3.p_partkey, + t3.p_name, + t3.p_mfgr, + t3.p_brand, + t3.p_type, + t3.p_size, + t3.p_container, + t3.p_retailprice, + t3.p_comment + FROM lineitem AS t2 + INNER JOIN part AS t3 + ON t3.p_partkey = t2.l_partkey + ) AS t5 WHERE ( ( @@ -69,24 +69,24 @@ FROM ( ( ( ( - t4.p_brand = 'Brand#12' + t5.p_brand = 'Brand#12' ) - AND t4.p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + AND t5.p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') ) AND ( - t4.l_quantity >= CAST(1 AS TINYINT) + t5.l_quantity >= CAST(1 AS TINYINT) ) ) AND ( - t4.l_quantity <= CAST(11 AS TINYINT) + t5.l_quantity <= CAST(11 AS TINYINT) ) ) - AND t4.p_size BETWEEN CAST(1 AS TINYINT) AND CAST(5 AS TINYINT) + AND t5.p_size BETWEEN CAST(1 AS TINYINT) AND CAST(5 AS TINYINT) ) - AND t4.l_shipmode IN ('AIR', 'AIR REG') + AND t5.l_shipmode IN ('AIR', 'AIR REG') ) AND ( - t4.l_shipinstruct = 'DELIVER IN PERSON' + t5.l_shipinstruct = 'DELIVER IN PERSON' ) ) OR ( @@ -96,24 +96,24 @@ FROM ( ( ( ( - t4.p_brand = 'Brand#23' + t5.p_brand = 'Brand#23' ) - AND t4.p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + AND t5.p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') ) AND ( - t4.l_quantity >= CAST(10 AS TINYINT) + t5.l_quantity >= CAST(10 AS TINYINT) ) ) AND ( - t4.l_quantity <= CAST(20 AS TINYINT) + t5.l_quantity <= CAST(20 AS TINYINT) ) ) - AND t4.p_size BETWEEN CAST(1 AS TINYINT) AND CAST(10 AS TINYINT) + AND t5.p_size BETWEEN CAST(1 AS TINYINT) AND CAST(10 AS TINYINT) ) - AND t4.l_shipmode IN ('AIR', 'AIR REG') + AND t5.l_shipmode IN ('AIR', 'AIR REG') ) AND ( - t4.l_shipinstruct = 'DELIVER IN PERSON' + t5.l_shipinstruct = 'DELIVER IN PERSON' ) ) ) @@ -124,24 +124,24 @@ FROM ( ( ( ( - t4.p_brand = 'Brand#34' + t5.p_brand = 'Brand#34' ) - AND t4.p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + AND t5.p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') ) AND ( - t4.l_quantity >= CAST(20 AS TINYINT) + t5.l_quantity >= CAST(20 AS TINYINT) ) ) AND ( - t4.l_quantity <= CAST(30 AS TINYINT) + t5.l_quantity <= CAST(30 AS TINYINT) ) ) - AND t4.p_size BETWEEN CAST(1 AS TINYINT) AND CAST(15 AS TINYINT) + AND t5.p_size BETWEEN CAST(1 AS TINYINT) AND CAST(15 AS TINYINT) ) - AND t4.l_shipmode IN ('AIR', 'AIR REG') + AND t5.l_shipmode IN ('AIR', 'AIR REG') ) AND ( - t4.l_shipinstruct = 'DELIVER IN PERSON' + t5.l_shipinstruct = 'DELIVER IN PERSON' ) ) -) AS t5 \ No newline at end of file +) AS t6 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h20/test_tpc_h20/duckdb/h20.sql b/ibis/backends/tests/tpch/snapshots/test_h20/test_tpc_h20/duckdb/h20.sql index ad8d1c7fb6186..111f26421e9a3 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h20/test_tpc_h20/duckdb/h20.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h20/test_tpc_h20/duckdb/h20.sql @@ -1,68 +1,68 @@ SELECT - t9.s_name AS s_name, - t9.s_address AS s_address + t10.s_name, + t10.s_address FROM ( SELECT - t0.s_suppkey AS s_suppkey, - t0.s_name AS s_name, - t0.s_address AS s_address, - t0.s_nationkey AS s_nationkey, - t0.s_phone AS s_phone, - t0.s_acctbal AS s_acctbal, - t0.s_comment AS s_comment, - t5.n_nationkey AS n_nationkey, - t5.n_name AS n_name, - t5.n_regionkey AS n_regionkey, - t5.n_comment AS n_comment - FROM supplier AS t0 - INNER JOIN nation AS t5 - ON t0.s_nationkey = t5.n_nationkey -) AS t9 + t5.s_suppkey, + t5.s_name, + t5.s_address, + t5.s_nationkey, + t5.s_phone, + t5.s_acctbal, + t5.s_comment, + t6.n_nationkey, + t6.n_name, + t6.n_regionkey, + t6.n_comment + FROM supplier AS t5 + INNER JOIN nation AS t6 + ON t5.s_nationkey = t6.n_nationkey +) AS t10 WHERE - t9.n_name = 'CANADA' - AND t9.s_suppkey IN (( + t10.n_name = 'CANADA' + AND t10.s_suppkey IN ( SELECT - t1.ps_suppkey AS ps_suppkey + t1.ps_suppkey FROM partsupp AS t1 WHERE - t1.ps_partkey IN (( + t1.ps_partkey IN ( SELECT - t3.p_partkey AS p_partkey + t3.p_partkey FROM part AS t3 WHERE t3.p_name LIKE 'forest%' - )) + ) AND t1.ps_availqty > ( ( SELECT - SUM(t7.l_quantity) AS "Sum(l_quantity)" + SUM(t8.l_quantity) AS "Sum(l_quantity)" FROM ( SELECT - t4.l_orderkey AS l_orderkey, - t4.l_partkey AS l_partkey, - t4.l_suppkey AS l_suppkey, - t4.l_linenumber AS l_linenumber, - t4.l_quantity AS l_quantity, - t4.l_extendedprice AS l_extendedprice, - t4.l_discount AS l_discount, - t4.l_tax AS l_tax, - t4.l_returnflag AS l_returnflag, - t4.l_linestatus AS l_linestatus, - t4.l_shipdate AS l_shipdate, - t4.l_commitdate AS l_commitdate, - t4.l_receiptdate AS l_receiptdate, - t4.l_shipinstruct AS l_shipinstruct, - t4.l_shipmode AS l_shipmode, - t4.l_comment AS l_comment + t4.l_orderkey, + t4.l_partkey, + t4.l_suppkey, + t4.l_linenumber, + t4.l_quantity, + t4.l_extendedprice, + t4.l_discount, + t4.l_tax, + t4.l_returnflag, + t4.l_linestatus, + t4.l_shipdate, + t4.l_commitdate, + t4.l_receiptdate, + t4.l_shipinstruct, + t4.l_shipmode, + t4.l_comment FROM lineitem AS t4 WHERE t4.l_partkey = t1.ps_partkey AND t4.l_suppkey = t1.ps_suppkey AND t4.l_shipdate >= MAKE_DATE(1994, 1, 1) AND t4.l_shipdate < MAKE_DATE(1995, 1, 1) - ) AS t7 + ) AS t8 ) * CAST(0.5 AS DOUBLE) ) - )) + ) ORDER BY - t9.s_name ASC \ No newline at end of file + t10.s_name ASC \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h21/test_tpc_h21/duckdb/h21.sql b/ibis/backends/tests/tpch/snapshots/test_h21/test_tpc_h21/duckdb/h21.sql index 282d2c3c05e27..72dd9ea9697bb 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h21/test_tpc_h21/duckdb/h21.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h21/test_tpc_h21/duckdb/h21.sql @@ -1,78 +1,74 @@ SELECT - t16.s_name AS s_name, - t16.numwait AS numwait + t17.s_name, + t17.numwait FROM ( SELECT - t15.s_name AS s_name, + t16.s_name, COUNT(*) AS numwait FROM ( SELECT - t12.l1_orderkey AS l1_orderkey, - t12.o_orderstatus AS o_orderstatus, - t12.l_receiptdate AS l_receiptdate, - t12.l_commitdate AS l_commitdate, - t12.l1_suppkey AS l1_suppkey, - t12.s_name AS s_name, - t12.n_name AS n_name + t13.l1_orderkey, + t13.o_orderstatus, + t13.l_receiptdate, + t13.l_commitdate, + t13.l1_suppkey, + t13.s_name, + t13.n_name FROM ( SELECT - t4.l_orderkey AS l1_orderkey, - t7.o_orderstatus AS o_orderstatus, - t4.l_receiptdate AS l_receiptdate, - t4.l_commitdate AS l_commitdate, - t4.l_suppkey AS l1_suppkey, - t0.s_name AS s_name, - t8.n_name AS n_name - FROM supplier AS t0 - INNER JOIN lineitem AS t4 - ON t0.s_suppkey = t4.l_suppkey - INNER JOIN orders AS t7 - ON t7.o_orderkey = t4.l_orderkey - INNER JOIN nation AS t8 - ON t0.s_nationkey = t8.n_nationkey - ) AS t12 + t5.l_orderkey AS l1_orderkey, + t8.o_orderstatus, + t5.l_receiptdate, + t5.l_commitdate, + t5.l_suppkey AS l1_suppkey, + t4.s_name, + t9.n_name + FROM supplier AS t4 + INNER JOIN lineitem AS t5 + ON t4.s_suppkey = t5.l_suppkey + INNER JOIN orders AS t8 + ON t8.o_orderkey = t5.l_orderkey + INNER JOIN nation AS t9 + ON t4.s_nationkey = t9.n_nationkey + ) AS t13 WHERE - t12.o_orderstatus = 'F' - AND t12.l_receiptdate > t12.l_commitdate - AND t12.n_name = 'SAUDI ARABIA' + t13.o_orderstatus = 'F' + AND t13.l_receiptdate > t13.l_commitdate + AND t13.n_name = 'SAUDI ARABIA' AND EXISTS( - ( + SELECT + CAST(1 AS TINYINT) AS "1" + FROM lineitem AS t6 + WHERE + ( + t6.l_orderkey = t13.l1_orderkey + ) AND ( + t6.l_suppkey <> t13.l1_suppkey + ) + ) + AND NOT ( + EXISTS( SELECT CAST(1 AS TINYINT) AS "1" - FROM lineitem AS t5 + FROM lineitem AS t7 WHERE ( - t5.l_orderkey = t12.l1_orderkey - ) AND ( - t5.l_suppkey <> t12.l1_suppkey - ) - ) - ) - AND NOT ( - EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM lineitem AS t6 - WHERE ( - ( - t6.l_orderkey = t12.l1_orderkey - ) AND ( - t6.l_suppkey <> t12.l1_suppkey - ) - ) - AND ( - t6.l_receiptdate > t6.l_commitdate + t7.l_orderkey = t13.l1_orderkey + ) AND ( + t7.l_suppkey <> t13.l1_suppkey ) - ) + ) + AND ( + t7.l_receiptdate > t7.l_commitdate + ) ) ) - ) AS t15 + ) AS t16 GROUP BY 1 -) AS t16 +) AS t17 ORDER BY - t16.numwait DESC, - t16.s_name ASC + t17.numwait DESC, + t17.s_name ASC LIMIT 100 \ No newline at end of file diff --git a/ibis/backends/tests/tpch/snapshots/test_h22/test_tpc_h22/duckdb/h22.sql b/ibis/backends/tests/tpch/snapshots/test_h22/test_tpc_h22/duckdb/h22.sql index 2d821d39eca3f..323185ab0e0df 100644 --- a/ibis/backends/tests/tpch/snapshots/test_h22/test_tpc_h22/duckdb/h22.sql +++ b/ibis/backends/tests/tpch/snapshots/test_h22/test_tpc_h22/duckdb/h22.sql @@ -1,10 +1,10 @@ SELECT - t6.cntrycode AS cntrycode, - t6.numcust AS numcust, - t6.totacctbal AS totacctbal + t6.cntrycode, + t6.numcust, + t6.totacctbal FROM ( SELECT - t5.cntrycode AS cntrycode, + t5.cntrycode, COUNT(*) AS numcust, SUM(t5.c_acctbal) AS totacctbal FROM ( @@ -14,7 +14,7 @@ FROM ( THEN SUBSTRING(t0.c_phone, CAST(0 AS TINYINT) + 1, CAST(2 AS TINYINT)) ELSE SUBSTRING(t0.c_phone, CAST(0 AS TINYINT), CAST(2 AS TINYINT)) END AS cntrycode, - t0.c_acctbal AS c_acctbal + t0.c_acctbal FROM customer AS t0 WHERE CASE @@ -27,14 +27,14 @@ FROM ( AVG(t3.c_acctbal) AS "Mean(c_acctbal)" FROM ( SELECT - t0.c_custkey AS c_custkey, - t0.c_name AS c_name, - t0.c_address AS c_address, - t0.c_nationkey AS c_nationkey, - t0.c_phone AS c_phone, - t0.c_acctbal AS c_acctbal, - t0.c_mktsegment AS c_mktsegment, - t0.c_comment AS c_comment + t0.c_custkey, + t0.c_name, + t0.c_address, + t0.c_nationkey, + t0.c_phone, + t0.c_acctbal, + t0.c_mktsegment, + t0.c_comment FROM customer AS t0 WHERE t0.c_acctbal > CAST(0.0 AS DOUBLE) @@ -47,13 +47,11 @@ FROM ( ) AND NOT ( EXISTS( - ( - SELECT - CAST(1 AS TINYINT) AS "1" - FROM orders AS t1 - WHERE - t1.o_custkey = t0.c_custkey - ) + SELECT + CAST(1 AS TINYINT) AS "1" + FROM orders AS t1 + WHERE + t1.o_custkey = t0.c_custkey ) ) ) AS t5 diff --git a/ibis/backends/tests/tpch/test_h08.py b/ibis/backends/tests/tpch/test_h08.py index 971a83c4c3526..3ab657c3bec71 100644 --- a/ibis/backends/tests/tpch/test_h08.py +++ b/ibis/backends/tests/tpch/test_h08.py @@ -8,6 +8,11 @@ @tpch_test +@pytest.mark.notimpl( + ["snowflake"], + raises=AssertionError, + reason="ibis doesn't preserve decimal types in aggregations", +) @pytest.mark.xfail_version( trino=["sqlalchemy>=2"], reason="slightly different code is generated for sqlalchemy 2 for aggregations", diff --git a/ibis/backends/tests/tpch/test_h11.py b/ibis/backends/tests/tpch/test_h11.py index e13ba99179f98..75439d06c8ce4 100644 --- a/ibis/backends/tests/tpch/test_h11.py +++ b/ibis/backends/tests/tpch/test_h11.py @@ -1,11 +1,18 @@ from __future__ import annotations +import pytest + import ibis from .conftest import tpch_test @tpch_test +@pytest.mark.broken( + ["snowflake"], + reason="ibis generates incorrect code for the right-hand-side of the exists statement", + raises=AssertionError, +) def test_tpc_h11(partsupp, supplier, nation): NATION = "GERMANY" FRACTION = 0.0001 diff --git a/ibis/backends/tests/tpch/test_h14.py b/ibis/backends/tests/tpch/test_h14.py index f72bbcaf6c2b6..cb57d99115771 100644 --- a/ibis/backends/tests/tpch/test_h14.py +++ b/ibis/backends/tests/tpch/test_h14.py @@ -8,6 +8,11 @@ @tpch_test +@pytest.mark.notimpl( + ["snowflake"], + raises=AssertionError, + reason="ibis doesn't preserve decimal types in aggregations", +) @pytest.mark.xfail_version( trino=["sqlalchemy>=2"], reason="slightly different code is generated for sqlalchemy 2 for aggregations", diff --git a/ibis/backends/tests/tpch/test_h17.py b/ibis/backends/tests/tpch/test_h17.py index 0d112d048c910..fbe50eb78f7e5 100644 --- a/ibis/backends/tests/tpch/test_h17.py +++ b/ibis/backends/tests/tpch/test_h17.py @@ -6,6 +6,11 @@ @tpch_test +@pytest.mark.notimpl( + ["snowflake"], + raises=AssertionError, + reason="ibis doesn't preserve decimal types in aggregations", +) @pytest.mark.xfail_version( trino=["sqlalchemy>=2"], reason="slightly different code is generated for sqlalchemy 2 for aggregations", diff --git a/ibis/backends/tests/tpch/test_h21.py b/ibis/backends/tests/tpch/test_h21.py index 487b574bb615a..f8aea4314c81a 100644 --- a/ibis/backends/tests/tpch/test_h21.py +++ b/ibis/backends/tests/tpch/test_h21.py @@ -1,11 +1,19 @@ from __future__ import annotations +import pytest +import sqlalchemy as sa + import ibis from .conftest import tpch_test @tpch_test +@pytest.mark.broken( + ["snowflake"], + reason="ibis generates overlapping aliases", + raises=sa.exc.CompileError, +) def test_tpc_h21(supplier, lineitem, orders, nation): """Suppliers Who Kept Orders Waiting Query (Q21) diff --git a/ibis/backends/tests/tpch/test_h22.py b/ibis/backends/tests/tpch/test_h22.py index d505436c4927c..f18da1d2930bf 100644 --- a/ibis/backends/tests/tpch/test_h22.py +++ b/ibis/backends/tests/tpch/test_h22.py @@ -1,9 +1,16 @@ from __future__ import annotations +import pytest + from .conftest import tpch_test @tpch_test +@pytest.mark.broken( + ["snowflake"], + reason="ibis generates incorrect code for the right-hand-side of the exists statement", + raises=AssertionError, +) def test_tpc_h22(customer, orders): """Global Sales Opportunity Query (Q22) diff --git a/ibis/examples/tests/test_examples.py b/ibis/examples/tests/test_examples.py index b17da0ed32273..c9d0b9567dc47 100644 --- a/ibis/examples/tests/test_examples.py +++ b/ibis/examples/tests/test_examples.py @@ -11,7 +11,6 @@ pytestmark = pytest.mark.examples duckdb = pytest.importorskip("duckdb") -pytest.importorskip("pins") # large files or files that are used elsewhere ignored = frozenset( @@ -95,27 +94,3 @@ def test_table_name_arg(): name = f"penguins-{uuid.uuid4().hex}" t = ibis.examples.penguins.fetch(backend=con, table_name=name) assert t.get_name() == name - - -@pytest.mark.pandas -@pytest.mark.duckdb -@pytest.mark.backend -@skip_linux_nix -@pytest.mark.parametrize( - ("example", "columns"), - [ - ("ml_latest_small_links", ["movieId", "imdbId", "tmdbId"]), - ("band_instruments", ["name", "plays"]), - ( - "AwardsManagers", - ["player_id", "award_id", "year_id", "lg_id", "tie", "notes"], - ), - ], - ids=["parquet", "csv", "csv-all-null"], -) -@pytest.mark.parametrize("backend_name", ["duckdb", "polars", "pandas"]) -def test_load_example(backend_name, example, columns): - pytest.importorskip(backend_name) - con = getattr(ibis, backend_name).connect() - t = getattr(ibis.examples, example).fetch(backend=con) - assert t.columns == columns diff --git a/ibis/expr/decompile.py b/ibis/expr/decompile.py index 3b27c166852aa..6c96648b0ff9c 100644 --- a/ibis/expr/decompile.py +++ b/ibis/expr/decompile.py @@ -132,7 +132,10 @@ def _wrap_alias(values, rendered): for k, v in values.items(): text = rendered[k] if v.name != k: - text = f"{text}.name({k!r})" + if isinstance(v, ops.Binary): + text = f"({text}).name({k!r})" + else: + text = f"{text}.name({k!r})" result.append(text) return result @@ -189,6 +192,11 @@ def self_reference(op, parent, identifier): return f"{parent}.view()" +@translate.register(ops.Distinct) +def distinct(op, parent): + return f"{parent}.distinct()" + + @translate.register(ops.JoinTable) def join_table(op, parent, index): return parent @@ -202,7 +210,12 @@ def join_link(op, table, predicates, how): @translate.register(ops.JoinChain) def join(op, first, rest, values): calls = "".join(rest) - return f"{first}{calls}" + pieces = [f"{first}{calls}"] + if values: + values = _wrap_alias(op.values, values) + pieces.append(f"select({_inline(values)})") + result = ".".join(pieces) + return result @translate.register(ops.Set) @@ -224,7 +237,9 @@ def limit(op, parent, n, offset): @translate.register(ops.Field) def table_column(op, rel, name): - return f"{rel}.{name}" + if name.isidentifier(): + return f"{rel}.{name}" + return f"{rel}[{name!r}]" @translate.register(ops.SortKey) @@ -337,10 +352,11 @@ def isin(op, value, options): class CodeContext: always_assign = ( ops.ScalarParameter, - ops.UnboundTable, ops.Aggregate, + ops.PhysicalTable, ops.SelfReference, ) + always_ignore = ( ops.JoinTable, ops.Field, diff --git a/ibis/expr/operations/relations.py b/ibis/expr/operations/relations.py index a4c37ce2912bf..5ab1ee37c5952 100644 --- a/ibis/expr/operations/relations.py +++ b/ibis/expr/operations/relations.py @@ -20,7 +20,6 @@ from ibis.expr.operations.sortkeys import SortKey # noqa: TCH001 from ibis.expr.schema import Schema from ibis.formats import TableProxy # noqa: TCH001 -from ibis.util import gen_name T = TypeVar("T") @@ -111,13 +110,10 @@ def __init__(self, rel, **kwargs): ) super().__init__(rel=rel, **kwargs) - @attribute - def name(self): - return self.rel.schema.names[0] - @attribute def value(self): - return self.rel.values[self.name] + name = self.rel.schema.names[0] + return self.rel.values[name] @attribute def relations(self): @@ -208,12 +204,6 @@ def __init__(self, parent, identifier): identifier = next(self._uid_counter) super().__init__(parent=parent, identifier=identifier) - @attribute - def name(self) -> str: - if (name := getattr(self.parent, "name", None)) is not None: - return f"{name}_ref" - return gen_name("self_ref") - JoinKind = Literal[ "inner", @@ -427,6 +417,18 @@ def schema(self): return backend._get_schema_using_query(self.query) +@public +class View(PhysicalTable): + """A view created from an expression.""" + + child: Relation + name: str + + @attribute + def schema(self): + return self.child.schema + + @public class DummyTable(Relation): values: FrozenDict[str, Value] diff --git a/ibis/expr/rewrites.py b/ibis/expr/rewrites.py index 12a314379d9af..5cac1708e89b5 100644 --- a/ibis/expr/rewrites.py +++ b/ibis/expr/rewrites.py @@ -1,8 +1,13 @@ """Some common rewrite functions to be shared between backends.""" from __future__ import annotations +import functools +from collections.abc import Mapping + import toolz +import ibis.common.exceptions as com +import ibis.expr.datatypes as dt import ibis.expr.operations as ops from ibis.common.deferred import Item, _, deferred, var from ibis.common.exceptions import ExpressionError @@ -22,6 +27,85 @@ def peel_join_field(_): return _.rel.values[_.name] +@replace(p.Alias(p.ScalarParameter)) +def unwrap_scalar_parameter(_): + """Replace aliased scalar parameters with the parameter itself.""" + return _.arg + + +def replace_scalar_parameter(params): + """Replace scalar parameters with their values.""" + + @replace(p.ScalarParameter) + def repl(_): + return ops.Literal(value=params[_], dtype=_.dtype) + + return repl + + +@replace(p.FillNa) +def rewrite_fillna(_): + """Rewrite FillNa expressions to use more common operations.""" + if isinstance(_.replacements, Mapping): + mapping = _.replacements + else: + mapping = { + name: _.replacements + for name, type in _.parent.schema.items() + if type.nullable + } + + if not mapping: + return _.parent + + selections = [] + for name in _.parent.schema.names: + col = ops.TableColumn(_.parent, name) + if (value := mapping.get(name)) is not None: + col = ops.Alias(ops.Coalesce((col, value)), name) + selections.append(col) + + return ops.Project(_.parent, selections) + + +@replace(p.DropNa) +def rewrite_dropna(_): + """Rewrite DropNa expressions to use more common operations.""" + if _.subset is None: + columns = [ops.TableColumn(_.parent, name) for name in _.parent.schema.names] + else: + columns = _.subset + + if columns: + preds = [ + functools.reduce( + ops.And if _.how == "any" else ops.Or, + [ops.NotNull(c) for c in columns], + ) + ] + elif _.how == "all": + preds = [ops.Literal(False, dtype=dt.bool)] + else: + return _.parent + + return ops.Filter(_.parent, tuple(preds)) + + +@replace(p.Sample) +def rewrite_sample(_): + """Rewrite Sample as `t.filter(random() <= fraction)`. + + Errors as unsupported if a `seed` is specified. + """ + + if _.seed is not None: + raise com.UnsupportedOperationError( + "`Table.sample` with a random seed is unsupported" + ) + + return ops.Filter(_.parent, (ops.LessEqual(ops.RandomScalar(), _.fraction),)) + + @replace(ops.Analytic) def project_wrap_analytic(_, rel): # Wrap analytic functions in a window function @@ -118,6 +202,43 @@ def rewrite_window_input(value, frame): return node.replace(window_merge_frames, filter=p.Value, context=context) +@replace(p.InValues(..., ())) +def empty_in_values_right_side(_): + """Replace checks against an empty right side with `False`.""" + return ops.Literal(False, dtype=dt.bool) + + +@replace( + p.WindowFunction( + p.PercentRank(y) | p.RankBase(y) | p.CumeDist(y) | p.NTile(y), + p.WindowFrame(..., order_by=()) >> _.copy(order_by=(y,)), + ) +) +def add_order_by_to_empty_ranking_window_functions(_): + """Add an ORDER BY clause to rank window functions that don't have one.""" + return _ + + +@replace( + p.WindowFunction(p.RankBase | p.NTile) + | p.StringFind + | p.FindInSet + | p.ArrayPosition +) +def one_to_zero_index(_, **__): + """Subtract one from one-index functions.""" + return ops.Subtract(_, 1) + + +@replace(ops.NthValue) +def add_one_to_nth_value_input(_, **__): + if isinstance(_.nth, ops.Literal): + nth = ops.Literal(_.nth.value + 1, dtype=_.nth.dtype) + else: + nth = ops.Add(_.nth, 1) + return _.copy(nth=nth) + + # TODO(kszucs): schema comparison should be updated to not distinguish between # different column order @replace(p.Project(y @ p.Relation) & Check(_.schema == y.schema)) diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_aggregation_with_multiple_joins/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_aggregation_with_multiple_joins/decompiled.py index 499385aab5148..3797511126194 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_aggregation_with_multiple_joins/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_aggregation_with_multiple_joins/decompiled.py @@ -18,8 +18,21 @@ call_outcome = ibis.table( name="call_outcome", schema={"outcome_text": "string", "id": "int64"} ) -joinchain = employee.inner_join(call, employee.id == call.employee_id).inner_join( - call_outcome, call.call_outcome_id == call_outcome.id +joinchain = ( + employee.inner_join(call, employee.id == call.employee_id) + .inner_join(call_outcome, call.call_outcome_id == call_outcome.id) + .select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, + call_outcome.outcome_text, + call_outcome.id.name("id_right"), + ) ) result = joinchain.aggregate( diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_aggregation_with_join/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_aggregation_with_join/decompiled.py index 0b23d16874458..42fdcbfec8e70 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_aggregation_with_join/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_aggregation_with_join/decompiled.py @@ -15,7 +15,16 @@ "call_attempts": "int64", }, ) -joinchain = employee.left_join(call, employee.id == call.employee_id) +joinchain = employee.left_join(call, employee.id == call.employee_id).select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, +) result = joinchain.aggregate( [joinchain.call_attempts.sum().name("attempts")], by=[joinchain.id] diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/inner/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/inner/decompiled.py index 8439fd762875c..290fddcfd9d3d 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/inner/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/inner/decompiled.py @@ -15,7 +15,16 @@ "call_attempts": "int64", }, ) -joinchain = employee.inner_join(call, employee.id == call.employee_id) +joinchain = employee.inner_join(call, employee.id == call.employee_id).select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, +) f = joinchain.filter(joinchain.id < 5) s = f.order_by(f.id.desc()) diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/left/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/left/decompiled.py index 3e375cd052d29..4b3a6f52c08b5 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/left/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/left/decompiled.py @@ -15,7 +15,16 @@ "call_attempts": "int64", }, ) -joinchain = employee.left_join(call, employee.id == call.employee_id) +joinchain = employee.left_join(call, employee.id == call.employee_id).select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, +) f = joinchain.filter(joinchain.id < 5) s = f.order_by(f.id.desc()) diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/right/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/right/decompiled.py index e9a8b2082dc1f..f7f22e528a2ad 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/right/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_basic_join/right/decompiled.py @@ -15,7 +15,16 @@ "call_attempts": "int64", }, ) -joinchain = employee.right_join(call, employee.id == call.employee_id) +joinchain = employee.right_join(call, employee.id == call.employee_id).select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, +) f = joinchain.filter(joinchain.id < 5) s = f.order_by(f.id.desc()) diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_join_with_filter/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_join_with_filter/decompiled.py index 3e375cd052d29..4b3a6f52c08b5 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_join_with_filter/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_join_with_filter/decompiled.py @@ -15,7 +15,16 @@ "call_attempts": "int64", }, ) -joinchain = employee.left_join(call, employee.id == call.employee_id) +joinchain = employee.left_join(call, employee.id == call.employee_id).select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, +) f = joinchain.filter(joinchain.id < 5) s = f.order_by(f.id.desc()) diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_multiple_joins/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_multiple_joins/decompiled.py index d6df17717b272..68a7ecaed1368 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_multiple_joins/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_multiple_joins/decompiled.py @@ -19,6 +19,19 @@ name="call_outcome", schema={"outcome_text": "string", "id": "int64"} ) -result = employee.inner_join(call, employee.id == call.employee_id).inner_join( - call_outcome, call.call_outcome_id == call_outcome.id +result = ( + employee.inner_join(call, employee.id == call.employee_id) + .inner_join(call_outcome, call.call_outcome_id == call_outcome.id) + .select( + employee.first_name, + employee.last_name, + employee.id, + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, + call_outcome.outcome_text, + call_outcome.id.name("id_right"), + ) ) diff --git a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_scalar_subquery/decompiled.py b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_scalar_subquery/decompiled.py index f73ace43c0d8b..6080950c3d24e 100644 --- a/ibis/expr/tests/snapshots/test_sql/test_parse_sql_scalar_subquery/decompiled.py +++ b/ibis/expr/tests/snapshots/test_sql/test_parse_sql_scalar_subquery/decompiled.py @@ -13,4 +13,13 @@ ) agg = call.aggregate([call.call_attempts.mean().name("mean")]) -result = call.inner_join(agg, [call.call_attempts > agg.mean, ibis.literal(True)]) +result = call.inner_join( + agg, [agg.mean < call.call_attempts, ibis.literal(True)] +).select( + call.start_time, + call.end_time, + call.employee_id, + call.call_outcome_id, + call.call_attempts, + agg.mean, +) diff --git a/ibis/expr/types/joins.py b/ibis/expr/types/joins.py index 4afaca2889800..0b2aa972e948f 100644 --- a/ibis/expr/types/joins.py +++ b/ibis/expr/types/joins.py @@ -185,6 +185,11 @@ def join( ) preds = flatten_predicates(list(preds)) + # if there are no predicates, default to every row matching unless the + # join is a cross join, because a cross join already has this behavior + if not preds and how != "cross": + preds.append(ops.Literal(True, dtype="bool")) + # calculate the fields based in lname and rname, this should be a best # effort to avoid collisions, but does not raise if there are any # if no disambiaution happens using a final .select() call, then diff --git a/ibis/formats/pandas.py b/ibis/formats/pandas.py index 7fa0e4f37137c..7dc7f92adf113 100644 --- a/ibis/formats/pandas.py +++ b/ibis/formats/pandas.py @@ -3,6 +3,7 @@ import contextlib import datetime import warnings +from importlib.util import find_spec as _find_spec import numpy as np import pandas as pd @@ -24,6 +25,8 @@ "Install pandas >= 1.5.0 for interop with pandas and arrow dtype support" ) +geospatial_supported = _find_spec("geopandas") is not None + class PandasType(NumpyType): @classmethod @@ -118,6 +121,23 @@ def convert_table(cls, df, schema): # return data with the schema's columns which may be different than the # input columns df.columns = schema.names + + if geospatial_supported: + from geopandas import GeoDataFrame + from geopandas.array import GeometryDtype + + if ( + # pluck out the first geometry column if it exists + geom := next( + ( + name + for name, c in df.items() + if isinstance(c.dtype, GeometryDtype) + ), + None, + ) + ) is not None: + return GeoDataFrame(df, geometry=geom) return df @classmethod @@ -141,7 +161,11 @@ def convert_scalar(cls, obj, dtype): @classmethod def convert_GeoSpatial(cls, s, dtype, pandas_type): - return s + import geopandas as gpd + + if isinstance(s.dtype, gpd.array.GeometryDtype): + return gpd.GeoSeries(s) + return gpd.GeoSeries.from_wkb(s) convert_Point = ( convert_LineString diff --git a/ibis/tests/expr/mocks.py b/ibis/tests/expr/mocks.py index cfb7e7e4aa5cf..bab44651beef5 100644 --- a/ibis/tests/expr/mocks.py +++ b/ibis/tests/expr/mocks.py @@ -47,6 +47,11 @@ def list_tables(self): def list_databases(self): return ["mockdb"] + def _to_sql(self, expr, **kwargs): + import ibis + + return ibis.to_sql(expr, dialect="duckdb", **kwargs) + def fetch_from_cursor(self, cursor, schema): pass diff --git a/ibis/tests/util.py b/ibis/tests/util.py index f51dfca04ab71..47df8e59ebf92 100644 --- a/ibis/tests/util.py +++ b/ibis/tests/util.py @@ -30,7 +30,9 @@ def assert_pickle_roundtrip(obj): def schemas_eq(left: ir.Expr, right: ir.Expr) -> bool: - assert left.as_table().schema().equals(right.as_table().schema()) + left_schema = left.as_table().schema() + right_schema = right.as_table().schema() + return left_schema == right_schema def assert_decompile_roundtrip( diff --git a/pyproject.toml b/pyproject.toml index 52cba96bf84f8..739a7473fa85e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,6 @@ datafusion = { version = ">=0.6,<34", optional = true } db-dtypes = { version = ">=0.3,<2", optional = true } deltalake = { version = ">=0.9.0,<1", optional = true } duckdb = { version = ">=0.8.1,<1", optional = true } -duckdb-engine = { version = ">=0.1.8,<1", optional = true } geoalchemy2 = { version = ">=0.6.3,<1", optional = true } geopandas = { version = ">=0.6,<1", optional = true } google-cloud-bigquery = { version = ">=3,<4", optional = true } @@ -155,7 +154,6 @@ all = [ "datafusion", "db-dtypes", "duckdb", - "duckdb-engine", "deltalake", "geoalchemy2", "geopandas", @@ -187,11 +185,11 @@ bigquery = [ "google-cloud-bigquery-storage", "pydata-google-auth", ] -clickhouse = ["clickhouse-connect", "sqlalchemy"] +clickhouse = ["clickhouse-connect"] dask = ["dask", "regex"] datafusion = ["datafusion"] druid = ["pydruid", "sqlalchemy"] -duckdb = ["duckdb", "duckdb-engine", "sqlalchemy", "sqlalchemy-views"] +duckdb = ["duckdb"] exasol = ["sqlalchemy", "sqlalchemy-exasol", "sqlalchemy-views"] flink = [] geospatial = ["geoalchemy2", "geopandas", "shapely"] @@ -295,9 +293,6 @@ filterwarnings = [ 'ignore:`np\.bool` is a deprecated alias for the builtin `bool`:DeprecationWarning', # numpy, coming from a pandas call 'ignore:In the future `np\.bool` will be defined as the corresponding NumPy scalar:FutureWarning', - # duckdb-engine - 'ignore:Dialect .+ does \*not\* support Decimal:', - "ignore:duckdb-engine doesn't yet support reflection on indices:", # druid 'ignore:Dialect druid.rest will not make use of SQL compilation caching:', # ibis