mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-23 22:49:58 +00:00
Compare commits
83 Commits
v1.0.0-bet
...
feature/df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef80503454 | ||
|
|
69f0249039 | ||
|
|
1f91422bae | ||
|
|
377373b8fd | ||
|
|
e107030d85 | ||
|
|
18875eed4d | ||
|
|
ee76d50569 | ||
|
|
5d634aeba0 | ||
|
|
8346acb900 | ||
|
|
fdab75ce27 | ||
|
|
4c07d2d5de | ||
|
|
020477994b | ||
|
|
afefc0c604 | ||
|
|
e44323c433 | ||
|
|
0aeaf405c7 | ||
|
|
b5cbc35a0d | ||
|
|
5472bdfc0f | ||
|
|
6485a26fa3 | ||
|
|
69865c831d | ||
|
|
713525797a | ||
|
|
09d1074e23 | ||
|
|
1ebd25adbb | ||
|
|
c66f661494 | ||
|
|
2783a5218e | ||
|
|
6b6d1ce7c4 | ||
|
|
7e4f0af065 | ||
|
|
d811c4f060 | ||
|
|
be3c26f2b8 | ||
|
|
9eb44071b1 | ||
|
|
77e507cbe8 | ||
|
|
5bf72ab327 | ||
|
|
9f4902b10a | ||
|
|
b32ca3ad86 | ||
|
|
d180cc8f4b | ||
|
|
b099abc3a3 | ||
|
|
52a576cf6d | ||
|
|
c0d0b99a32 | ||
|
|
7d575d18ee | ||
|
|
ff99bce37c | ||
|
|
2f447e6f91 | ||
|
|
c9a7b1fd68 | ||
|
|
8c3da5e81f | ||
|
|
c152a45d44 | ||
|
|
c054c13e48 | ||
|
|
4a7c16586b | ||
|
|
c5173fccfc | ||
|
|
c02754b44c | ||
|
|
0b4f00feef | ||
|
|
c13febe35d | ||
|
|
29d23e0ba1 | ||
|
|
25fab2ba7d | ||
|
|
ec8263b464 | ||
|
|
01ea7e1468 | ||
|
|
7f1da17150 | ||
|
|
0cee4fa115 | ||
|
|
e59612043d | ||
|
|
5d8819e7af | ||
|
|
8b7b5c17c7 | ||
|
|
ee35ec0a39 | ||
|
|
605f3270e5 | ||
|
|
4e9f419de7 | ||
|
|
29bbff3c90 | ||
|
|
ff2a12a49d | ||
|
|
77483ad7d4 | ||
|
|
6adc348fcd | ||
|
|
cc61af7c65 | ||
|
|
1eb8d6b76b | ||
|
|
6c93c7d299 | ||
|
|
cdf9d18c36 | ||
|
|
32168e8ca8 | ||
|
|
de9ae6066f | ||
|
|
2bbc4bc4bc | ||
|
|
b1525e566b | ||
|
|
df954b47d5 | ||
|
|
acfd674332 | ||
|
|
e7928aaeee | ||
|
|
d5f52013ec | ||
|
|
c1e762960a | ||
|
|
7cc0439cc9 | ||
|
|
6eb7efcb76 | ||
|
|
5d0e94bfa8 | ||
|
|
e842d401fb | ||
|
|
30ca2d7652 |
22
.github/CODEOWNERS
vendored
22
.github/CODEOWNERS
vendored
@@ -5,23 +5,23 @@
|
|||||||
* @GreptimeTeam/db-approver
|
* @GreptimeTeam/db-approver
|
||||||
|
|
||||||
## [Module] Database Engine
|
## [Module] Database Engine
|
||||||
/src/index @zhongzc
|
/src/index @evenyag @discord9 @WenyXu
|
||||||
/src/mito2 @evenyag @v0y4g3r @waynexia
|
/src/mito2 @evenyag @v0y4g3r @waynexia
|
||||||
/src/query @evenyag
|
/src/query @evenyag @waynexia @discord9
|
||||||
|
|
||||||
## [Module] Distributed
|
## [Module] Distributed
|
||||||
/src/common/meta @MichaelScofield
|
/src/common/meta @MichaelScofield @WenyXu
|
||||||
/src/common/procedure @MichaelScofield
|
/src/common/procedure @MichaelScofield @WenyXu
|
||||||
/src/meta-client @MichaelScofield
|
/src/meta-client @MichaelScofield @WenyXu
|
||||||
/src/meta-srv @MichaelScofield
|
/src/meta-srv @MichaelScofield @WenyXu
|
||||||
|
|
||||||
## [Module] Write Ahead Log
|
## [Module] Write Ahead Log
|
||||||
/src/log-store @v0y4g3r
|
/src/log-store @v0y4g3r @WenyXu
|
||||||
/src/store-api @v0y4g3r
|
/src/store-api @v0y4g3r @evenyag
|
||||||
|
|
||||||
## [Module] Metrics Engine
|
## [Module] Metrics Engine
|
||||||
/src/metric-engine @waynexia
|
/src/metric-engine @waynexia @WenyXu
|
||||||
/src/promql @waynexia
|
/src/promql @waynexia @evenyag @discord9
|
||||||
|
|
||||||
## [Module] Flow
|
## [Module] Flow
|
||||||
/src/flow @zhongzc @waynexia
|
/src/flow @discord9 @waynexia
|
||||||
|
|||||||
17
.github/actions/build-greptime-binary/action.yml
vendored
17
.github/actions/build-greptime-binary/action.yml
vendored
@@ -32,9 +32,23 @@ inputs:
|
|||||||
description: Image Registry
|
description: Image Registry
|
||||||
required: false
|
required: false
|
||||||
default: 'docker.io'
|
default: 'docker.io'
|
||||||
|
large-page-size:
|
||||||
|
description: Build GreptimeDB with large page size (65536).
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
|
- name: Set extra build environment variables
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [[ '${{ inputs.large-page-size }}' == 'true' ]]; then
|
||||||
|
echo 'EXTRA_BUILD_ENVS="JEMALLOC_SYS_WITH_LG_PAGE=16"' >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo 'EXTRA_BUILD_ENVS=' >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Build greptime binary
|
- name: Build greptime binary
|
||||||
shell: bash
|
shell: bash
|
||||||
if: ${{ inputs.build-android-artifacts == 'false' }}
|
if: ${{ inputs.build-android-artifacts == 'false' }}
|
||||||
@@ -45,7 +59,8 @@ runs:
|
|||||||
FEATURES=${{ inputs.features }} \
|
FEATURES=${{ inputs.features }} \
|
||||||
BASE_IMAGE=${{ inputs.base-image }} \
|
BASE_IMAGE=${{ inputs.base-image }} \
|
||||||
IMAGE_NAMESPACE=${{ inputs.image-namespace }} \
|
IMAGE_NAMESPACE=${{ inputs.image-namespace }} \
|
||||||
IMAGE_REGISTRY=${{ inputs.image-registry }}
|
IMAGE_REGISTRY=${{ inputs.image-registry }} \
|
||||||
|
EXTRA_BUILD_ENVS=$EXTRA_BUILD_ENVS
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: ./.github/actions/upload-artifacts
|
uses: ./.github/actions/upload-artifacts
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ inputs:
|
|||||||
description: Working directory to build the artifacts
|
description: Working directory to build the artifacts
|
||||||
required: false
|
required: false
|
||||||
default: .
|
default: .
|
||||||
|
large-page-size:
|
||||||
|
description: Build GreptimeDB with large page size (65536).
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
@@ -59,6 +63,7 @@ runs:
|
|||||||
working-dir: ${{ inputs.working-dir }}
|
working-dir: ${{ inputs.working-dir }}
|
||||||
image-registry: ${{ inputs.image-registry }}
|
image-registry: ${{ inputs.image-registry }}
|
||||||
image-namespace: ${{ inputs.image-namespace }}
|
image-namespace: ${{ inputs.image-namespace }}
|
||||||
|
large-page-size: ${{ inputs.large-page-size }}
|
||||||
|
|
||||||
- name: Clean up the target directory # Clean up the target directory for the centos7 base image, or it will still use the objects of last build.
|
- name: Clean up the target directory # Clean up the target directory for the centos7 base image, or it will still use the objects of last build.
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -77,6 +82,7 @@ runs:
|
|||||||
working-dir: ${{ inputs.working-dir }}
|
working-dir: ${{ inputs.working-dir }}
|
||||||
image-registry: ${{ inputs.image-registry }}
|
image-registry: ${{ inputs.image-registry }}
|
||||||
image-namespace: ${{ inputs.image-namespace }}
|
image-namespace: ${{ inputs.image-namespace }}
|
||||||
|
large-page-size: ${{ inputs.large-page-size }}
|
||||||
|
|
||||||
- name: Build greptime on android base image
|
- name: Build greptime on android base image
|
||||||
uses: ./.github/actions/build-greptime-binary
|
uses: ./.github/actions/build-greptime-binary
|
||||||
@@ -89,3 +95,4 @@ runs:
|
|||||||
build-android-artifacts: true
|
build-android-artifacts: true
|
||||||
image-registry: ${{ inputs.image-registry }}
|
image-registry: ${{ inputs.image-registry }}
|
||||||
image-namespace: ${{ inputs.image-namespace }}
|
image-namespace: ${{ inputs.image-namespace }}
|
||||||
|
large-page-size: ${{ inputs.large-page-size }}
|
||||||
|
|||||||
@@ -39,8 +39,11 @@ update_helm_charts_version() {
|
|||||||
--body "This PR updates the GreptimeDB version." \
|
--body "This PR updates the GreptimeDB version." \
|
||||||
--base main \
|
--base main \
|
||||||
--head $BRANCH_NAME \
|
--head $BRANCH_NAME \
|
||||||
--reviewer zyy17 \
|
--reviewer sunng87 \
|
||||||
--reviewer daviderli614
|
--reviewer daviderli614 \
|
||||||
|
--reviewer killme2008 \
|
||||||
|
--reviewer evenyag \
|
||||||
|
--reviewer fengjiachun
|
||||||
}
|
}
|
||||||
|
|
||||||
update_helm_charts_version
|
update_helm_charts_version
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ update_homebrew_greptime_version() {
|
|||||||
--body "This PR updates the GreptimeDB version." \
|
--body "This PR updates the GreptimeDB version." \
|
||||||
--base main \
|
--base main \
|
||||||
--head $BRANCH_NAME \
|
--head $BRANCH_NAME \
|
||||||
--reviewer zyy17 \
|
--reviewer sunng87 \
|
||||||
--reviewer daviderli614
|
--reviewer daviderli614 \
|
||||||
|
--reviewer killme2008 \
|
||||||
|
--reviewer evenyag \
|
||||||
|
--reviewer fengjiachun
|
||||||
}
|
}
|
||||||
|
|
||||||
update_homebrew_greptime_version
|
update_homebrew_greptime_version
|
||||||
|
|||||||
9
.github/workflows/dev-build.yml
vendored
9
.github/workflows/dev-build.yml
vendored
@@ -4,10 +4,11 @@ name: GreptimeDB Development Build
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch: # Allows you to run this workflow manually.
|
workflow_dispatch: # Allows you to run this workflow manually.
|
||||||
inputs:
|
inputs:
|
||||||
repository:
|
large-page-size:
|
||||||
description: The public repository to build
|
description: Build GreptimeDB with large page size (65536).
|
||||||
|
type: boolean
|
||||||
required: false
|
required: false
|
||||||
default: GreptimeTeam/greptimedb
|
default: false
|
||||||
commit: # Note: We only pull the source code and use the current workflow to build the artifacts.
|
commit: # Note: We only pull the source code and use the current workflow to build the artifacts.
|
||||||
description: The commit to build
|
description: The commit to build
|
||||||
required: true
|
required: true
|
||||||
@@ -181,6 +182,7 @@ jobs:
|
|||||||
working-dir: ${{ env.CHECKOUT_GREPTIMEDB_PATH }}
|
working-dir: ${{ env.CHECKOUT_GREPTIMEDB_PATH }}
|
||||||
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
||||||
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
||||||
|
large-page-size: ${{ inputs.large-page-size }}
|
||||||
|
|
||||||
build-linux-arm64-artifacts:
|
build-linux-arm64-artifacts:
|
||||||
name: Build linux-arm64 artifacts
|
name: Build linux-arm64 artifacts
|
||||||
@@ -214,6 +216,7 @@ jobs:
|
|||||||
working-dir: ${{ env.CHECKOUT_GREPTIMEDB_PATH }}
|
working-dir: ${{ env.CHECKOUT_GREPTIMEDB_PATH }}
|
||||||
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
||||||
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
||||||
|
large-page-size: ${{ inputs.large-page-size }}
|
||||||
|
|
||||||
release-images-to-dockerhub:
|
release-images-to-dockerhub:
|
||||||
name: Build and push images to DockerHub
|
name: Build and push images to DockerHub
|
||||||
|
|||||||
57
.github/workflows/multi-lang-tests.yml
vendored
Normal file
57
.github/workflows/multi-lang-tests.yml
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
name: Multi-language Integration Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-greptimedb:
|
||||||
|
if: ${{ github.repository == 'GreptimeTeam/greptimedb' }}
|
||||||
|
name: Build GreptimeDB binary
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- uses: arduino/setup-protoc@v3
|
||||||
|
with:
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: "multi-lang-build"
|
||||||
|
cache-all-crates: "true"
|
||||||
|
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
|
- name: Install cargo-gc-bin
|
||||||
|
shell: bash
|
||||||
|
run: cargo install cargo-gc-bin --force
|
||||||
|
- name: Build greptime binary
|
||||||
|
shell: bash
|
||||||
|
run: cargo gc -- --bin greptime --features "pg_kvbackend,mysql_kvbackend"
|
||||||
|
- name: Pack greptime binary
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir bin && \
|
||||||
|
mv ./target/debug/greptime bin
|
||||||
|
- name: Print greptime binary info
|
||||||
|
run: ls -lh bin
|
||||||
|
- name: Upload greptime binary
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: greptime-bin
|
||||||
|
path: bin/
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
run-multi-lang-tests:
|
||||||
|
name: Run Multi-language SDK Tests
|
||||||
|
needs: build-greptimedb
|
||||||
|
uses: ./.github/workflows/run-multi-lang-tests.yml
|
||||||
|
with:
|
||||||
|
artifact-name: greptime-bin
|
||||||
21
.github/workflows/nightly-build.yml
vendored
21
.github/workflows/nightly-build.yml
vendored
@@ -174,6 +174,18 @@ jobs:
|
|||||||
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
||||||
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
||||||
|
|
||||||
|
run-multi-lang-tests:
|
||||||
|
name: Run Multi-language SDK Tests
|
||||||
|
if: ${{ inputs.build_linux_amd64_artifacts || github.event_name == 'schedule' }}
|
||||||
|
needs: [
|
||||||
|
allocate-runners,
|
||||||
|
build-linux-amd64-artifacts,
|
||||||
|
]
|
||||||
|
uses: ./.github/workflows/run-multi-lang-tests.yml
|
||||||
|
with:
|
||||||
|
artifact-name: greptime-linux-amd64-${{ needs.allocate-runners.outputs.version }}
|
||||||
|
artifact-is-tarball: true
|
||||||
|
|
||||||
release-images-to-dockerhub:
|
release-images-to-dockerhub:
|
||||||
name: Build and push images to DockerHub
|
name: Build and push images to DockerHub
|
||||||
if: ${{ inputs.release_images || github.event_name == 'schedule' }}
|
if: ${{ inputs.release_images || github.event_name == 'schedule' }}
|
||||||
@@ -301,7 +313,8 @@ jobs:
|
|||||||
if: ${{ github.repository == 'GreptimeTeam/greptimedb' && always() }} # Not requiring successful dependent jobs, always run.
|
if: ${{ github.repository == 'GreptimeTeam/greptimedb' && always() }} # Not requiring successful dependent jobs, always run.
|
||||||
name: Send notification to Greptime team
|
name: Send notification to Greptime team
|
||||||
needs: [
|
needs: [
|
||||||
release-images-to-dockerhub
|
release-images-to-dockerhub,
|
||||||
|
run-multi-lang-tests,
|
||||||
]
|
]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
@@ -319,17 +332,17 @@ jobs:
|
|||||||
run: pnpm tsx bin/report-ci-failure.ts
|
run: pnpm tsx bin/report-ci-failure.ts
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
CI_REPORT_STATUS: ${{ needs.release-images-to-dockerhub.outputs.nightly-build-result == 'success' }}
|
CI_REPORT_STATUS: ${{ needs.release-images-to-dockerhub.outputs.nightly-build-result == 'success' && (needs.run-multi-lang-tests.result == 'success' || needs.run-multi-lang-tests.result == 'skipped') }}
|
||||||
- name: Notify nightly build successful result
|
- name: Notify nightly build successful result
|
||||||
uses: slackapi/slack-github-action@v1.23.0
|
uses: slackapi/slack-github-action@v1.23.0
|
||||||
if: ${{ needs.release-images-to-dockerhub.outputs.nightly-build-result == 'success' }}
|
if: ${{ needs.release-images-to-dockerhub.outputs.nightly-build-result == 'success' && (needs.run-multi-lang-tests.result == 'success' || needs.run-multi-lang-tests.result == 'skipped') }}
|
||||||
with:
|
with:
|
||||||
payload: |
|
payload: |
|
||||||
{"text": "GreptimeDB's ${{ env.NEXT_RELEASE_VERSION }} build has completed successfully."}
|
{"text": "GreptimeDB's ${{ env.NEXT_RELEASE_VERSION }} build has completed successfully."}
|
||||||
|
|
||||||
- name: Notify nightly build failed result
|
- name: Notify nightly build failed result
|
||||||
uses: slackapi/slack-github-action@v1.23.0
|
uses: slackapi/slack-github-action@v1.23.0
|
||||||
if: ${{ needs.release-images-to-dockerhub.outputs.nightly-build-result != 'success' }}
|
if: ${{ needs.release-images-to-dockerhub.outputs.nightly-build-result != 'success' || needs.run-multi-lang-tests.result == 'failure' }}
|
||||||
with:
|
with:
|
||||||
payload: |
|
payload: |
|
||||||
{"text": "GreptimeDB's ${{ env.NEXT_RELEASE_VERSION }} build has failed, please check ${{ steps.report-ci-status.outputs.html_url }}."}
|
{"text": "GreptimeDB's ${{ env.NEXT_RELEASE_VERSION }} build has failed, please check ${{ steps.report-ci-status.outputs.html_url }}."}
|
||||||
|
|||||||
14
.github/workflows/release.yml
vendored
14
.github/workflows/release.yml
vendored
@@ -215,6 +215,18 @@ jobs:
|
|||||||
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
image-registry: ${{ vars.ECR_IMAGE_REGISTRY }}
|
||||||
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
image-namespace: ${{ vars.ECR_IMAGE_NAMESPACE }}
|
||||||
|
|
||||||
|
run-multi-lang-tests:
|
||||||
|
name: Run Multi-language SDK Tests
|
||||||
|
if: ${{ inputs.build_linux_amd64_artifacts || github.event_name == 'push' || github.event_name == 'schedule' }}
|
||||||
|
needs: [
|
||||||
|
allocate-runners,
|
||||||
|
build-linux-amd64-artifacts,
|
||||||
|
]
|
||||||
|
uses: ./.github/workflows/run-multi-lang-tests.yml
|
||||||
|
with:
|
||||||
|
artifact-name: greptime-linux-amd64-${{ needs.allocate-runners.outputs.version }}
|
||||||
|
artifact-is-tarball: true
|
||||||
|
|
||||||
build-macos-artifacts:
|
build-macos-artifacts:
|
||||||
name: Build macOS artifacts
|
name: Build macOS artifacts
|
||||||
strategy:
|
strategy:
|
||||||
@@ -303,6 +315,7 @@ jobs:
|
|||||||
allocate-runners,
|
allocate-runners,
|
||||||
build-linux-amd64-artifacts,
|
build-linux-amd64-artifacts,
|
||||||
build-linux-arm64-artifacts,
|
build-linux-arm64-artifacts,
|
||||||
|
run-multi-lang-tests,
|
||||||
]
|
]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
@@ -381,6 +394,7 @@ jobs:
|
|||||||
build-macos-artifacts,
|
build-macos-artifacts,
|
||||||
build-windows-artifacts,
|
build-windows-artifacts,
|
||||||
release-images-to-dockerhub,
|
release-images-to-dockerhub,
|
||||||
|
run-multi-lang-tests,
|
||||||
]
|
]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
194
.github/workflows/run-multi-lang-tests.yml
vendored
Normal file
194
.github/workflows/run-multi-lang-tests.yml
vendored
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# Reusable workflow for running multi-language SDK tests against GreptimeDB
|
||||||
|
# Used by: multi-lang-tests.yml, release.yml, nightly-build.yml
|
||||||
|
# Supports both direct binary artifacts and tarball artifacts
|
||||||
|
|
||||||
|
name: Run Multi-language SDK Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
artifact-name:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
description: 'Name of the artifact containing greptime binary'
|
||||||
|
http-port:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: '4000'
|
||||||
|
description: 'HTTP server port'
|
||||||
|
mysql-port:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: '4002'
|
||||||
|
description: 'MySQL server port'
|
||||||
|
postgres-port:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: '4003'
|
||||||
|
description: 'PostgreSQL server port'
|
||||||
|
db-name:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: 'test_db'
|
||||||
|
description: 'Test database name'
|
||||||
|
username:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: 'greptime_user'
|
||||||
|
description: 'Authentication username'
|
||||||
|
password:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: 'greptime_pwd'
|
||||||
|
description: 'Authentication password'
|
||||||
|
timeout-minutes:
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
default: 30
|
||||||
|
description: 'Job timeout in minutes'
|
||||||
|
artifact-is-tarball:
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
description: 'Whether the artifact is a tarball (tar.gz) that needs to be extracted'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run-tests:
|
||||||
|
name: Run Multi-language SDK Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: ${{ inputs.timeout-minutes }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout greptimedb-tests repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: GreptimeTeam/greptimedb-tests
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Download pre-built greptime binary
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ inputs.artifact-name }}
|
||||||
|
path: artifact
|
||||||
|
|
||||||
|
- name: Setup greptime binary
|
||||||
|
run: |
|
||||||
|
mkdir -p bin
|
||||||
|
if [ "${{ inputs.artifact-is-tarball }}" = "true" ]; then
|
||||||
|
# Extract tarball and find greptime binary
|
||||||
|
tar -xzf artifact/*.tar.gz -C artifact
|
||||||
|
find artifact -name "greptime" -type f -exec cp {} bin/greptime \;
|
||||||
|
else
|
||||||
|
# Direct binary format
|
||||||
|
if [ -f artifact/greptime ]; then
|
||||||
|
cp artifact/greptime bin/greptime
|
||||||
|
else
|
||||||
|
cp artifact/* bin/greptime
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
chmod +x ./bin/greptime
|
||||||
|
ls -lh ./bin/greptime
|
||||||
|
./bin/greptime --version
|
||||||
|
|
||||||
|
- name: Setup Java 17
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
cache: 'maven'
|
||||||
|
|
||||||
|
- name: Setup Python 3.8
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.8'
|
||||||
|
|
||||||
|
- name: Setup Go 1.24
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '1.24'
|
||||||
|
cache: true
|
||||||
|
cache-dependency-path: go-tests/go.sum
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '18'
|
||||||
|
|
||||||
|
- name: Install Python dependencies
|
||||||
|
run: |
|
||||||
|
pip install mysql-connector-python psycopg2-binary
|
||||||
|
python3 -c "import mysql.connector; print(f'mysql-connector-python {mysql.connector.__version__}')"
|
||||||
|
python3 -c "import psycopg2; print(f'psycopg2 {psycopg2.__version__}')"
|
||||||
|
|
||||||
|
- name: Install Go dependencies
|
||||||
|
working-directory: go-tests
|
||||||
|
run: |
|
||||||
|
go mod download
|
||||||
|
go mod verify
|
||||||
|
go version
|
||||||
|
|
||||||
|
- name: Kill existing GreptimeDB processes
|
||||||
|
run: |
|
||||||
|
pkill -f greptime || true
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
- name: Start GreptimeDB standalone
|
||||||
|
run: |
|
||||||
|
./bin/greptime standalone start \
|
||||||
|
--http-addr 0.0.0.0:${{ inputs.http-port }} \
|
||||||
|
--rpc-addr 0.0.0.0:4001 \
|
||||||
|
--mysql-addr 0.0.0.0:${{ inputs.mysql-port }} \
|
||||||
|
--postgres-addr 0.0.0.0:${{ inputs.postgres-port }} \
|
||||||
|
--user-provider=static_user_provider:cmd:${{ inputs.username }}=${{ inputs.password }} > /tmp/greptimedb.log 2>&1 &
|
||||||
|
|
||||||
|
- name: Wait for GreptimeDB to be ready
|
||||||
|
run: |
|
||||||
|
echo "Waiting for GreptimeDB..."
|
||||||
|
for i in {1..60}; do
|
||||||
|
if curl -sf http://localhost:${{ inputs.http-port }}/health > /dev/null; then
|
||||||
|
echo "✅ GreptimeDB is ready"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "❌ GreptimeDB failed to start"
|
||||||
|
cat /tmp/greptimedb.log
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: Run multi-language tests
|
||||||
|
env:
|
||||||
|
DB_NAME: ${{ inputs.db-name }}
|
||||||
|
MYSQL_HOST: 127.0.0.1
|
||||||
|
MYSQL_PORT: ${{ inputs.mysql-port }}
|
||||||
|
POSTGRES_HOST: 127.0.0.1
|
||||||
|
POSTGRES_PORT: ${{ inputs.postgres-port }}
|
||||||
|
HTTP_HOST: 127.0.0.1
|
||||||
|
HTTP_PORT: ${{ inputs.http-port }}
|
||||||
|
GREPTIME_USERNAME: ${{ inputs.username }}
|
||||||
|
GREPTIME_PASSWORD: ${{ inputs.password }}
|
||||||
|
run: |
|
||||||
|
chmod +x ./run_tests.sh
|
||||||
|
./run_tests.sh
|
||||||
|
|
||||||
|
- name: Collect logs on failure
|
||||||
|
if: failure()
|
||||||
|
run: |
|
||||||
|
echo "=== GreptimeDB Logs ==="
|
||||||
|
cat /tmp/greptimedb.log || true
|
||||||
|
|
||||||
|
- name: Upload test logs on failure
|
||||||
|
if: failure()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: test-logs
|
||||||
|
path: |
|
||||||
|
/tmp/greptimedb.log
|
||||||
|
java-tests/target/surefire-reports/
|
||||||
|
python-tests/.pytest_cache/
|
||||||
|
go-tests/*.log
|
||||||
|
**/test-output/
|
||||||
|
retention-days: 7
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
pkill -f greptime || true
|
||||||
253
Cargo.lock
generated
253
Cargo.lock
generated
@@ -212,7 +212,7 @@ checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "api"
|
name = "api"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow-schema",
|
"arrow-schema",
|
||||||
"common-base",
|
"common-base",
|
||||||
@@ -733,7 +733,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "auth"
|
name = "auth"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -1383,7 +1383,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cache"
|
name = "cache"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"catalog",
|
"catalog",
|
||||||
"common-error",
|
"common-error",
|
||||||
@@ -1418,7 +1418,7 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "catalog"
|
name = "catalog"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -1763,7 +1763,7 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cli"
|
name = "cli"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -1816,7 +1816,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "client"
|
name = "client"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
@@ -1849,7 +1849,7 @@ dependencies = [
|
|||||||
"snafu 0.8.6",
|
"snafu 0.8.6",
|
||||||
"store-api",
|
"store-api",
|
||||||
"substrait 0.37.3",
|
"substrait 0.37.3",
|
||||||
"substrait 1.0.0-beta.1",
|
"substrait 1.0.0-beta.2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tonic 0.13.1",
|
"tonic 0.13.1",
|
||||||
@@ -1889,7 +1889,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cmd"
|
name = "cmd"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"auth",
|
"auth",
|
||||||
@@ -2012,7 +2012,7 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-base"
|
name = "common-base"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anymap2",
|
"anymap2",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -2036,14 +2036,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-catalog"
|
name = "common-catalog"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"const_format",
|
"const_format",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-config"
|
name = "common-config"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-base",
|
"common-base",
|
||||||
"common-error",
|
"common-error",
|
||||||
@@ -2067,7 +2067,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-datasource"
|
name = "common-datasource"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"arrow-schema",
|
"arrow-schema",
|
||||||
@@ -2102,7 +2102,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-decimal"
|
name = "common-decimal"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bigdecimal 0.4.8",
|
"bigdecimal 0.4.8",
|
||||||
"common-error",
|
"common-error",
|
||||||
@@ -2115,7 +2115,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-error"
|
name = "common-error"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-macro",
|
"common-macro",
|
||||||
"http 1.3.1",
|
"http 1.3.1",
|
||||||
@@ -2126,7 +2126,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-event-recorder"
|
name = "common-event-recorder"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -2148,7 +2148,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-frontend"
|
name = "common-frontend"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -2170,7 +2170,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-function"
|
name = "common-function"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"api",
|
"api",
|
||||||
@@ -2208,6 +2208,7 @@ dependencies = [
|
|||||||
"hyperloglogplus",
|
"hyperloglogplus",
|
||||||
"jsonb",
|
"jsonb",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
"mito-codec",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
"num",
|
"num",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
@@ -2229,7 +2230,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-greptimedb-telemetry"
|
name = "common-greptimedb-telemetry"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"common-runtime",
|
"common-runtime",
|
||||||
@@ -2246,7 +2247,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-grpc"
|
name = "common-grpc"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arrow-flight",
|
"arrow-flight",
|
||||||
@@ -2265,11 +2266,13 @@ dependencies = [
|
|||||||
"hyper 1.6.0",
|
"hyper 1.6.0",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"notify",
|
||||||
"prost 0.13.5",
|
"prost 0.13.5",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"snafu 0.8.6",
|
"snafu 0.8.6",
|
||||||
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tonic 0.13.1",
|
"tonic 0.13.1",
|
||||||
@@ -2279,7 +2282,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-grpc-expr"
|
name = "common-grpc-expr"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"common-base",
|
"common-base",
|
||||||
@@ -2299,7 +2302,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-macro"
|
name = "common-macro"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"greptime-proto",
|
"greptime-proto",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -2310,7 +2313,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-mem-prof"
|
name = "common-mem-prof"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"common-error",
|
"common-error",
|
||||||
@@ -2326,7 +2329,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-meta"
|
name = "common-meta"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anymap2",
|
"anymap2",
|
||||||
"api",
|
"api",
|
||||||
@@ -2398,7 +2401,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-options"
|
name = "common-options"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-grpc",
|
"common-grpc",
|
||||||
"humantime-serde",
|
"humantime-serde",
|
||||||
@@ -2407,11 +2410,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-plugins"
|
name = "common-plugins"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-pprof"
|
name = "common-pprof"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-error",
|
"common-error",
|
||||||
"common-macro",
|
"common-macro",
|
||||||
@@ -2423,7 +2426,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-procedure"
|
name = "common-procedure"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-stream",
|
"async-stream",
|
||||||
@@ -2452,7 +2455,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-procedure-test"
|
name = "common-procedure-test"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"common-procedure",
|
"common-procedure",
|
||||||
@@ -2462,7 +2465,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-query"
|
name = "common-query"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -2488,7 +2491,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-recordbatch"
|
name = "common-recordbatch"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
"common-base",
|
"common-base",
|
||||||
@@ -2512,7 +2515,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-runtime"
|
name = "common-runtime"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"clap 4.5.40",
|
"clap 4.5.40",
|
||||||
@@ -2541,7 +2544,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-session"
|
name = "common-session"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"strum 0.27.1",
|
"strum 0.27.1",
|
||||||
@@ -2549,7 +2552,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-sql"
|
name = "common-sql"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-base",
|
"common-base",
|
||||||
"common-decimal",
|
"common-decimal",
|
||||||
@@ -2567,7 +2570,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-stat"
|
name = "common-stat"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-base",
|
"common-base",
|
||||||
"common-runtime",
|
"common-runtime",
|
||||||
@@ -2582,7 +2585,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-telemetry"
|
name = "common-telemetry"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"common-base",
|
"common-base",
|
||||||
@@ -2611,7 +2614,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-test-util"
|
name = "common-test-util"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"client",
|
"client",
|
||||||
"common-grpc",
|
"common-grpc",
|
||||||
@@ -2624,7 +2627,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-time"
|
name = "common-time"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -2642,7 +2645,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-version"
|
name = "common-version"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"build-data",
|
"build-data",
|
||||||
"cargo-manifest",
|
"cargo-manifest",
|
||||||
@@ -2653,7 +2656,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-wal"
|
name = "common-wal"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-base",
|
"common-base",
|
||||||
"common-error",
|
"common-error",
|
||||||
@@ -2676,7 +2679,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common-workload"
|
name = "common-workload"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common-telemetry",
|
"common-telemetry",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -3271,7 +3274,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion"
|
name = "datafusion"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"arrow-ipc",
|
"arrow-ipc",
|
||||||
@@ -3326,7 +3329,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-catalog"
|
name = "datafusion-catalog"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3350,7 +3353,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-catalog-listing"
|
name = "datafusion-catalog-listing"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3372,7 +3375,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-common"
|
name = "datafusion-common"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -3395,7 +3398,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-common-runtime"
|
name = "datafusion-common-runtime"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"log",
|
"log",
|
||||||
@@ -3405,7 +3408,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-datasource"
|
name = "datafusion-datasource"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-compression 0.4.19",
|
"async-compression 0.4.19",
|
||||||
@@ -3439,7 +3442,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-datasource-csv"
|
name = "datafusion-datasource-csv"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3461,7 +3464,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-datasource-json"
|
name = "datafusion-datasource-json"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3482,7 +3485,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-datasource-parquet"
|
name = "datafusion-datasource-parquet"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3511,12 +3514,12 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-doc"
|
name = "datafusion-doc"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-execution"
|
name = "datafusion-execution"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3535,7 +3538,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-expr"
|
name = "datafusion-expr"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3557,7 +3560,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-expr-common"
|
name = "datafusion-expr-common"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
@@ -3569,7 +3572,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions"
|
name = "datafusion-functions"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"arrow-buffer",
|
"arrow-buffer",
|
||||||
@@ -3597,7 +3600,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions-aggregate"
|
name = "datafusion-functions-aggregate"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -3617,7 +3620,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions-aggregate-common"
|
name = "datafusion-functions-aggregate-common"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -3629,7 +3632,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions-nested"
|
name = "datafusion-functions-nested"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"arrow-ord",
|
"arrow-ord",
|
||||||
@@ -3651,7 +3654,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions-table"
|
name = "datafusion-functions-table"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3666,7 +3669,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions-window"
|
name = "datafusion-functions-window"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
@@ -3683,7 +3686,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-functions-window-common"
|
name = "datafusion-functions-window-common"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
"datafusion-physical-expr-common",
|
"datafusion-physical-expr-common",
|
||||||
@@ -3692,7 +3695,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-macros"
|
name = "datafusion-macros"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"datafusion-doc",
|
"datafusion-doc",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -3702,7 +3705,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-optimizer"
|
name = "datafusion-optimizer"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -3738,9 +3741,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-pg-catalog"
|
name = "datafusion-pg-catalog"
|
||||||
version = "0.12.1"
|
version = "0.12.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "15824c98ff2009c23b0398d441499b147f7c5ac0e5ee993e7a473d79040e3626"
|
checksum = "755393864c0c2dd95575ceed4b25e348686028e1b83d06f8f39914209999f821"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"datafusion",
|
"datafusion",
|
||||||
@@ -3753,7 +3756,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-physical-expr"
|
name = "datafusion-physical-expr"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -3774,7 +3777,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-physical-expr-adapter"
|
name = "datafusion-physical-expr-adapter"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
@@ -3788,7 +3791,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-physical-expr-common"
|
name = "datafusion-physical-expr-common"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -3801,7 +3804,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-physical-optimizer"
|
name = "datafusion-physical-optimizer"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
@@ -3819,7 +3822,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-physical-plan"
|
name = "datafusion-physical-plan"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -3849,7 +3852,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-pruning"
|
name = "datafusion-pruning"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
@@ -3865,7 +3868,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-session"
|
name = "datafusion-session"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"datafusion-common",
|
"datafusion-common",
|
||||||
@@ -3878,7 +3881,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-sql"
|
name = "datafusion-sql"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"bigdecimal 0.4.8",
|
"bigdecimal 0.4.8",
|
||||||
@@ -3895,7 +3898,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "datafusion-substrait"
|
name = "datafusion-substrait"
|
||||||
version = "50.1.0"
|
version = "50.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=fd4b2abcf3c3e43e94951bda452c9fd35243aab0#fd4b2abcf3c3e43e94951bda452c9fd35243aab0"
|
source = "git+https://github.com/GreptimeTeam/datafusion.git?rev=7f8ea0a45748ed32695757368f847ab9ac7b6c82#7f8ea0a45748ed32695757368f847ab9ac7b6c82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3913,7 +3916,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "datanode"
|
name = "datanode"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arrow-flight",
|
"arrow-flight",
|
||||||
@@ -3977,7 +3980,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "datatypes"
|
name = "datatypes"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrow",
|
"arrow",
|
||||||
"arrow-array",
|
"arrow-array",
|
||||||
@@ -4649,7 +4652,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "file-engine"
|
name = "file-engine"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -4781,7 +4784,7 @@ checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flow"
|
name = "flow"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arrow",
|
"arrow",
|
||||||
@@ -4850,7 +4853,7 @@ dependencies = [
|
|||||||
"sql",
|
"sql",
|
||||||
"store-api",
|
"store-api",
|
||||||
"strum 0.27.1",
|
"strum 0.27.1",
|
||||||
"substrait 1.0.0-beta.1",
|
"substrait 1.0.0-beta.2",
|
||||||
"table",
|
"table",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tonic 0.13.1",
|
"tonic 0.13.1",
|
||||||
@@ -4905,7 +4908,7 @@ checksum = "28dd6caf6059519a65843af8fe2a3ae298b14b80179855aeb4adc2c1934ee619"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "frontend"
|
name = "frontend"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
@@ -5348,7 +5351,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "greptime-proto"
|
name = "greptime-proto"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/GreptimeTeam/greptime-proto.git?rev=14b9dc40bdc8288742b0cefc7bb024303b7429ef#14b9dc40bdc8288742b0cefc7bb024303b7429ef"
|
source = "git+https://github.com/GreptimeTeam/greptime-proto.git?rev=0df99f09f1d6785055b2d9da96fc4ecc2bdf6803#0df99f09f1d6785055b2d9da96fc4ecc2bdf6803"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"prost 0.13.5",
|
"prost 0.13.5",
|
||||||
"prost-types 0.13.5",
|
"prost-types 0.13.5",
|
||||||
@@ -6116,7 +6119,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "index"
|
name = "index"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"asynchronous-codec",
|
"asynchronous-codec",
|
||||||
@@ -7045,7 +7048,7 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log-query"
|
name = "log-query"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"common-error",
|
"common-error",
|
||||||
@@ -7057,7 +7060,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log-store"
|
name = "log-store"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -7364,7 +7367,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "meta-client"
|
name = "meta-client"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -7392,7 +7395,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "meta-srv"
|
name = "meta-srv"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -7440,7 +7443,9 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"local-ip-address",
|
"local-ip-address",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"ordered-float 4.6.0",
|
||||||
"parking_lot 0.12.4",
|
"parking_lot 0.12.4",
|
||||||
|
"partition",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"prost 0.13.5",
|
"prost 0.13.5",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
@@ -7490,7 +7495,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "metric-engine"
|
name = "metric-engine"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"aquamarine",
|
"aquamarine",
|
||||||
@@ -7585,7 +7590,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mito-codec"
|
name = "mito-codec"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -7610,7 +7615,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mito2"
|
name = "mito2"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"aquamarine",
|
"aquamarine",
|
||||||
@@ -8348,7 +8353,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object-store"
|
name = "object-store"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -8357,6 +8362,7 @@ dependencies = [
|
|||||||
"common-macro",
|
"common-macro",
|
||||||
"common-telemetry",
|
"common-telemetry",
|
||||||
"common-test-util",
|
"common-test-util",
|
||||||
|
"derive_builder 0.20.2",
|
||||||
"futures",
|
"futures",
|
||||||
"humantime-serde",
|
"humantime-serde",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -8527,7 +8533,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "opensrv-mysql"
|
name = "opensrv-mysql"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "git+https://github.com/datafuselabs/opensrv?rev=a1fb4da215c8693c7e4f62be249a01b7fec52997#a1fb4da215c8693c7e4f62be249a01b7fec52997"
|
source = "git+https://github.com/datafuselabs/opensrv?tag=v0.10.0#074bd8fb81da3c9e6d6a098a482f3380478b9c0b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
@@ -8633,7 +8639,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "operator"
|
name = "operator"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"api",
|
"api",
|
||||||
@@ -8659,6 +8665,7 @@ dependencies = [
|
|||||||
"common-recordbatch",
|
"common-recordbatch",
|
||||||
"common-runtime",
|
"common-runtime",
|
||||||
"common-sql",
|
"common-sql",
|
||||||
|
"common-stat",
|
||||||
"common-telemetry",
|
"common-telemetry",
|
||||||
"common-test-util",
|
"common-test-util",
|
||||||
"common-time",
|
"common-time",
|
||||||
@@ -8670,6 +8677,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"humantime",
|
"humantime",
|
||||||
|
"itertools 0.14.0",
|
||||||
"jsonb",
|
"jsonb",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"meta-client",
|
"meta-client",
|
||||||
@@ -8691,7 +8699,7 @@ dependencies = [
|
|||||||
"sql",
|
"sql",
|
||||||
"sqlparser",
|
"sqlparser",
|
||||||
"store-api",
|
"store-api",
|
||||||
"substrait 1.0.0-beta.1",
|
"substrait 1.0.0-beta.2",
|
||||||
"table",
|
"table",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
@@ -8977,7 +8985,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "partition"
|
name = "partition"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -9181,10 +9189,21 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pgwire"
|
name = "pg_interval"
|
||||||
version = "0.34.2"
|
version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4f56a81b4fcc69016028f657a68f9b8e8a2a4b7d07684ca3298f2d3e7ff199ce"
|
checksum = "fe46640b465e284b048ef065cbed8ef17a622878d310c724578396b4cfd00df2"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"chrono",
|
||||||
|
"postgres-types",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pgwire"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d331bb0eef5bc83a221c0a85b1f205bccf094d4f72a26ae1d68a1b1c535123b7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
@@ -9200,6 +9219,7 @@ dependencies = [
|
|||||||
"ring",
|
"ring",
|
||||||
"rust_decimal",
|
"rust_decimal",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"stringprep",
|
"stringprep",
|
||||||
@@ -9322,7 +9342,7 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pipeline"
|
name = "pipeline"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"api",
|
"api",
|
||||||
@@ -9478,9 +9498,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plugins"
|
name = "plugins"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"auth",
|
"auth",
|
||||||
|
"catalog",
|
||||||
"clap 4.5.40",
|
"clap 4.5.40",
|
||||||
"cli",
|
"cli",
|
||||||
"common-base",
|
"common-base",
|
||||||
@@ -9489,6 +9510,7 @@ dependencies = [
|
|||||||
"datanode",
|
"datanode",
|
||||||
"flow",
|
"flow",
|
||||||
"frontend",
|
"frontend",
|
||||||
|
"meta-client",
|
||||||
"meta-srv",
|
"meta-srv",
|
||||||
"serde",
|
"serde",
|
||||||
"snafu 0.8.6",
|
"snafu 0.8.6",
|
||||||
@@ -9778,7 +9800,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "promql"
|
name = "promql"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -10061,7 +10083,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "puffin"
|
name = "puffin"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-compression 0.4.19",
|
"async-compression 0.4.19",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -10103,7 +10125,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "query"
|
name = "query"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"api",
|
"api",
|
||||||
@@ -10170,7 +10192,7 @@ dependencies = [
|
|||||||
"sql",
|
"sql",
|
||||||
"sqlparser",
|
"sqlparser",
|
||||||
"store-api",
|
"store-api",
|
||||||
"substrait 1.0.0-beta.1",
|
"substrait 1.0.0-beta.2",
|
||||||
"table",
|
"table",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
@@ -11506,7 +11528,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servers"
|
name = "servers"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"api",
|
"api",
|
||||||
@@ -11583,6 +11605,7 @@ dependencies = [
|
|||||||
"otel-arrow-rust",
|
"otel-arrow-rust",
|
||||||
"parking_lot 0.12.4",
|
"parking_lot 0.12.4",
|
||||||
"permutation",
|
"permutation",
|
||||||
|
"pg_interval",
|
||||||
"pgwire",
|
"pgwire",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"pipeline",
|
"pipeline",
|
||||||
@@ -11624,6 +11647,7 @@ dependencies = [
|
|||||||
"tower 0.5.2",
|
"tower 0.5.2",
|
||||||
"tower-http 0.6.6",
|
"tower-http 0.6.6",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-opentelemetry",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
"uuid",
|
"uuid",
|
||||||
"vrl",
|
"vrl",
|
||||||
@@ -11632,7 +11656,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "session"
|
name = "session"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.8.12",
|
"ahash 0.8.12",
|
||||||
"api",
|
"api",
|
||||||
@@ -11966,7 +11990,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sql"
|
name = "sql"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arrow-buffer",
|
"arrow-buffer",
|
||||||
@@ -12026,7 +12050,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlness-runner"
|
name = "sqlness-runner"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"clap 4.5.40",
|
"clap 4.5.40",
|
||||||
@@ -12303,7 +12327,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "standalone"
|
name = "standalone"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"catalog",
|
"catalog",
|
||||||
@@ -12344,7 +12368,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "store-api"
|
name = "store-api"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"aquamarine",
|
"aquamarine",
|
||||||
@@ -12557,7 +12581,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "substrait"
|
name = "substrait"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -12680,7 +12704,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "table"
|
name = "table"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -12919,7 +12943,7 @@ dependencies = [
|
|||||||
"getrandom 0.3.3",
|
"getrandom 0.3.3",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 1.0.7",
|
"rustix 1.0.7",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -12949,7 +12973,7 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tests-fuzz"
|
name = "tests-fuzz"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -12993,7 +13017,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tests-integration"
|
name = "tests-integration"
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"api",
|
"api",
|
||||||
"arrow-flight",
|
"arrow-flight",
|
||||||
@@ -13043,6 +13067,7 @@ dependencies = [
|
|||||||
"loki-proto",
|
"loki-proto",
|
||||||
"meta-client",
|
"meta-client",
|
||||||
"meta-srv",
|
"meta-srv",
|
||||||
|
"mito2",
|
||||||
"moka",
|
"moka",
|
||||||
"mysql_async",
|
"mysql_async",
|
||||||
"object-store",
|
"object-store",
|
||||||
@@ -13067,7 +13092,7 @@ dependencies = [
|
|||||||
"sqlx",
|
"sqlx",
|
||||||
"standalone",
|
"standalone",
|
||||||
"store-api",
|
"store-api",
|
||||||
"substrait 1.0.0-beta.1",
|
"substrait 1.0.0-beta.2",
|
||||||
"table",
|
"table",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"time",
|
"time",
|
||||||
|
|||||||
31
Cargo.toml
31
Cargo.toml
@@ -74,7 +74,7 @@ members = [
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "1.0.0-beta.1"
|
version = "1.0.0-beta.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ datafusion-functions = "50"
|
|||||||
datafusion-functions-aggregate-common = "50"
|
datafusion-functions-aggregate-common = "50"
|
||||||
datafusion-optimizer = "50"
|
datafusion-optimizer = "50"
|
||||||
datafusion-orc = "0.5"
|
datafusion-orc = "0.5"
|
||||||
datafusion-pg-catalog = "0.12.1"
|
datafusion-pg-catalog = "0.12.2"
|
||||||
datafusion-physical-expr = "50"
|
datafusion-physical-expr = "50"
|
||||||
datafusion-physical-plan = "50"
|
datafusion-physical-plan = "50"
|
||||||
datafusion-sql = "50"
|
datafusion-sql = "50"
|
||||||
@@ -148,7 +148,7 @@ etcd-client = { git = "https://github.com/GreptimeTeam/etcd-client", rev = "f62d
|
|||||||
fst = "0.4.7"
|
fst = "0.4.7"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "14b9dc40bdc8288742b0cefc7bb024303b7429ef" }
|
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "0df99f09f1d6785055b2d9da96fc4ecc2bdf6803" }
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
http = "1"
|
http = "1"
|
||||||
humantime = "2.1"
|
humantime = "2.1"
|
||||||
@@ -234,6 +234,7 @@ tower = "0.5"
|
|||||||
tower-http = "0.6"
|
tower-http = "0.6"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-appender = "0.2"
|
tracing-appender = "0.2"
|
||||||
|
tracing-opentelemetry = "0.31.0"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "fmt"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "fmt"] }
|
||||||
typetag = "0.2"
|
typetag = "0.2"
|
||||||
uuid = { version = "1.17", features = ["serde", "v4", "fast-rng"] }
|
uuid = { version = "1.17", features = ["serde", "v4", "fast-rng"] }
|
||||||
@@ -315,18 +316,18 @@ git = "https://github.com/GreptimeTeam/greptime-meter.git"
|
|||||||
rev = "5618e779cf2bb4755b499c630fba4c35e91898cb"
|
rev = "5618e779cf2bb4755b499c630fba4c35e91898cb"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
datafusion = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-expr = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-expr = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-functions = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-functions = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-functions-aggregate-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-functions-aggregate-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-optimizer = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-optimizer = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-physical-expr = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-physical-expr = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-physical-expr-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-physical-expr-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-physical-plan = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-physical-plan = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-datasource = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-datasource = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-sql = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-sql = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
datafusion-substrait = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" }
|
datafusion-substrait = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "7f8ea0a45748ed32695757368f847ab9ac7b6c82" }
|
||||||
sqlparser = { git = "https://github.com/GreptimeTeam/sqlparser-rs.git", rev = "4b519a5caa95472cc3988f5556813a583dd35af1" } # branch = "v0.58.x"
|
sqlparser = { git = "https://github.com/GreptimeTeam/sqlparser-rs.git", rev = "4b519a5caa95472cc3988f5556813a583dd35af1" } # branch = "v0.58.x"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -17,6 +17,8 @@ CARGO_REGISTRY_CACHE ?= ${HOME}/.cargo/registry
|
|||||||
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
|
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
|
||||||
OUTPUT_DIR := $(shell if [ "$(RELEASE)" = "true" ]; then echo "release"; elif [ ! -z "$(CARGO_PROFILE)" ]; then echo "$(CARGO_PROFILE)" ; else echo "debug"; fi)
|
OUTPUT_DIR := $(shell if [ "$(RELEASE)" = "true" ]; then echo "release"; elif [ ! -z "$(CARGO_PROFILE)" ]; then echo "$(CARGO_PROFILE)" ; else echo "debug"; fi)
|
||||||
SQLNESS_OPTS ?=
|
SQLNESS_OPTS ?=
|
||||||
|
EXTRA_BUILD_ENVS ?=
|
||||||
|
ASSEMBLED_EXTRA_BUILD_ENV := $(foreach var,$(EXTRA_BUILD_ENVS),-e $(var))
|
||||||
|
|
||||||
# The arguments for running integration tests.
|
# The arguments for running integration tests.
|
||||||
ETCD_VERSION ?= v3.5.9
|
ETCD_VERSION ?= v3.5.9
|
||||||
@@ -83,6 +85,7 @@ build: ## Build debug version greptime.
|
|||||||
.PHONY: build-by-dev-builder
|
.PHONY: build-by-dev-builder
|
||||||
build-by-dev-builder: ## Build greptime by dev-builder.
|
build-by-dev-builder: ## Build greptime by dev-builder.
|
||||||
docker run --network=host \
|
docker run --network=host \
|
||||||
|
${ASSEMBLED_EXTRA_BUILD_ENV} \
|
||||||
-v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry \
|
-v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry \
|
||||||
-w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_BUILDER_IMAGE_TAG} \
|
-w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_BUILDER_IMAGE_TAG} \
|
||||||
make build \
|
make build \
|
||||||
|
|||||||
61
README.md
61
README.md
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h3 align="center">
|
<h3 align="center">
|
||||||
<a href="https://docs.greptime.com/">User Guide</a> |
|
<a href="https://docs.greptime.com/user-guide/overview/">User Guide</a> |
|
||||||
<a href="https://greptimedb.rs/">API Docs</a> |
|
<a href="https://greptimedb.rs/">API Docs</a> |
|
||||||
<a href="https://github.com/GreptimeTeam/greptimedb/issues/5446">Roadmap 2025</a>
|
<a href="https://github.com/GreptimeTeam/greptimedb/issues/5446">Roadmap 2025</a>
|
||||||
</h4>
|
</h4>
|
||||||
@@ -66,17 +66,24 @@
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
**GreptimeDB** is an open-source, cloud-native database purpose-built for the unified collection and analysis of observability data (metrics, logs, and traces). Whether you’re operating on the edge, in the cloud, or across hybrid environments, GreptimeDB empowers real-time insights at massive scale — all in one system.
|
**GreptimeDB** is an open-source, cloud-native database that unifies metrics, logs, and traces, enabling real-time observability at any scale — across edge, cloud, and hybrid environments.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
| Feature | Description |
|
| Feature | Description |
|
||||||
| --------- | ----------- |
|
| --------- | ----------- |
|
||||||
| [Unified Observability Data](https://docs.greptime.com/user-guide/concepts/why-greptimedb) | Store metrics, logs, and traces as timestamped, contextual wide events. Query via [SQL](https://docs.greptime.com/user-guide/query-data/sql), [PromQL](https://docs.greptime.com/user-guide/query-data/promql), and [streaming](https://docs.greptime.com/user-guide/flow-computation/overview). |
|
| [All-in-One Observability](https://docs.greptime.com/user-guide/concepts/why-greptimedb) | OpenTelemetry-native platform unifying metrics, logs, and traces. Query via [SQL](https://docs.greptime.com/user-guide/query-data/sql), [PromQL](https://docs.greptime.com/user-guide/query-data/promql), and [Flow](https://docs.greptime.com/user-guide/flow-computation/overview). |
|
||||||
| [High Performance & Cost Effective](https://docs.greptime.com/user-guide/manage-data/data-index) | Written in Rust, with a distributed query engine, [rich indexing](https://docs.greptime.com/user-guide/manage-data/data-index), and optimized columnar storage, delivering sub-second responses at PB scale. |
|
| [High Performance](https://docs.greptime.com/user-guide/manage-data/data-index) | Written in Rust with [rich indexing](https://docs.greptime.com/user-guide/manage-data/data-index) (inverted, fulltext, skipping, vector), delivering sub-second responses at PB scale. |
|
||||||
| [Cloud-Native Architecture](https://docs.greptime.com/user-guide/concepts/architecture) | Designed for [Kubernetes](https://docs.greptime.com/user-guide/deployments-administration/deploy-on-kubernetes/greptimedb-operator-management), with compute/storage separation, native object storage (AWS S3, Azure Blob, etc.) and seamless cross-cloud access. |
|
| [Cost Efficiency](https://docs.greptime.com/user-guide/concepts/architecture) | 50x lower operational and storage costs with compute-storage separation and native object storage (S3, Azure Blob, etc.). |
|
||||||
| [Developer-Friendly](https://docs.greptime.com/user-guide/protocols/overview) | Access via SQL/PromQL interfaces, REST API, MySQL/PostgreSQL protocols, and popular ingestion [protocols](https://docs.greptime.com/user-guide/protocols/overview). |
|
| [Cloud-Native & Scalable](https://docs.greptime.com/user-guide/deployments-administration/deploy-on-kubernetes/greptimedb-operator-management) | Purpose-built for [Kubernetes](https://docs.greptime.com/user-guide/deployments-administration/deploy-on-kubernetes/greptimedb-operator-management) with unlimited cross-cloud scaling, handling hundreds of thousands of concurrent requests. |
|
||||||
| [Flexible Deployment](https://docs.greptime.com/user-guide/deployments-administration/overview) | Deploy anywhere: edge (including ARM/[Android](https://docs.greptime.com/user-guide/deployments-administration/run-on-android)) or cloud, with unified APIs and efficient data sync. |
|
| [Developer-Friendly](https://docs.greptime.com/user-guide/protocols/overview) | SQL/PromQL interfaces, built-in web dashboard, REST API, MySQL/PostgreSQL protocol compatibility, and native [OpenTelemetry](https://docs.greptime.com/user-guide/ingest-data/for-observability/opentelemetry/) support. |
|
||||||
|
| [Flexible Deployment](https://docs.greptime.com/user-guide/deployments-administration/overview) | Deploy anywhere from ARM-based edge devices (including [Android](https://docs.greptime.com/user-guide/deployments-administration/run-on-android)) to cloud, with unified APIs and efficient data sync. |
|
||||||
|
|
||||||
|
✅ **Perfect for:**
|
||||||
|
- Unified observability stack replacing Prometheus + Loki + Tempo
|
||||||
|
- Large-scale metrics with high cardinality (millions to billions of time series)
|
||||||
|
- Large-scale observability platform requiring cost efficiency and scalability
|
||||||
|
- IoT and edge computing with resource and bandwidth constraints
|
||||||
|
|
||||||
Learn more in [Why GreptimeDB](https://docs.greptime.com/user-guide/concepts/why-greptimedb) and [Observability 2.0 and the Database for It](https://greptime.com/blogs/2025-04-25-greptimedb-observability2-new-database).
|
Learn more in [Why GreptimeDB](https://docs.greptime.com/user-guide/concepts/why-greptimedb) and [Observability 2.0 and the Database for It](https://greptime.com/blogs/2025-04-25-greptimedb-observability2-new-database).
|
||||||
|
|
||||||
@@ -85,10 +92,10 @@ Learn more in [Why GreptimeDB](https://docs.greptime.com/user-guide/concepts/why
|
|||||||
| Feature | GreptimeDB | Traditional TSDB | Log Stores |
|
| Feature | GreptimeDB | Traditional TSDB | Log Stores |
|
||||||
|----------------------------------|-----------------------|--------------------|-----------------|
|
|----------------------------------|-----------------------|--------------------|-----------------|
|
||||||
| Data Types | Metrics, Logs, Traces | Metrics only | Logs only |
|
| Data Types | Metrics, Logs, Traces | Metrics only | Logs only |
|
||||||
| Query Language | SQL, PromQL, Streaming| Custom/PromQL | Custom/DSL |
|
| Query Language | SQL, PromQL | Custom/PromQL | Custom/DSL |
|
||||||
| Deployment | Edge + Cloud | Cloud/On-prem | Mostly central |
|
| Deployment | Edge + Cloud | Cloud/On-prem | Mostly central |
|
||||||
| Indexing & Performance | PB-Scale, Sub-second | Varies | Varies |
|
| Indexing & Performance | PB-Scale, Sub-second | Varies | Varies |
|
||||||
| Integration | REST, SQL, Common protocols | Varies | Varies |
|
| Integration | REST API, SQL, Common protocols | Varies | Varies |
|
||||||
|
|
||||||
**Performance:**
|
**Performance:**
|
||||||
* [GreptimeDB tops JSONBench's billion-record cold run test!](https://greptime.com/blogs/2025-03-18-jsonbench-greptimedb-performance)
|
* [GreptimeDB tops JSONBench's billion-record cold run test!](https://greptime.com/blogs/2025-03-18-jsonbench-greptimedb-performance)
|
||||||
@@ -98,8 +105,14 @@ Read [more benchmark reports](https://docs.greptime.com/user-guide/concepts/feat
|
|||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
* Read the [architecture](https://docs.greptime.com/contributor-guide/overview/#architecture) document.
|
GreptimeDB can run in two modes:
|
||||||
* [DeepWiki](https://deepwiki.com/GreptimeTeam/greptimedb/1-overview) provides an in-depth look at GreptimeDB:
|
* **Standalone Mode** - Single binary for development and small deployments
|
||||||
|
* **Distributed Mode** - Separate components for production scale:
|
||||||
|
- Frontend: Query processing and protocol handling
|
||||||
|
- Datanode: Data storage and retrieval
|
||||||
|
- Metasrv: Metadata management and coordination
|
||||||
|
|
||||||
|
Read the [architecture](https://docs.greptime.com/contributor-guide/overview/#architecture) document. [DeepWiki](https://deepwiki.com/GreptimeTeam/greptimedb/1-overview) provides an in-depth look at GreptimeDB:
|
||||||
<img alt="GreptimeDB System Overview" src="docs/architecture.png">
|
<img alt="GreptimeDB System Overview" src="docs/architecture.png">
|
||||||
|
|
||||||
## Try GreptimeDB
|
## Try GreptimeDB
|
||||||
@@ -119,7 +132,8 @@ docker run -p 127.0.0.1:4000-4003:4000-4003 \
|
|||||||
--postgres-addr 0.0.0.0:4003
|
--postgres-addr 0.0.0.0:4003
|
||||||
```
|
```
|
||||||
Dashboard: [http://localhost:4000/dashboard](http://localhost:4000/dashboard)
|
Dashboard: [http://localhost:4000/dashboard](http://localhost:4000/dashboard)
|
||||||
[Full Install Guide](https://docs.greptime.com/getting-started/installation/overview)
|
|
||||||
|
Read more in the [full Install Guide](https://docs.greptime.com/getting-started/installation/overview).
|
||||||
|
|
||||||
**Troubleshooting:**
|
**Troubleshooting:**
|
||||||
* Cannot connect to the database? Ensure that ports `4000`, `4001`, `4002`, and `4003` are not blocked by a firewall or used by other services.
|
* Cannot connect to the database? Ensure that ports `4000`, `4001`, `4002`, and `4003` are not blocked by a firewall or used by other services.
|
||||||
@@ -148,21 +162,26 @@ cargo run -- standalone start
|
|||||||
|
|
||||||
## Tools & Extensions
|
## Tools & Extensions
|
||||||
|
|
||||||
- **Kubernetes:** [GreptimeDB Operator](https://github.com/GrepTimeTeam/greptimedb-operator)
|
- **Kubernetes**: [GreptimeDB Operator](https://github.com/GrepTimeTeam/greptimedb-operator)
|
||||||
- **Helm Charts:** [Greptime Helm Charts](https://github.com/GreptimeTeam/helm-charts)
|
- **Helm Charts**: [Greptime Helm Charts](https://github.com/GreptimeTeam/helm-charts)
|
||||||
- **Dashboard:** [Web UI](https://github.com/GreptimeTeam/dashboard)
|
- **Dashboard**: [Web UI](https://github.com/GreptimeTeam/dashboard)
|
||||||
- **SDKs/Ingester:** [Go](https://github.com/GreptimeTeam/greptimedb-ingester-go), [Java](https://github.com/GreptimeTeam/greptimedb-ingester-java), [C++](https://github.com/GreptimeTeam/greptimedb-ingester-cpp), [Erlang](https://github.com/GreptimeTeam/greptimedb-ingester-erl), [Rust](https://github.com/GreptimeTeam/greptimedb-ingester-rust), [JS](https://github.com/GreptimeTeam/greptimedb-ingester-js)
|
- **gRPC Ingester**: [Go](https://github.com/GreptimeTeam/greptimedb-ingester-go), [Java](https://github.com/GreptimeTeam/greptimedb-ingester-java), [C++](https://github.com/GreptimeTeam/greptimedb-ingester-cpp), [Erlang](https://github.com/GreptimeTeam/greptimedb-ingester-erl), [Rust](https://github.com/GreptimeTeam/greptimedb-ingester-rust)
|
||||||
- **Grafana**: [Official Dashboard](https://github.com/GreptimeTeam/greptimedb/blob/main/grafana/README.md)
|
- **Grafana Data Source**: [GreptimeDB Grafana data source plugin](https://github.com/GreptimeTeam/greptimedb-grafana-datasource)
|
||||||
|
- **Grafana Dashboard**: [Official Dashboard for monitoring](https://github.com/GreptimeTeam/greptimedb/blob/main/grafana/README.md)
|
||||||
|
|
||||||
## Project Status
|
## Project Status
|
||||||
|
|
||||||
> **Status:** Beta.
|
> **Status:** Beta — marching toward v1.0 GA!
|
||||||
> **GA (v1.0):** Targeted for mid 2025.
|
> **GA (v1.0):** January 10, 2026
|
||||||
|
|
||||||
- Being used in production by early adopters
|
- Deployed in production by open-source projects and commercial users
|
||||||
- Stable, actively maintained, with regular releases ([version info](https://docs.greptime.com/nightly/reference/about-greptimedb-version))
|
- Stable, actively maintained, with regular releases ([version info](https://docs.greptime.com/nightly/reference/about-greptimedb-version))
|
||||||
- Suitable for evaluation and pilot deployments
|
- Suitable for evaluation and pilot deployments
|
||||||
|
|
||||||
|
GreptimeDB v1.0 represents a major milestone toward maturity — marking stable APIs, production readiness, and proven performance.
|
||||||
|
|
||||||
|
**Roadmap:** Beta1 (Nov 10) → Beta2 (Nov 24) → RC1 (Dec 8) → GA (Jan 10, 2026), please read [v1.0 highlights and release plan](https://greptime.com/blogs/2025-11-05-greptimedb-v1-highlights) for details.
|
||||||
|
|
||||||
For production use, we recommend using the latest stable release.
|
For production use, we recommend using the latest stable release.
|
||||||
[](https://www.star-history.com/#GreptimeTeam/GreptimeDB&Date)
|
[](https://www.star-history.com/#GreptimeTeam/GreptimeDB&Date)
|
||||||
|
|
||||||
@@ -203,5 +222,5 @@ Special thanks to all contributors! See [AUTHORS.md](https://github.com/Greptime
|
|||||||
|
|
||||||
- Uses [Apache Arrow™](https://arrow.apache.org/) (memory model)
|
- Uses [Apache Arrow™](https://arrow.apache.org/) (memory model)
|
||||||
- [Apache Parquet™](https://parquet.apache.org/) (file storage)
|
- [Apache Parquet™](https://parquet.apache.org/) (file storage)
|
||||||
- [Apache Arrow DataFusion™](https://arrow.apache.org/datafusion/) (query engine)
|
- [Apache DataFusion™](https://arrow.apache.org/datafusion/) (query engine)
|
||||||
- [Apache OpenDAL™](https://opendal.apache.org/) (data access abstraction)
|
- [Apache OpenDAL™](https://opendal.apache.org/) (data access abstraction)
|
||||||
|
|||||||
@@ -210,14 +210,6 @@
|
|||||||
| `slow_query.record_type` | String | Unset | The record type of slow queries. It can be `system_table` or `log`. |
|
| `slow_query.record_type` | String | Unset | The record type of slow queries. It can be `system_table` or `log`. |
|
||||||
| `slow_query.threshold` | String | Unset | The threshold of slow query. |
|
| `slow_query.threshold` | String | Unset | The threshold of slow query. |
|
||||||
| `slow_query.sample_ratio` | Float | Unset | The sampling ratio of slow query log. The value should be in the range of (0, 1]. |
|
| `slow_query.sample_ratio` | Float | Unset | The sampling ratio of slow query log. The value should be in the range of (0, 1]. |
|
||||||
| `export_metrics` | -- | -- | The standalone can export its metrics and send to Prometheus compatible service (e.g. `greptimedb`) from remote-write API.<br/>This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
|
|
||||||
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
|
|
||||||
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
|
|
||||||
| `export_metrics.self_import` | -- | -- | For `standalone` mode, `self_import` is recommended to collect metrics generated by itself<br/>You must create the database before enabling it. |
|
|
||||||
| `export_metrics.self_import.db` | String | Unset | -- |
|
|
||||||
| `export_metrics.remote_write` | -- | -- | -- |
|
|
||||||
| `export_metrics.remote_write.url` | String | `""` | The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`. |
|
|
||||||
| `export_metrics.remote_write.headers` | InlineTable | -- | HTTP headers of Prometheus remote-write carry. |
|
|
||||||
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
||||||
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
||||||
| `memory` | -- | -- | The memory options. |
|
| `memory` | -- | -- | The memory options. |
|
||||||
@@ -335,12 +327,6 @@
|
|||||||
| `slow_query.threshold` | String | `30s` | The threshold of slow query. It can be human readable time string, for example: `10s`, `100ms`, `1s`. |
|
| `slow_query.threshold` | String | `30s` | The threshold of slow query. It can be human readable time string, for example: `10s`, `100ms`, `1s`. |
|
||||||
| `slow_query.sample_ratio` | Float | `1.0` | The sampling ratio of slow query log. The value should be in the range of (0, 1]. For example, `0.1` means 10% of the slow queries will be logged and `1.0` means all slow queries will be logged. |
|
| `slow_query.sample_ratio` | Float | `1.0` | The sampling ratio of slow query log. The value should be in the range of (0, 1]. For example, `0.1` means 10% of the slow queries will be logged and `1.0` means all slow queries will be logged. |
|
||||||
| `slow_query.ttl` | String | `90d` | The TTL of the `slow_queries` system table. Default is `90d` when `record_type` is `system_table`. |
|
| `slow_query.ttl` | String | `90d` | The TTL of the `slow_queries` system table. Default is `90d` when `record_type` is `system_table`. |
|
||||||
| `export_metrics` | -- | -- | The frontend can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.<br/>This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
|
|
||||||
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
|
|
||||||
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
|
|
||||||
| `export_metrics.remote_write` | -- | -- | -- |
|
|
||||||
| `export_metrics.remote_write.url` | String | `""` | The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`. |
|
|
||||||
| `export_metrics.remote_write.headers` | InlineTable | -- | HTTP headers of Prometheus remote-write carry. |
|
|
||||||
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
||||||
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
||||||
| `memory` | -- | -- | The memory options. |
|
| `memory` | -- | -- | The memory options. |
|
||||||
@@ -354,7 +340,7 @@
|
|||||||
| Key | Type | Default | Descriptions |
|
| Key | Type | Default | Descriptions |
|
||||||
| --- | -----| ------- | ----------- |
|
| --- | -----| ------- | ----------- |
|
||||||
| `data_home` | String | `./greptimedb_data` | The working home directory. |
|
| `data_home` | String | `./greptimedb_data` | The working home directory. |
|
||||||
| `store_addrs` | Array | -- | Store server address default to etcd store.<br/>For postgres store, the format is:<br/>"password=password dbname=postgres user=postgres host=localhost port=5432"<br/>For etcd store, the format is:<br/>"127.0.0.1:2379" |
|
| `store_addrs` | Array | -- | Store server address(es). The format depends on the selected backend.<br/><br/>For etcd: a list of "host:port" endpoints.<br/>e.g. ["192.168.1.1:2379", "192.168.1.2:2379"]<br/><br/>For PostgreSQL: a connection string in libpq format or URI.<br/>e.g.<br/>- "host=localhost port=5432 user=postgres password=<PASSWORD> dbname=postgres"<br/>- "postgresql://user:password@localhost:5432/mydb?connect_timeout=10"<br/>The detail see: https://docs.rs/tokio-postgres/latest/tokio_postgres/config/struct.Config.html<br/><br/>For mysql store, the format is a MySQL connection URL.<br/>e.g. "mysql://user:password@localhost:3306/greptime_meta?ssl-mode=VERIFY_CA&ssl-ca=/path/to/ca.pem" |
|
||||||
| `store_key_prefix` | String | `""` | If it's not empty, the metasrv will store all data with this key prefix. |
|
| `store_key_prefix` | String | `""` | If it's not empty, the metasrv will store all data with this key prefix. |
|
||||||
| `backend` | String | `etcd_store` | The datastore for meta server.<br/>Available values:<br/>- `etcd_store` (default value)<br/>- `memory_store`<br/>- `postgres_store`<br/>- `mysql_store` |
|
| `backend` | String | `etcd_store` | The datastore for meta server.<br/>Available values:<br/>- `etcd_store` (default value)<br/>- `memory_store`<br/>- `postgres_store`<br/>- `mysql_store` |
|
||||||
| `meta_table_name` | String | `greptime_metakv` | Table name in RDS to store metadata. Effect when using a RDS kvbackend.<br/>**Only used when backend is `postgres_store`.** |
|
| `meta_table_name` | String | `greptime_metakv` | Table name in RDS to store metadata. Effect when using a RDS kvbackend.<br/>**Only used when backend is `postgres_store`.** |
|
||||||
@@ -370,12 +356,11 @@
|
|||||||
| `runtime` | -- | -- | The runtime options. |
|
| `runtime` | -- | -- | The runtime options. |
|
||||||
| `runtime.global_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
|
| `runtime.global_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
|
||||||
| `runtime.compact_rt_size` | Integer | `4` | The number of threads to execute the runtime for global write operations. |
|
| `runtime.compact_rt_size` | Integer | `4` | The number of threads to execute the runtime for global write operations. |
|
||||||
| `backend_tls` | -- | -- | TLS configuration for kv store backend (applicable for etcd, PostgreSQL, and MySQL backends)<br/>When using etcd, PostgreSQL, or MySQL as metadata store, you can configure TLS here |
|
| `backend_tls` | -- | -- | TLS configuration for kv store backend (applicable for etcd, PostgreSQL, and MySQL backends)<br/>When using etcd, PostgreSQL, or MySQL as metadata store, you can configure TLS here<br/><br/>Note: if TLS is configured in both this section and the `store_addrs` connection string, the<br/>settings here will override the TLS settings in `store_addrs`. |
|
||||||
| `backend_tls.mode` | String | `prefer` | TLS mode, refer to https://www.postgresql.org/docs/current/libpq-ssl.html<br/>- "disable" - No TLS<br/>- "prefer" (default) - Try TLS, fallback to plain<br/>- "require" - Require TLS<br/>- "verify_ca" - Require TLS and verify CA<br/>- "verify_full" - Require TLS and verify hostname |
|
| `backend_tls.mode` | String | `prefer` | TLS mode, refer to https://www.postgresql.org/docs/current/libpq-ssl.html<br/>- "disable" - No TLS<br/>- "prefer" (default) - Try TLS, fallback to plain<br/>- "require" - Require TLS<br/>- "verify_ca" - Require TLS and verify CA<br/>- "verify_full" - Require TLS and verify hostname |
|
||||||
| `backend_tls.cert_path` | String | `""` | Path to client certificate file (for client authentication)<br/>Like "/path/to/client.crt" |
|
| `backend_tls.cert_path` | String | `""` | Path to client certificate file (for client authentication)<br/>Like "/path/to/client.crt" |
|
||||||
| `backend_tls.key_path` | String | `""` | Path to client private key file (for client authentication)<br/>Like "/path/to/client.key" |
|
| `backend_tls.key_path` | String | `""` | Path to client private key file (for client authentication)<br/>Like "/path/to/client.key" |
|
||||||
| `backend_tls.ca_cert_path` | String | `""` | Path to CA certificate file (for server certificate verification)<br/>Required when using custom CAs or self-signed certificates<br/>Leave empty to use system root certificates only<br/>Like "/path/to/ca.crt" |
|
| `backend_tls.ca_cert_path` | String | `""` | Path to CA certificate file (for server certificate verification)<br/>Required when using custom CAs or self-signed certificates<br/>Leave empty to use system root certificates only<br/>Like "/path/to/ca.crt" |
|
||||||
| `backend_tls.watch` | Bool | `false` | Watch for certificate file changes and auto reload |
|
|
||||||
| `grpc` | -- | -- | The gRPC server options. |
|
| `grpc` | -- | -- | The gRPC server options. |
|
||||||
| `grpc.bind_addr` | String | `127.0.0.1:3002` | The address to bind the gRPC server. |
|
| `grpc.bind_addr` | String | `127.0.0.1:3002` | The address to bind the gRPC server. |
|
||||||
| `grpc.server_addr` | String | `127.0.0.1:3002` | The communication server address for the frontend and datanode to connect to metasrv.<br/>If left empty or unset, the server will automatically use the IP address of the first network interface<br/>on the host, with the same port number as the one specified in `bind_addr`. |
|
| `grpc.server_addr` | String | `127.0.0.1:3002` | The communication server address for the frontend and datanode to connect to metasrv.<br/>If left empty or unset, the server will automatically use the IP address of the first network interface<br/>on the host, with the same port number as the one specified in `bind_addr`. |
|
||||||
@@ -430,12 +415,6 @@
|
|||||||
| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http |
|
| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http |
|
||||||
| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.<br/>Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.<br/>ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
|
| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.<br/>Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.<br/>ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
|
||||||
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
|
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
|
||||||
| `export_metrics` | -- | -- | The metasrv can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.<br/>This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
|
|
||||||
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
|
|
||||||
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
|
|
||||||
| `export_metrics.remote_write` | -- | -- | -- |
|
|
||||||
| `export_metrics.remote_write.url` | String | `""` | The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`. |
|
|
||||||
| `export_metrics.remote_write.headers` | InlineTable | -- | HTTP headers of Prometheus remote-write carry. |
|
|
||||||
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
||||||
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
||||||
| `memory` | -- | -- | The memory options. |
|
| `memory` | -- | -- | The memory options. |
|
||||||
@@ -608,12 +587,6 @@
|
|||||||
| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http |
|
| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http |
|
||||||
| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.<br/>Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.<br/>ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
|
| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.<br/>Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.<br/>ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
|
||||||
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
|
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
|
||||||
| `export_metrics` | -- | -- | The datanode can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.<br/>This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
|
|
||||||
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
|
|
||||||
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
|
|
||||||
| `export_metrics.remote_write` | -- | -- | -- |
|
|
||||||
| `export_metrics.remote_write.url` | String | `""` | The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`. |
|
|
||||||
| `export_metrics.remote_write.headers` | InlineTable | -- | HTTP headers of Prometheus remote-write carry. |
|
|
||||||
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
|
||||||
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
|
||||||
| `memory` | -- | -- | The memory options. |
|
| `memory` | -- | -- | The memory options. |
|
||||||
|
|||||||
@@ -712,21 +712,6 @@ otlp_export_protocol = "http"
|
|||||||
[logging.tracing_sample_ratio]
|
[logging.tracing_sample_ratio]
|
||||||
default_ratio = 1.0
|
default_ratio = 1.0
|
||||||
|
|
||||||
## The datanode can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.
|
|
||||||
## This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape.
|
|
||||||
[export_metrics]
|
|
||||||
## whether enable export metrics.
|
|
||||||
enable = false
|
|
||||||
## The interval of export metrics.
|
|
||||||
write_interval = "30s"
|
|
||||||
|
|
||||||
[export_metrics.remote_write]
|
|
||||||
## The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`.
|
|
||||||
url = ""
|
|
||||||
|
|
||||||
## HTTP headers of Prometheus remote-write carry.
|
|
||||||
headers = { }
|
|
||||||
|
|
||||||
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
||||||
#+ [tracing]
|
#+ [tracing]
|
||||||
## The tokio console address.
|
## The tokio console address.
|
||||||
|
|||||||
@@ -329,21 +329,6 @@ sample_ratio = 1.0
|
|||||||
## The TTL of the `slow_queries` system table. Default is `90d` when `record_type` is `system_table`.
|
## The TTL of the `slow_queries` system table. Default is `90d` when `record_type` is `system_table`.
|
||||||
ttl = "90d"
|
ttl = "90d"
|
||||||
|
|
||||||
## The frontend can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.
|
|
||||||
## This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape.
|
|
||||||
[export_metrics]
|
|
||||||
## whether enable export metrics.
|
|
||||||
enable = false
|
|
||||||
## The interval of export metrics.
|
|
||||||
write_interval = "30s"
|
|
||||||
|
|
||||||
[export_metrics.remote_write]
|
|
||||||
## The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`.
|
|
||||||
url = ""
|
|
||||||
|
|
||||||
## HTTP headers of Prometheus remote-write carry.
|
|
||||||
headers = { }
|
|
||||||
|
|
||||||
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
||||||
#+ [tracing]
|
#+ [tracing]
|
||||||
## The tokio console address.
|
## The tokio console address.
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
## The working home directory.
|
## The working home directory.
|
||||||
data_home = "./greptimedb_data"
|
data_home = "./greptimedb_data"
|
||||||
|
|
||||||
## Store server address default to etcd store.
|
## Store server address(es). The format depends on the selected backend.
|
||||||
## For postgres store, the format is:
|
##
|
||||||
## "password=password dbname=postgres user=postgres host=localhost port=5432"
|
## For etcd: a list of "host:port" endpoints.
|
||||||
## For etcd store, the format is:
|
## e.g. ["192.168.1.1:2379", "192.168.1.2:2379"]
|
||||||
## "127.0.0.1:2379"
|
##
|
||||||
|
## For PostgreSQL: a connection string in libpq format or URI.
|
||||||
|
## e.g.
|
||||||
|
## - "host=localhost port=5432 user=postgres password=<PASSWORD> dbname=postgres"
|
||||||
|
## - "postgresql://user:password@localhost:5432/mydb?connect_timeout=10"
|
||||||
|
## The detail see: https://docs.rs/tokio-postgres/latest/tokio_postgres/config/struct.Config.html
|
||||||
|
##
|
||||||
|
## For mysql store, the format is a MySQL connection URL.
|
||||||
|
## e.g. "mysql://user:password@localhost:3306/greptime_meta?ssl-mode=VERIFY_CA&ssl-ca=/path/to/ca.pem"
|
||||||
store_addrs = ["127.0.0.1:2379"]
|
store_addrs = ["127.0.0.1:2379"]
|
||||||
|
|
||||||
## If it's not empty, the metasrv will store all data with this key prefix.
|
## If it's not empty, the metasrv will store all data with this key prefix.
|
||||||
@@ -75,6 +83,9 @@ node_max_idle_time = "24hours"
|
|||||||
|
|
||||||
## TLS configuration for kv store backend (applicable for etcd, PostgreSQL, and MySQL backends)
|
## TLS configuration for kv store backend (applicable for etcd, PostgreSQL, and MySQL backends)
|
||||||
## When using etcd, PostgreSQL, or MySQL as metadata store, you can configure TLS here
|
## When using etcd, PostgreSQL, or MySQL as metadata store, you can configure TLS here
|
||||||
|
##
|
||||||
|
## Note: if TLS is configured in both this section and the `store_addrs` connection string, the
|
||||||
|
## settings here will override the TLS settings in `store_addrs`.
|
||||||
[backend_tls]
|
[backend_tls]
|
||||||
## TLS mode, refer to https://www.postgresql.org/docs/current/libpq-ssl.html
|
## TLS mode, refer to https://www.postgresql.org/docs/current/libpq-ssl.html
|
||||||
## - "disable" - No TLS
|
## - "disable" - No TLS
|
||||||
@@ -98,9 +109,6 @@ key_path = ""
|
|||||||
## Like "/path/to/ca.crt"
|
## Like "/path/to/ca.crt"
|
||||||
ca_cert_path = ""
|
ca_cert_path = ""
|
||||||
|
|
||||||
## Watch for certificate file changes and auto reload
|
|
||||||
watch = false
|
|
||||||
|
|
||||||
## The gRPC server options.
|
## The gRPC server options.
|
||||||
[grpc]
|
[grpc]
|
||||||
## The address to bind the gRPC server.
|
## The address to bind the gRPC server.
|
||||||
@@ -323,21 +331,6 @@ otlp_export_protocol = "http"
|
|||||||
[logging.tracing_sample_ratio]
|
[logging.tracing_sample_ratio]
|
||||||
default_ratio = 1.0
|
default_ratio = 1.0
|
||||||
|
|
||||||
## The metasrv can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.
|
|
||||||
## This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape.
|
|
||||||
[export_metrics]
|
|
||||||
## whether enable export metrics.
|
|
||||||
enable = false
|
|
||||||
## The interval of export metrics.
|
|
||||||
write_interval = "30s"
|
|
||||||
|
|
||||||
[export_metrics.remote_write]
|
|
||||||
## The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`.
|
|
||||||
url = ""
|
|
||||||
|
|
||||||
## HTTP headers of Prometheus remote-write carry.
|
|
||||||
headers = { }
|
|
||||||
|
|
||||||
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
||||||
#+ [tracing]
|
#+ [tracing]
|
||||||
## The tokio console address.
|
## The tokio console address.
|
||||||
|
|||||||
@@ -820,27 +820,6 @@ default_ratio = 1.0
|
|||||||
## @toml2docs:none-default
|
## @toml2docs:none-default
|
||||||
#+ sample_ratio = 1.0
|
#+ sample_ratio = 1.0
|
||||||
|
|
||||||
## The standalone can export its metrics and send to Prometheus compatible service (e.g. `greptimedb`) from remote-write API.
|
|
||||||
## This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape.
|
|
||||||
[export_metrics]
|
|
||||||
## whether enable export metrics.
|
|
||||||
enable = false
|
|
||||||
## The interval of export metrics.
|
|
||||||
write_interval = "30s"
|
|
||||||
|
|
||||||
## For `standalone` mode, `self_import` is recommended to collect metrics generated by itself
|
|
||||||
## You must create the database before enabling it.
|
|
||||||
[export_metrics.self_import]
|
|
||||||
## @toml2docs:none-default
|
|
||||||
db = "greptime_metrics"
|
|
||||||
|
|
||||||
[export_metrics.remote_write]
|
|
||||||
## The prometheus remote write endpoint that the metrics send to. The url example can be: `http://127.0.0.1:4000/v1/prometheus/write?db=greptime_metrics`.
|
|
||||||
url = ""
|
|
||||||
|
|
||||||
## HTTP headers of Prometheus remote-write carry.
|
|
||||||
headers = { }
|
|
||||||
|
|
||||||
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
## The tracing options. Only effect when compiled with `tokio-console` feature.
|
||||||
#+ [tracing]
|
#+ [tracing]
|
||||||
## The tokio console address.
|
## The tokio console address.
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
FROM centos:7 as builder
|
FROM centos:7 AS builder
|
||||||
|
|
||||||
ARG CARGO_PROFILE
|
ARG CARGO_PROFILE
|
||||||
ARG FEATURES
|
ARG FEATURES
|
||||||
ARG OUTPUT_DIR
|
ARG OUTPUT_DIR
|
||||||
|
|
||||||
ENV LANG en_US.utf8
|
ENV LANG=en_US.utf8
|
||||||
WORKDIR /greptimedb
|
WORKDIR /greptimedb
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
@@ -22,7 +22,7 @@ RUN unzip protoc-3.15.8-linux-x86_64.zip -d /usr/local/
|
|||||||
# Install Rust
|
# Install Rust
|
||||||
SHELL ["/bin/bash", "-c"]
|
SHELL ["/bin/bash", "-c"]
|
||||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
|
||||||
ENV PATH /usr/local/bin:/root/.cargo/bin/:$PATH
|
ENV PATH=/usr/local/bin:/root/.cargo/bin/:$PATH
|
||||||
|
|
||||||
# Build the project in release mode.
|
# Build the project in release mode.
|
||||||
RUN --mount=target=.,rw \
|
RUN --mount=target=.,rw \
|
||||||
@@ -33,7 +33,7 @@ RUN --mount=target=.,rw \
|
|||||||
TARGET_DIR=/out/target
|
TARGET_DIR=/out/target
|
||||||
|
|
||||||
# Export the binary to the clean image.
|
# Export the binary to the clean image.
|
||||||
FROM centos:7 as base
|
FROM centos:7 AS base
|
||||||
|
|
||||||
ARG OUTPUT_DIR
|
ARG OUTPUT_DIR
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ RUN yum install -y epel-release \
|
|||||||
|
|
||||||
WORKDIR /greptime
|
WORKDIR /greptime
|
||||||
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/
|
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/
|
||||||
ENV PATH /greptime/bin/:$PATH
|
ENV PATH=/greptime/bin/:$PATH
|
||||||
|
|
||||||
ENV MALLOC_CONF="prof:true,prof_active:false"
|
ENV MALLOC_CONF="prof:true,prof_active:false"
|
||||||
|
|
||||||
|
|||||||
65
docker/buildx/distroless/Dockerfile
Normal file
65
docker/buildx/distroless/Dockerfile
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
FROM ubuntu:22.04 AS builder
|
||||||
|
|
||||||
|
ARG CARGO_PROFILE
|
||||||
|
ARG FEATURES
|
||||||
|
ARG OUTPUT_DIR
|
||||||
|
|
||||||
|
ENV LANG=en_US.utf8
|
||||||
|
WORKDIR /greptimedb
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common
|
||||||
|
|
||||||
|
# Install dependencies.
|
||||||
|
RUN --mount=type=cache,target=/var/cache/apt \
|
||||||
|
apt-get update && apt-get install -y \
|
||||||
|
libssl-dev \
|
||||||
|
protobuf-compiler \
|
||||||
|
curl \
|
||||||
|
git \
|
||||||
|
build-essential \
|
||||||
|
pkg-config
|
||||||
|
|
||||||
|
# Install Rust.
|
||||||
|
SHELL ["/bin/bash", "-c"]
|
||||||
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
|
||||||
|
ENV PATH=/root/.cargo/bin/:$PATH
|
||||||
|
|
||||||
|
# Build the project in release mode.
|
||||||
|
RUN --mount=target=. \
|
||||||
|
--mount=type=cache,target=/root/.cargo/registry \
|
||||||
|
make build \
|
||||||
|
CARGO_PROFILE=${CARGO_PROFILE} \
|
||||||
|
FEATURES=${FEATURES} \
|
||||||
|
TARGET_DIR=/out/target
|
||||||
|
|
||||||
|
FROM ubuntu:22.04 AS libs
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
# Copy required library dependencies based on architecture
|
||||||
|
RUN if [ "$TARGETARCH" = "amd64" ]; then \
|
||||||
|
cp /lib/x86_64-linux-gnu/libz.so.1.2.11 /lib/x86_64-linux-gnu/libz.so.1; \
|
||||||
|
elif [ "$TARGETARCH" = "arm64" ]; then \
|
||||||
|
cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /lib/aarch64-linux-gnu/libz.so.1; \
|
||||||
|
else \
|
||||||
|
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Export the binary to the clean distroless image.
|
||||||
|
FROM gcr.io/distroless/cc-debian12:latest AS base
|
||||||
|
|
||||||
|
ARG OUTPUT_DIR
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
# Copy required library dependencies
|
||||||
|
COPY --from=libs /lib /lib
|
||||||
|
COPY --from=busybox:stable /bin/busybox /bin/busybox
|
||||||
|
|
||||||
|
WORKDIR /greptime
|
||||||
|
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/greptime
|
||||||
|
ENV PATH=/greptime/bin/:$PATH
|
||||||
|
|
||||||
|
ENV MALLOC_CONF="prof:true,prof_active:false"
|
||||||
|
|
||||||
|
ENTRYPOINT ["greptime"]
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
FROM ubuntu:22.04 as builder
|
FROM ubuntu:22.04 AS builder
|
||||||
|
|
||||||
ARG CARGO_PROFILE
|
ARG CARGO_PROFILE
|
||||||
ARG FEATURES
|
ARG FEATURES
|
||||||
ARG OUTPUT_DIR
|
ARG OUTPUT_DIR
|
||||||
|
|
||||||
ENV LANG en_US.utf8
|
ENV LANG=en_US.utf8
|
||||||
WORKDIR /greptimedb
|
WORKDIR /greptimedb
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
@@ -23,7 +23,7 @@ RUN --mount=type=cache,target=/var/cache/apt \
|
|||||||
# Install Rust.
|
# Install Rust.
|
||||||
SHELL ["/bin/bash", "-c"]
|
SHELL ["/bin/bash", "-c"]
|
||||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
|
||||||
ENV PATH /root/.cargo/bin/:$PATH
|
ENV PATH=/root/.cargo/bin/:$PATH
|
||||||
|
|
||||||
# Build the project in release mode.
|
# Build the project in release mode.
|
||||||
RUN --mount=target=. \
|
RUN --mount=target=. \
|
||||||
@@ -35,7 +35,7 @@ RUN --mount=target=. \
|
|||||||
|
|
||||||
# Export the binary to the clean image.
|
# Export the binary to the clean image.
|
||||||
# TODO(zyy17): Maybe should use the more secure container image.
|
# TODO(zyy17): Maybe should use the more secure container image.
|
||||||
FROM ubuntu:22.04 as base
|
FROM ubuntu:22.04 AS base
|
||||||
|
|
||||||
ARG OUTPUT_DIR
|
ARG OUTPUT_DIR
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get \
|
|||||||
|
|
||||||
WORKDIR /greptime
|
WORKDIR /greptime
|
||||||
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/
|
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/
|
||||||
ENV PATH /greptime/bin/:$PATH
|
ENV PATH=/greptime/bin/:$PATH
|
||||||
|
|
||||||
ENV MALLOC_CONF="prof:true,prof_active:false"
|
ENV MALLOC_CONF="prof:true,prof_active:false"
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ ARG TARGETARCH
|
|||||||
|
|
||||||
ADD $TARGETARCH/greptime /greptime/bin/
|
ADD $TARGETARCH/greptime /greptime/bin/
|
||||||
|
|
||||||
ENV PATH /greptime/bin/:$PATH
|
ENV PATH=/greptime/bin/:$PATH
|
||||||
|
|
||||||
ENV MALLOC_CONF="prof:true,prof_active:false"
|
ENV MALLOC_CONF="prof:true,prof_active:false"
|
||||||
|
|
||||||
|
|||||||
40
docker/ci/distroless/Dockerfile
Normal file
40
docker/ci/distroless/Dockerfile
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
FROM ubuntu:22.04 AS libs
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
# Copy required library dependencies based on architecture
|
||||||
|
# TARGETARCH values: amd64, arm64
|
||||||
|
# Ubuntu library paths: x86_64-linux-gnu, aarch64-linux-gnu
|
||||||
|
RUN if [ "$TARGETARCH" = "amd64" ]; then \
|
||||||
|
mkdir -p /output/x86_64-linux-gnu && \
|
||||||
|
cp /lib/x86_64-linux-gnu/libz.so.1.2.11 /output/x86_64-linux-gnu/libz.so.1; \
|
||||||
|
elif [ "$TARGETARCH" = "arm64" ]; then \
|
||||||
|
mkdir -p /output/aarch64-linux-gnu && \
|
||||||
|
cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /output/aarch64-linux-gnu/libz.so.1; \
|
||||||
|
else \
|
||||||
|
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
FROM gcr.io/distroless/cc-debian12:latest
|
||||||
|
|
||||||
|
# The root path under which contains all the dependencies to build this Dockerfile.
|
||||||
|
ARG DOCKER_BUILD_ROOT=.
|
||||||
|
# The binary name of GreptimeDB executable.
|
||||||
|
# Defaults to "greptime", but sometimes in other projects it might be different.
|
||||||
|
ARG TARGET_BIN=greptime
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
# Copy required library dependencies
|
||||||
|
COPY --from=libs /output /lib
|
||||||
|
COPY --from=busybox:stable /bin/busybox /bin/busybox
|
||||||
|
|
||||||
|
ADD $TARGETARCH/$TARGET_BIN /greptime/bin/
|
||||||
|
|
||||||
|
ENV PATH=/greptime/bin/:$PATH
|
||||||
|
|
||||||
|
ENV TARGET_BIN=$TARGET_BIN
|
||||||
|
|
||||||
|
ENV MALLOC_CONF="prof:true,prof_active:false"
|
||||||
|
|
||||||
|
ENTRYPOINT ["greptime"]
|
||||||
@@ -14,7 +14,7 @@ ARG TARGETARCH
|
|||||||
|
|
||||||
ADD $TARGETARCH/$TARGET_BIN /greptime/bin/
|
ADD $TARGETARCH/$TARGET_BIN /greptime/bin/
|
||||||
|
|
||||||
ENV PATH /greptime/bin/:$PATH
|
ENV PATH=/greptime/bin/:$PATH
|
||||||
|
|
||||||
ENV TARGET_BIN=$TARGET_BIN
|
ENV TARGET_BIN=$TARGET_BIN
|
||||||
|
|
||||||
|
|||||||
@@ -13,4 +13,19 @@ Log Level changed from Some("info") to "trace,flow=debug"%
|
|||||||
|
|
||||||
The data is a string in the format of `global_level,module1=level1,module2=level2,...` that follows the same rule of `RUST_LOG`.
|
The data is a string in the format of `global_level,module1=level1,module2=level2,...` that follows the same rule of `RUST_LOG`.
|
||||||
|
|
||||||
The module is the module name of the log, and the level is the log level. The log level can be one of the following: `trace`, `debug`, `info`, `warn`, `error`, `off`(case insensitive).
|
The module is the module name of the log, and the level is the log level. The log level can be one of the following: `trace`, `debug`, `info`, `warn`, `error`, `off`(case insensitive).
|
||||||
|
|
||||||
|
# Enable/Disable Trace on the Fly
|
||||||
|
|
||||||
|
## HTTP API
|
||||||
|
|
||||||
|
example:
|
||||||
|
```bash
|
||||||
|
curl --data "true" 127.0.0.1:4000/debug/enable_trace
|
||||||
|
```
|
||||||
|
And database will reply with something like:
|
||||||
|
```
|
||||||
|
trace enabled%
|
||||||
|
```
|
||||||
|
|
||||||
|
Possible values are "true" or "false".
|
||||||
|
|||||||
@@ -106,6 +106,37 @@ This mechanism may be too complex to implement at once. We can consider a two-ph
|
|||||||
Also the read replica shouldn't be later in manifest version for more than the lingering time of obsolete files, otherwise it might ref to files that are already deleted by the GC worker.
|
Also the read replica shouldn't be later in manifest version for more than the lingering time of obsolete files, otherwise it might ref to files that are already deleted by the GC worker.
|
||||||
- need to upload tmp manifest to object storage, which may introduce additional complexity and potential performance overhead. But since long-running queries are typically not frequent, the performance impact is expected to be minimal.
|
- need to upload tmp manifest to object storage, which may introduce additional complexity and potential performance overhead. But since long-running queries are typically not frequent, the performance impact is expected to be minimal.
|
||||||
|
|
||||||
|
one potential race condition with region-migration is illustrated below:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant gc_worker as GC Worker(same dn as region 1)
|
||||||
|
participant region1 as Region 1 (Leader → Follower)
|
||||||
|
participant region2 as Region 2 (Follower → Leader)
|
||||||
|
participant region_dir as Region Directory
|
||||||
|
|
||||||
|
gc_worker->>region1: Start GC, get region manifest
|
||||||
|
activate region1
|
||||||
|
region1-->>gc_worker: Region 1 manifest
|
||||||
|
deactivate region1
|
||||||
|
gc_worker->>region_dir: Scan region directory
|
||||||
|
|
||||||
|
Note over region1,region2: Region Migration Occurs
|
||||||
|
region1-->>region2: Downgrade to Follower
|
||||||
|
region2-->>region1: Becomes Leader
|
||||||
|
|
||||||
|
region2->>region_dir: Add new file
|
||||||
|
|
||||||
|
gc_worker->>region_dir: Continue scanning
|
||||||
|
gc_worker-->>region_dir: Discovers new file
|
||||||
|
Note over gc_worker: New file not in Region 1's manifest
|
||||||
|
gc_worker->>gc_worker: Mark file as orphan(incorrectly)
|
||||||
|
```
|
||||||
|
which could cause gc worker to incorrectly mark the new file as orphan and delete it, if config the lingering time for orphan files(files not mentioned anywhere(in used or unused)) is not long enough.
|
||||||
|
|
||||||
|
A good enough solution could be to use lock to prevent gc worker to happen on the region if region migration is happening on the region, and vise versa.
|
||||||
|
|
||||||
|
The race condition between gc worker and repartition also needs to be considered carefully. For now, acquiring lock for both region-migration and repartition during gc worker process could be a simple solution.
|
||||||
|
|
||||||
## Conclusion and Rationale
|
## Conclusion and Rationale
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use common_decimal::Decimal128;
|
use common_decimal::Decimal128;
|
||||||
@@ -20,13 +20,12 @@ use common_decimal::decimal128::{DECIMAL128_DEFAULT_SCALE, DECIMAL128_MAX_PRECIS
|
|||||||
use common_time::time::Time;
|
use common_time::time::Time;
|
||||||
use common_time::timestamp::TimeUnit;
|
use common_time::timestamp::TimeUnit;
|
||||||
use common_time::{Date, IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth, Timestamp};
|
use common_time::{Date, IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth, Timestamp};
|
||||||
|
use datatypes::json::value::{JsonNumber, JsonValue, JsonValueRef, JsonVariant};
|
||||||
use datatypes::prelude::{ConcreteDataType, ValueRef};
|
use datatypes::prelude::{ConcreteDataType, ValueRef};
|
||||||
use datatypes::types::{
|
use datatypes::types::{
|
||||||
IntervalType, JsonFormat, StructField, StructType, TimeType, TimestampType,
|
IntervalType, JsonFormat, JsonType, StructField, StructType, TimeType, TimestampType,
|
||||||
};
|
|
||||||
use datatypes::value::{
|
|
||||||
ListValue, ListValueRef, OrderedF32, OrderedF64, StructValue, StructValueRef, Value,
|
|
||||||
};
|
};
|
||||||
|
use datatypes::value::{ListValueRef, OrderedF32, OrderedF64, StructValueRef, Value};
|
||||||
use datatypes::vectors::VectorRef;
|
use datatypes::vectors::VectorRef;
|
||||||
use greptime_proto::v1::column_data_type_extension::TypeExt;
|
use greptime_proto::v1::column_data_type_extension::TypeExt;
|
||||||
use greptime_proto::v1::ddl_request::Expr;
|
use greptime_proto::v1::ddl_request::Expr;
|
||||||
@@ -34,9 +33,9 @@ use greptime_proto::v1::greptime_request::Request;
|
|||||||
use greptime_proto::v1::query_request::Query;
|
use greptime_proto::v1::query_request::Query;
|
||||||
use greptime_proto::v1::value::ValueData;
|
use greptime_proto::v1::value::ValueData;
|
||||||
use greptime_proto::v1::{
|
use greptime_proto::v1::{
|
||||||
self, ColumnDataTypeExtension, DdlRequest, DecimalTypeExtension, JsonNativeTypeExtension,
|
self, ColumnDataTypeExtension, DdlRequest, DecimalTypeExtension, DictionaryTypeExtension,
|
||||||
JsonTypeExtension, ListTypeExtension, QueryRequest, Row, SemanticType, StructTypeExtension,
|
JsonList, JsonNativeTypeExtension, JsonObject, JsonTypeExtension, ListTypeExtension,
|
||||||
VectorTypeExtension,
|
QueryRequest, Row, SemanticType, StructTypeExtension, VectorTypeExtension, json_value,
|
||||||
};
|
};
|
||||||
use paste::paste;
|
use paste::paste;
|
||||||
use snafu::prelude::*;
|
use snafu::prelude::*;
|
||||||
@@ -81,6 +80,10 @@ impl ColumnDataTypeWrapper {
|
|||||||
pub fn to_parts(&self) -> (ColumnDataType, Option<ColumnDataTypeExtension>) {
|
pub fn to_parts(&self) -> (ColumnDataType, Option<ColumnDataTypeExtension>) {
|
||||||
(self.datatype, self.datatype_ext.clone())
|
(self.datatype, self.datatype_ext.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_parts(self) -> (ColumnDataType, Option<ColumnDataTypeExtension>) {
|
||||||
|
(self.datatype, self.datatype_ext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ColumnDataTypeWrapper> for ConcreteDataType {
|
impl From<ColumnDataTypeWrapper> for ConcreteDataType {
|
||||||
@@ -126,6 +129,7 @@ impl From<ColumnDataTypeWrapper> for ConcreteDataType {
|
|||||||
};
|
};
|
||||||
ConcreteDataType::json_native_datatype(inner_type.into())
|
ConcreteDataType::json_native_datatype(inner_type.into())
|
||||||
}
|
}
|
||||||
|
None => ConcreteDataType::Json(JsonType::null()),
|
||||||
_ => {
|
_ => {
|
||||||
// invalid state, type extension is missing or invalid
|
// invalid state, type extension is missing or invalid
|
||||||
ConcreteDataType::null_datatype()
|
ConcreteDataType::null_datatype()
|
||||||
@@ -215,6 +219,26 @@ impl From<ColumnDataTypeWrapper> for ConcreteDataType {
|
|||||||
ConcreteDataType::null_datatype()
|
ConcreteDataType::null_datatype()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ColumnDataType::Dictionary => {
|
||||||
|
if let Some(TypeExt::DictionaryType(d)) = datatype_wrapper
|
||||||
|
.datatype_ext
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|datatype_ext| datatype_ext.type_ext.as_ref())
|
||||||
|
{
|
||||||
|
let key_type = ColumnDataTypeWrapper {
|
||||||
|
datatype: d.key_datatype(),
|
||||||
|
datatype_ext: d.key_datatype_extension.clone().map(|ext| *ext),
|
||||||
|
};
|
||||||
|
let value_type = ColumnDataTypeWrapper {
|
||||||
|
datatype: d.value_datatype(),
|
||||||
|
datatype_ext: d.value_datatype_extension.clone().map(|ext| *ext),
|
||||||
|
};
|
||||||
|
ConcreteDataType::dictionary_datatype(key_type.into(), value_type.into())
|
||||||
|
} else {
|
||||||
|
// invalid state: type extension not found
|
||||||
|
ConcreteDataType::null_datatype()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,13 +362,30 @@ impl ColumnDataTypeWrapper {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dictionary_datatype(
|
||||||
|
key_type: ColumnDataTypeWrapper,
|
||||||
|
value_type: ColumnDataTypeWrapper,
|
||||||
|
) -> Self {
|
||||||
|
ColumnDataTypeWrapper {
|
||||||
|
datatype: ColumnDataType::Dictionary,
|
||||||
|
datatype_ext: Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::DictionaryType(Box::new(DictionaryTypeExtension {
|
||||||
|
key_datatype: key_type.datatype().into(),
|
||||||
|
key_datatype_extension: key_type.datatype_ext.map(Box::new),
|
||||||
|
value_datatype: value_type.datatype().into(),
|
||||||
|
value_datatype_extension: value_type.datatype_ext.map(Box::new),
|
||||||
|
}))),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
|
impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
|
||||||
type Error = error::Error;
|
type Error = error::Error;
|
||||||
|
|
||||||
fn try_from(datatype: ConcreteDataType) -> Result<Self> {
|
fn try_from(datatype: ConcreteDataType) -> Result<Self> {
|
||||||
let column_datatype = match datatype {
|
let column_datatype = match &datatype {
|
||||||
ConcreteDataType::Boolean(_) => ColumnDataType::Boolean,
|
ConcreteDataType::Boolean(_) => ColumnDataType::Boolean,
|
||||||
ConcreteDataType::Int8(_) => ColumnDataType::Int8,
|
ConcreteDataType::Int8(_) => ColumnDataType::Int8,
|
||||||
ConcreteDataType::Int16(_) => ColumnDataType::Int16,
|
ConcreteDataType::Int16(_) => ColumnDataType::Int16,
|
||||||
@@ -381,9 +422,8 @@ impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
|
|||||||
ConcreteDataType::Vector(_) => ColumnDataType::Vector,
|
ConcreteDataType::Vector(_) => ColumnDataType::Vector,
|
||||||
ConcreteDataType::List(_) => ColumnDataType::List,
|
ConcreteDataType::List(_) => ColumnDataType::List,
|
||||||
ConcreteDataType::Struct(_) => ColumnDataType::Struct,
|
ConcreteDataType::Struct(_) => ColumnDataType::Struct,
|
||||||
ConcreteDataType::Null(_)
|
ConcreteDataType::Dictionary(_) => ColumnDataType::Dictionary,
|
||||||
| ConcreteDataType::Dictionary(_)
|
ConcreteDataType::Null(_) | ConcreteDataType::Duration(_) => {
|
||||||
| ConcreteDataType::Duration(_) => {
|
|
||||||
return error::IntoColumnDataTypeSnafu { from: datatype }.fail();
|
return error::IntoColumnDataTypeSnafu { from: datatype }.fail();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -404,16 +444,22 @@ impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
|
|||||||
JsonFormat::Jsonb => Some(ColumnDataTypeExtension {
|
JsonFormat::Jsonb => Some(ColumnDataTypeExtension {
|
||||||
type_ext: Some(TypeExt::JsonType(JsonTypeExtension::JsonBinary.into())),
|
type_ext: Some(TypeExt::JsonType(JsonTypeExtension::JsonBinary.into())),
|
||||||
}),
|
}),
|
||||||
JsonFormat::Native(inner) => {
|
JsonFormat::Native(native_type) => {
|
||||||
let inner_type = ColumnDataTypeWrapper::try_from(*inner.clone())?;
|
if native_type.is_null() {
|
||||||
Some(ColumnDataTypeExtension {
|
None
|
||||||
type_ext: Some(TypeExt::JsonNativeType(Box::new(
|
} else {
|
||||||
JsonNativeTypeExtension {
|
let native_type = ConcreteDataType::from(native_type.as_ref());
|
||||||
datatype: inner_type.datatype.into(),
|
let (datatype, datatype_extension) =
|
||||||
datatype_extension: inner_type.datatype_ext.map(Box::new),
|
ColumnDataTypeWrapper::try_from(native_type)?.into_parts();
|
||||||
},
|
Some(ColumnDataTypeExtension {
|
||||||
))),
|
type_ext: Some(TypeExt::JsonNativeType(Box::new(
|
||||||
})
|
JsonNativeTypeExtension {
|
||||||
|
datatype: datatype as i32,
|
||||||
|
datatype_extension: datatype_extension.map(Box::new),
|
||||||
|
},
|
||||||
|
))),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -463,6 +509,25 @@ impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ColumnDataType::Dictionary => {
|
||||||
|
if let ConcreteDataType::Dictionary(dict_type) = &datatype {
|
||||||
|
let key_type = ColumnDataTypeWrapper::try_from(dict_type.key_type().clone())?;
|
||||||
|
let value_type =
|
||||||
|
ColumnDataTypeWrapper::try_from(dict_type.value_type().clone())?;
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::DictionaryType(Box::new(
|
||||||
|
DictionaryTypeExtension {
|
||||||
|
key_datatype: key_type.datatype.into(),
|
||||||
|
key_datatype_extension: key_type.datatype_ext.map(Box::new),
|
||||||
|
value_datatype: value_type.datatype.into(),
|
||||||
|
value_datatype_extension: value_type.datatype_ext.map(Box::new),
|
||||||
|
},
|
||||||
|
))),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@@ -601,6 +666,9 @@ pub fn values_with_capacity(datatype: ColumnDataType, capacity: usize) -> Values
|
|||||||
struct_values: Vec::with_capacity(capacity),
|
struct_values: Vec::with_capacity(capacity),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
ColumnDataType::Dictionary => Values {
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,21 +869,8 @@ pub fn pb_value_to_value_ref<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ValueData::JsonValue(inner_value) => {
|
ValueData::JsonValue(inner_value) => {
|
||||||
let json_datatype_ext = datatype_ext
|
let value = decode_json_value(inner_value);
|
||||||
.as_ref()
|
ValueRef::Json(Box::new(value))
|
||||||
.and_then(|ext| {
|
|
||||||
if let Some(TypeExt::JsonNativeType(l)) = &ext.type_ext {
|
|
||||||
Some(l)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.expect("json value must contain datatype ext");
|
|
||||||
|
|
||||||
ValueRef::Json(Box::new(pb_value_to_value_ref(
|
|
||||||
inner_value,
|
|
||||||
json_datatype_ext.datatype_extension.as_deref(),
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -839,125 +894,64 @@ pub fn is_column_type_value_eq(
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert value into proto's value.
|
fn encode_json_value(value: JsonValue) -> v1::JsonValue {
|
||||||
pub fn to_proto_value(value: Value) -> v1::Value {
|
fn helper(json: JsonVariant) -> v1::JsonValue {
|
||||||
match value {
|
let value = match json {
|
||||||
Value::Null => v1::Value { value_data: None },
|
JsonVariant::Null => None,
|
||||||
Value::Boolean(v) => v1::Value {
|
JsonVariant::Bool(x) => Some(json_value::Value::Boolean(x)),
|
||||||
value_data: Some(ValueData::BoolValue(v)),
|
JsonVariant::Number(x) => Some(match x {
|
||||||
},
|
JsonNumber::PosInt(i) => json_value::Value::Uint(i),
|
||||||
Value::UInt8(v) => v1::Value {
|
JsonNumber::NegInt(i) => json_value::Value::Int(i),
|
||||||
value_data: Some(ValueData::U8Value(v.into())),
|
JsonNumber::Float(f) => json_value::Value::Float(f.0),
|
||||||
},
|
}),
|
||||||
Value::UInt16(v) => v1::Value {
|
JsonVariant::String(x) => Some(json_value::Value::Str(x)),
|
||||||
value_data: Some(ValueData::U16Value(v.into())),
|
JsonVariant::Array(x) => Some(json_value::Value::Array(JsonList {
|
||||||
},
|
items: x.into_iter().map(helper).collect::<Vec<_>>(),
|
||||||
Value::UInt32(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::U32Value(v)),
|
|
||||||
},
|
|
||||||
Value::UInt64(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::U64Value(v)),
|
|
||||||
},
|
|
||||||
Value::Int8(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::I8Value(v.into())),
|
|
||||||
},
|
|
||||||
Value::Int16(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::I16Value(v.into())),
|
|
||||||
},
|
|
||||||
Value::Int32(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::I32Value(v)),
|
|
||||||
},
|
|
||||||
Value::Int64(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::I64Value(v)),
|
|
||||||
},
|
|
||||||
Value::Float32(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::F32Value(*v)),
|
|
||||||
},
|
|
||||||
Value::Float64(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::F64Value(*v)),
|
|
||||||
},
|
|
||||||
Value::String(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::StringValue(v.as_utf8().to_string())),
|
|
||||||
},
|
|
||||||
Value::Binary(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::BinaryValue(v.to_vec())),
|
|
||||||
},
|
|
||||||
Value::Date(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::DateValue(v.val())),
|
|
||||||
},
|
|
||||||
Value::Timestamp(v) => match v.unit() {
|
|
||||||
TimeUnit::Second => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimestampSecondValue(v.value())),
|
|
||||||
},
|
|
||||||
TimeUnit::Millisecond => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimestampMillisecondValue(v.value())),
|
|
||||||
},
|
|
||||||
TimeUnit::Microsecond => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimestampMicrosecondValue(v.value())),
|
|
||||||
},
|
|
||||||
TimeUnit::Nanosecond => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimestampNanosecondValue(v.value())),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Value::Time(v) => match v.unit() {
|
|
||||||
TimeUnit::Second => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimeSecondValue(v.value())),
|
|
||||||
},
|
|
||||||
TimeUnit::Millisecond => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimeMillisecondValue(v.value())),
|
|
||||||
},
|
|
||||||
TimeUnit::Microsecond => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimeMicrosecondValue(v.value())),
|
|
||||||
},
|
|
||||||
TimeUnit::Nanosecond => v1::Value {
|
|
||||||
value_data: Some(ValueData::TimeNanosecondValue(v.value())),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Value::IntervalYearMonth(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::IntervalYearMonthValue(v.to_i32())),
|
|
||||||
},
|
|
||||||
Value::IntervalDayTime(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::IntervalDayTimeValue(v.to_i64())),
|
|
||||||
},
|
|
||||||
Value::IntervalMonthDayNano(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::IntervalMonthDayNanoValue(
|
|
||||||
convert_month_day_nano_to_pb(v),
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
Value::Decimal128(v) => v1::Value {
|
|
||||||
value_data: Some(ValueData::Decimal128Value(convert_to_pb_decimal128(v))),
|
|
||||||
},
|
|
||||||
Value::List(list_value) => v1::Value {
|
|
||||||
value_data: Some(ValueData::ListValue(v1::ListValue {
|
|
||||||
items: convert_list_to_pb_values(list_value),
|
|
||||||
})),
|
})),
|
||||||
},
|
JsonVariant::Object(x) => {
|
||||||
Value::Struct(struct_value) => v1::Value {
|
let entries = x
|
||||||
value_data: Some(ValueData::StructValue(v1::StructValue {
|
.into_iter()
|
||||||
items: convert_struct_to_pb_values(struct_value),
|
.map(|(key, v)| v1::json_object::Entry {
|
||||||
})),
|
key,
|
||||||
},
|
value: Some(helper(v)),
|
||||||
Value::Json(v) => v1::Value {
|
})
|
||||||
value_data: Some(ValueData::JsonValue(Box::new(to_proto_value(*v)))),
|
.collect::<Vec<_>>();
|
||||||
},
|
Some(json_value::Value::Object(JsonObject { entries }))
|
||||||
Value::Duration(_) => v1::Value { value_data: None },
|
}
|
||||||
|
};
|
||||||
|
v1::JsonValue { value }
|
||||||
}
|
}
|
||||||
|
helper(value.into_variant())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_list_to_pb_values(list_value: ListValue) -> Vec<v1::Value> {
|
fn decode_json_value(value: &v1::JsonValue) -> JsonValueRef<'_> {
|
||||||
list_value
|
let Some(value) = &value.value else {
|
||||||
.take_items()
|
return JsonValueRef::null();
|
||||||
.into_iter()
|
};
|
||||||
.map(to_proto_value)
|
match value {
|
||||||
.collect()
|
json_value::Value::Boolean(x) => (*x).into(),
|
||||||
}
|
json_value::Value::Int(x) => (*x).into(),
|
||||||
|
json_value::Value::Uint(x) => (*x).into(),
|
||||||
fn convert_struct_to_pb_values(struct_value: StructValue) -> Vec<v1::Value> {
|
json_value::Value::Float(x) => (*x).into(),
|
||||||
struct_value
|
json_value::Value::Str(x) => (x.as_str()).into(),
|
||||||
.take_items()
|
json_value::Value::Array(array) => array
|
||||||
.into_iter()
|
.items
|
||||||
.map(to_proto_value)
|
.iter()
|
||||||
.collect()
|
.map(|x| decode_json_value(x).into_variant())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into(),
|
||||||
|
json_value::Value::Object(x) => x
|
||||||
|
.entries
|
||||||
|
.iter()
|
||||||
|
.filter_map(|entry| {
|
||||||
|
entry
|
||||||
|
.value
|
||||||
|
.as_ref()
|
||||||
|
.map(|v| (entry.key.as_str(), decode_json_value(v).into_variant()))
|
||||||
|
})
|
||||||
|
.collect::<BTreeMap<_, _>>()
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [ColumnDataTypeWrapper] of the value.
|
/// Returns the [ColumnDataTypeWrapper] of the value.
|
||||||
@@ -1006,14 +1000,14 @@ pub fn vectors_to_rows<'a>(
|
|||||||
let mut rows = vec![Row { values: vec![] }; row_count];
|
let mut rows = vec![Row { values: vec![] }; row_count];
|
||||||
for column in columns {
|
for column in columns {
|
||||||
for (row_index, row) in rows.iter_mut().enumerate() {
|
for (row_index, row) in rows.iter_mut().enumerate() {
|
||||||
row.values.push(value_to_grpc_value(column.get(row_index)))
|
row.values.push(to_grpc_value(column.get(row_index)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rows
|
rows
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value_to_grpc_value(value: Value) -> GrpcValue {
|
pub fn to_grpc_value(value: Value) -> GrpcValue {
|
||||||
GrpcValue {
|
GrpcValue {
|
||||||
value_data: match value {
|
value_data: match value {
|
||||||
Value::Null => None,
|
Value::Null => None,
|
||||||
@@ -1053,7 +1047,7 @@ pub fn value_to_grpc_value(value: Value) -> GrpcValue {
|
|||||||
let items = list_value
|
let items = list_value
|
||||||
.take_items()
|
.take_items()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(value_to_grpc_value)
|
.map(to_grpc_value)
|
||||||
.collect();
|
.collect();
|
||||||
Some(ValueData::ListValue(v1::ListValue { items }))
|
Some(ValueData::ListValue(v1::ListValue { items }))
|
||||||
}
|
}
|
||||||
@@ -1061,13 +1055,11 @@ pub fn value_to_grpc_value(value: Value) -> GrpcValue {
|
|||||||
let items = struct_value
|
let items = struct_value
|
||||||
.take_items()
|
.take_items()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(value_to_grpc_value)
|
.map(to_grpc_value)
|
||||||
.collect();
|
.collect();
|
||||||
Some(ValueData::StructValue(v1::StructValue { items }))
|
Some(ValueData::StructValue(v1::StructValue { items }))
|
||||||
}
|
}
|
||||||
Value::Json(inner_value) => Some(ValueData::JsonValue(Box::new(value_to_grpc_value(
|
Value::Json(v) => Some(ValueData::JsonValue(encode_json_value(*v))),
|
||||||
*inner_value,
|
|
||||||
)))),
|
|
||||||
Value::Duration(_) => unreachable!(),
|
Value::Duration(_) => unreachable!(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1163,6 +1155,7 @@ mod tests {
|
|||||||
use common_time::interval::IntervalUnit;
|
use common_time::interval::IntervalUnit;
|
||||||
use datatypes::scalars::ScalarVector;
|
use datatypes::scalars::ScalarVector;
|
||||||
use datatypes::types::{Int8Type, Int32Type, UInt8Type, UInt32Type};
|
use datatypes::types::{Int8Type, Int32Type, UInt8Type, UInt32Type};
|
||||||
|
use datatypes::value::{ListValue, StructValue};
|
||||||
use datatypes::vectors::{
|
use datatypes::vectors::{
|
||||||
BooleanVector, DateVector, Float32Vector, PrimitiveVector, StringVector,
|
BooleanVector, DateVector, Float32Vector, PrimitiveVector, StringVector,
|
||||||
};
|
};
|
||||||
@@ -1259,6 +1252,9 @@ mod tests {
|
|||||||
let values = values_with_capacity(ColumnDataType::Json, 2);
|
let values = values_with_capacity(ColumnDataType::Json, 2);
|
||||||
assert_eq!(2, values.json_values.capacity());
|
assert_eq!(2, values.json_values.capacity());
|
||||||
assert_eq!(2, values.string_values.capacity());
|
assert_eq!(2, values.string_values.capacity());
|
||||||
|
|
||||||
|
let values = values_with_capacity(ColumnDataType::Dictionary, 2);
|
||||||
|
assert!(values.bool_values.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1355,6 +1351,17 @@ mod tests {
|
|||||||
ConcreteDataType::list_datatype(Arc::new(ConcreteDataType::string_datatype())),
|
ConcreteDataType::list_datatype(Arc::new(ConcreteDataType::string_datatype())),
|
||||||
ColumnDataTypeWrapper::list_datatype(ColumnDataTypeWrapper::string_datatype()).into()
|
ColumnDataTypeWrapper::list_datatype(ColumnDataTypeWrapper::string_datatype()).into()
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ConcreteDataType::dictionary_datatype(
|
||||||
|
ConcreteDataType::int32_datatype(),
|
||||||
|
ConcreteDataType::string_datatype()
|
||||||
|
),
|
||||||
|
ColumnDataTypeWrapper::dictionary_datatype(
|
||||||
|
ColumnDataTypeWrapper::int32_datatype(),
|
||||||
|
ColumnDataTypeWrapper::string_datatype()
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
);
|
||||||
let struct_type = StructType::new(Arc::new(vec![
|
let struct_type = StructType::new(Arc::new(vec![
|
||||||
StructField::new("id".to_string(), ConcreteDataType::int64_datatype(), true),
|
StructField::new("id".to_string(), ConcreteDataType::int64_datatype(), true),
|
||||||
StructField::new(
|
StructField::new(
|
||||||
@@ -1525,6 +1532,18 @@ mod tests {
|
|||||||
ColumnDataTypeWrapper::vector_datatype(3),
|
ColumnDataTypeWrapper::vector_datatype(3),
|
||||||
ConcreteDataType::vector_datatype(3).try_into().unwrap()
|
ConcreteDataType::vector_datatype(3).try_into().unwrap()
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ColumnDataTypeWrapper::dictionary_datatype(
|
||||||
|
ColumnDataTypeWrapper::int32_datatype(),
|
||||||
|
ColumnDataTypeWrapper::string_datatype()
|
||||||
|
),
|
||||||
|
ConcreteDataType::dictionary_datatype(
|
||||||
|
ConcreteDataType::int32_datatype(),
|
||||||
|
ConcreteDataType::string_datatype()
|
||||||
|
)
|
||||||
|
.try_into()
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
let result: Result<ColumnDataTypeWrapper> = ConcreteDataType::null_datatype().try_into();
|
let result: Result<ColumnDataTypeWrapper> = ConcreteDataType::null_datatype().try_into();
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
@@ -1580,6 +1599,20 @@ mod tests {
|
|||||||
datatype_extension: Some(Box::new(ColumnDataTypeExtension {
|
datatype_extension: Some(Box::new(ColumnDataTypeExtension {
|
||||||
type_ext: Some(TypeExt::StructType(StructTypeExtension {
|
type_ext: Some(TypeExt::StructType(StructTypeExtension {
|
||||||
fields: vec![
|
fields: vec![
|
||||||
|
v1::StructField {
|
||||||
|
name: "address".to_string(),
|
||||||
|
datatype: ColumnDataTypeWrapper::string_datatype()
|
||||||
|
.datatype()
|
||||||
|
.into(),
|
||||||
|
datatype_extension: None
|
||||||
|
},
|
||||||
|
v1::StructField {
|
||||||
|
name: "age".to_string(),
|
||||||
|
datatype: ColumnDataTypeWrapper::int64_datatype()
|
||||||
|
.datatype()
|
||||||
|
.into(),
|
||||||
|
datatype_extension: None
|
||||||
|
},
|
||||||
v1::StructField {
|
v1::StructField {
|
||||||
name: "id".to_string(),
|
name: "id".to_string(),
|
||||||
datatype: ColumnDataTypeWrapper::int64_datatype()
|
datatype: ColumnDataTypeWrapper::int64_datatype()
|
||||||
@@ -1594,20 +1627,6 @@ mod tests {
|
|||||||
.into(),
|
.into(),
|
||||||
datatype_extension: None
|
datatype_extension: None
|
||||||
},
|
},
|
||||||
v1::StructField {
|
|
||||||
name: "age".to_string(),
|
|
||||||
datatype: ColumnDataTypeWrapper::int32_datatype()
|
|
||||||
.datatype()
|
|
||||||
.into(),
|
|
||||||
datatype_extension: None
|
|
||||||
},
|
|
||||||
v1::StructField {
|
|
||||||
name: "address".to_string(),
|
|
||||||
datatype: ColumnDataTypeWrapper::string_datatype()
|
|
||||||
.datatype()
|
|
||||||
.into(),
|
|
||||||
datatype_extension: None
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
}))
|
}))
|
||||||
@@ -1740,7 +1759,7 @@ mod tests {
|
|||||||
Arc::new(ConcreteDataType::boolean_datatype()),
|
Arc::new(ConcreteDataType::boolean_datatype()),
|
||||||
));
|
));
|
||||||
|
|
||||||
let pb_value = to_proto_value(value);
|
let pb_value = to_grpc_value(value);
|
||||||
|
|
||||||
match pb_value.value_data.unwrap() {
|
match pb_value.value_data.unwrap() {
|
||||||
ValueData::ListValue(pb_list_value) => {
|
ValueData::ListValue(pb_list_value) => {
|
||||||
@@ -1769,7 +1788,7 @@ mod tests {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pb_value = to_proto_value(value);
|
let pb_value = to_grpc_value(value);
|
||||||
|
|
||||||
match pb_value.value_data.unwrap() {
|
match pb_value.value_data.unwrap() {
|
||||||
ValueData::StructValue(pb_struct_value) => {
|
ValueData::StructValue(pb_struct_value) => {
|
||||||
@@ -1778,4 +1797,199 @@ mod tests {
|
|||||||
_ => panic!("Unexpected value type"),
|
_ => panic!("Unexpected value type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_encode_decode_json_value() {
|
||||||
|
let json = JsonValue::null();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert!(proto.value.is_none());
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = true.into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(proto.value, Some(json_value::Value::Boolean(true)));
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = (-1i64).into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(proto.value, Some(json_value::Value::Int(-1)));
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = 1u64.into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(proto.value, Some(json_value::Value::Uint(1)));
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = 1.0f64.into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(proto.value, Some(json_value::Value::Float(1.0)));
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = "s".into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(proto.value, Some(json_value::Value::Str("s".to_string())));
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = [1i64, 2, 3].into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(
|
||||||
|
proto.value,
|
||||||
|
Some(json_value::Value::Array(JsonList {
|
||||||
|
items: vec![
|
||||||
|
v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(1))
|
||||||
|
},
|
||||||
|
v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(2))
|
||||||
|
},
|
||||||
|
v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(3))
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = [(); 0].into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(
|
||||||
|
proto.value,
|
||||||
|
Some(json_value::Value::Array(JsonList { items: vec![] }))
|
||||||
|
);
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = [("k3", 3i64), ("k2", 2i64), ("k1", 1i64)].into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(
|
||||||
|
proto.value,
|
||||||
|
Some(json_value::Value::Object(JsonObject {
|
||||||
|
entries: vec![
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "k1".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(1))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "k2".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(2))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "k3".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(3))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = [("null", ()); 0].into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(
|
||||||
|
proto.value,
|
||||||
|
Some(json_value::Value::Object(JsonObject { entries: vec![] }))
|
||||||
|
);
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
|
||||||
|
let json: JsonValue = [
|
||||||
|
("null", JsonVariant::from(())),
|
||||||
|
("bool", false.into()),
|
||||||
|
("list", ["hello", "world"].into()),
|
||||||
|
(
|
||||||
|
"object",
|
||||||
|
[
|
||||||
|
("positive_i", JsonVariant::from(42u64)),
|
||||||
|
("negative_i", (-42i64).into()),
|
||||||
|
("nested", [("what", "blah")].into()),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into();
|
||||||
|
let proto = encode_json_value(json.clone());
|
||||||
|
assert_eq!(
|
||||||
|
proto.value,
|
||||||
|
Some(json_value::Value::Object(JsonObject {
|
||||||
|
entries: vec![
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "bool".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Boolean(false))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "list".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Array(JsonList {
|
||||||
|
items: vec![
|
||||||
|
v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Str("hello".to_string()))
|
||||||
|
},
|
||||||
|
v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Str("world".to_string()))
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "null".to_string(),
|
||||||
|
value: Some(v1::JsonValue { value: None }),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "object".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Object(JsonObject {
|
||||||
|
entries: vec![
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "negative_i".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Int(-42))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "nested".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Object(JsonObject {
|
||||||
|
entries: vec![v1::json_object::Entry {
|
||||||
|
key: "what".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Str(
|
||||||
|
"blah".to_string()
|
||||||
|
))
|
||||||
|
}),
|
||||||
|
},]
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
v1::json_object::Entry {
|
||||||
|
key: "positive_i".to_string(),
|
||||||
|
value: Some(v1::JsonValue {
|
||||||
|
value: Some(json_value::Value::Uint(42))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
let value = decode_json_value(&proto);
|
||||||
|
assert_eq!(json.as_ref(), value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ edition.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
enterprise = []
|
|
||||||
testing = []
|
testing = []
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
pub use client::{CachedKvBackend, CachedKvBackendBuilder, MetaKvBackend};
|
|
||||||
|
|
||||||
mod builder;
|
mod builder;
|
||||||
mod client;
|
mod client;
|
||||||
mod manager;
|
mod manager;
|
||||||
mod table_cache;
|
mod table_cache;
|
||||||
|
|
||||||
pub use builder::KvBackendCatalogManagerBuilder;
|
pub use builder::{
|
||||||
|
CatalogManagerConfigurator, CatalogManagerConfiguratorRef, KvBackendCatalogManagerBuilder,
|
||||||
|
};
|
||||||
|
pub use client::{CachedKvBackend, CachedKvBackendBuilder, MetaKvBackend};
|
||||||
pub use manager::KvBackendCatalogManager;
|
pub use manager::KvBackendCatalogManager;
|
||||||
pub use table_cache::{TableCache, TableCacheRef, new_table_cache};
|
pub use table_cache::{TableCache, TableCacheRef, new_table_cache};
|
||||||
|
|||||||
@@ -12,9 +12,11 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use common_catalog::consts::DEFAULT_CATALOG_NAME;
|
use common_catalog::consts::DEFAULT_CATALOG_NAME;
|
||||||
|
use common_error::ext::BoxedError;
|
||||||
use common_meta::cache::LayeredCacheRegistryRef;
|
use common_meta::cache::LayeredCacheRegistryRef;
|
||||||
use common_meta::key::TableMetadataManager;
|
use common_meta::key::TableMetadataManager;
|
||||||
use common_meta::key::flow::FlowMetadataManager;
|
use common_meta::key::flow::FlowMetadataManager;
|
||||||
@@ -23,24 +25,34 @@ use common_procedure::ProcedureManagerRef;
|
|||||||
use moka::sync::Cache;
|
use moka::sync::Cache;
|
||||||
use partition::manager::PartitionRuleManager;
|
use partition::manager::PartitionRuleManager;
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
use crate::information_schema::{
|
||||||
use crate::information_schema::InformationSchemaTableFactoryRef;
|
InformationExtensionRef, InformationSchemaProvider, InformationSchemaTableFactoryRef,
|
||||||
use crate::information_schema::{InformationExtensionRef, InformationSchemaProvider};
|
};
|
||||||
use crate::kvbackend::KvBackendCatalogManager;
|
use crate::kvbackend::KvBackendCatalogManager;
|
||||||
use crate::kvbackend::manager::{CATALOG_CACHE_MAX_CAPACITY, SystemCatalog};
|
use crate::kvbackend::manager::{CATALOG_CACHE_MAX_CAPACITY, SystemCatalog};
|
||||||
use crate::process_manager::ProcessManagerRef;
|
use crate::process_manager::ProcessManagerRef;
|
||||||
use crate::system_schema::numbers_table_provider::NumbersTableProvider;
|
use crate::system_schema::numbers_table_provider::NumbersTableProvider;
|
||||||
use crate::system_schema::pg_catalog::PGCatalogProvider;
|
use crate::system_schema::pg_catalog::PGCatalogProvider;
|
||||||
|
|
||||||
|
/// The configurator that customizes or enhances the [`KvBackendCatalogManagerBuilder`].
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait CatalogManagerConfigurator<C>: Send + Sync {
|
||||||
|
async fn configure(
|
||||||
|
&self,
|
||||||
|
builder: KvBackendCatalogManagerBuilder,
|
||||||
|
ctx: C,
|
||||||
|
) -> std::result::Result<KvBackendCatalogManagerBuilder, BoxedError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type CatalogManagerConfiguratorRef<C> = Arc<dyn CatalogManagerConfigurator<C>>;
|
||||||
|
|
||||||
pub struct KvBackendCatalogManagerBuilder {
|
pub struct KvBackendCatalogManagerBuilder {
|
||||||
information_extension: InformationExtensionRef,
|
information_extension: InformationExtensionRef,
|
||||||
backend: KvBackendRef,
|
backend: KvBackendRef,
|
||||||
cache_registry: LayeredCacheRegistryRef,
|
cache_registry: LayeredCacheRegistryRef,
|
||||||
procedure_manager: Option<ProcedureManagerRef>,
|
procedure_manager: Option<ProcedureManagerRef>,
|
||||||
process_manager: Option<ProcessManagerRef>,
|
process_manager: Option<ProcessManagerRef>,
|
||||||
#[cfg(feature = "enterprise")]
|
extra_information_table_factories: HashMap<String, InformationSchemaTableFactoryRef>,
|
||||||
extra_information_table_factories:
|
|
||||||
std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KvBackendCatalogManagerBuilder {
|
impl KvBackendCatalogManagerBuilder {
|
||||||
@@ -55,8 +67,7 @@ impl KvBackendCatalogManagerBuilder {
|
|||||||
cache_registry,
|
cache_registry,
|
||||||
procedure_manager: None,
|
procedure_manager: None,
|
||||||
process_manager: None,
|
process_manager: None,
|
||||||
#[cfg(feature = "enterprise")]
|
extra_information_table_factories: HashMap::new(),
|
||||||
extra_information_table_factories: std::collections::HashMap::new(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,10 +82,9 @@ impl KvBackendCatalogManagerBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the extra information tables.
|
/// Sets the extra information tables.
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub fn with_extra_information_table_factories(
|
pub fn with_extra_information_table_factories(
|
||||||
mut self,
|
mut self,
|
||||||
factories: std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
|
factories: HashMap<String, InformationSchemaTableFactoryRef>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.extra_information_table_factories = factories;
|
self.extra_information_table_factories = factories;
|
||||||
self
|
self
|
||||||
@@ -87,7 +97,6 @@ impl KvBackendCatalogManagerBuilder {
|
|||||||
cache_registry,
|
cache_registry,
|
||||||
procedure_manager,
|
procedure_manager,
|
||||||
process_manager,
|
process_manager,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
extra_information_table_factories,
|
extra_information_table_factories,
|
||||||
} = self;
|
} = self;
|
||||||
Arc::new_cyclic(|me| KvBackendCatalogManager {
|
Arc::new_cyclic(|me| KvBackendCatalogManager {
|
||||||
@@ -111,7 +120,6 @@ impl KvBackendCatalogManagerBuilder {
|
|||||||
process_manager.clone(),
|
process_manager.clone(),
|
||||||
backend.clone(),
|
backend.clone(),
|
||||||
);
|
);
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
let provider = provider
|
let provider = provider
|
||||||
.with_extra_table_factories(extra_information_table_factories.clone());
|
.with_extra_table_factories(extra_information_table_factories.clone());
|
||||||
Arc::new(provider)
|
Arc::new(provider)
|
||||||
@@ -123,7 +131,6 @@ impl KvBackendCatalogManagerBuilder {
|
|||||||
numbers_table_provider: NumbersTableProvider,
|
numbers_table_provider: NumbersTableProvider,
|
||||||
backend,
|
backend,
|
||||||
process_manager,
|
process_manager,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
extra_information_table_factories,
|
extra_information_table_factories,
|
||||||
},
|
},
|
||||||
cache_registry,
|
cache_registry,
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ use crate::error::{
|
|||||||
CacheNotFoundSnafu, GetTableCacheSnafu, InvalidTableInfoInCatalogSnafu, ListCatalogsSnafu,
|
CacheNotFoundSnafu, GetTableCacheSnafu, InvalidTableInfoInCatalogSnafu, ListCatalogsSnafu,
|
||||||
ListSchemasSnafu, ListTablesSnafu, Result, TableMetadataManagerSnafu,
|
ListSchemasSnafu, ListTablesSnafu, Result, TableMetadataManagerSnafu,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "enterprise")]
|
use crate::information_schema::{
|
||||||
use crate::information_schema::InformationSchemaTableFactoryRef;
|
InformationExtensionRef, InformationSchemaProvider, InformationSchemaTableFactoryRef,
|
||||||
use crate::information_schema::{InformationExtensionRef, InformationSchemaProvider};
|
};
|
||||||
use crate::kvbackend::TableCacheRef;
|
use crate::kvbackend::TableCacheRef;
|
||||||
use crate::process_manager::ProcessManagerRef;
|
use crate::process_manager::ProcessManagerRef;
|
||||||
use crate::system_schema::SystemSchemaProvider;
|
use crate::system_schema::SystemSchemaProvider;
|
||||||
@@ -557,7 +557,6 @@ pub(super) struct SystemCatalog {
|
|||||||
pub(super) numbers_table_provider: NumbersTableProvider,
|
pub(super) numbers_table_provider: NumbersTableProvider,
|
||||||
pub(super) backend: KvBackendRef,
|
pub(super) backend: KvBackendRef,
|
||||||
pub(super) process_manager: Option<ProcessManagerRef>,
|
pub(super) process_manager: Option<ProcessManagerRef>,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub(super) extra_information_table_factories:
|
pub(super) extra_information_table_factories:
|
||||||
std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
|
std::collections::HashMap<String, InformationSchemaTableFactoryRef>,
|
||||||
}
|
}
|
||||||
@@ -628,7 +627,6 @@ impl SystemCatalog {
|
|||||||
self.process_manager.clone(),
|
self.process_manager.clone(),
|
||||||
self.backend.clone(),
|
self.backend.clone(),
|
||||||
);
|
);
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
let provider = provider
|
let provider = provider
|
||||||
.with_extra_table_factories(self.extra_information_table_factories.clone());
|
.with_extra_table_factories(self.extra_information_table_factories.clone());
|
||||||
Arc::new(provider)
|
Arc::new(provider)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ mod procedure_info;
|
|||||||
pub mod process_list;
|
pub mod process_list;
|
||||||
pub mod region_peers;
|
pub mod region_peers;
|
||||||
mod region_statistics;
|
mod region_statistics;
|
||||||
mod runtime_metrics;
|
|
||||||
pub mod schemata;
|
pub mod schemata;
|
||||||
mod ssts;
|
mod ssts;
|
||||||
mod table_constraints;
|
mod table_constraints;
|
||||||
@@ -65,7 +64,6 @@ use crate::system_schema::information_schema::information_memory_table::get_sche
|
|||||||
use crate::system_schema::information_schema::key_column_usage::InformationSchemaKeyColumnUsage;
|
use crate::system_schema::information_schema::key_column_usage::InformationSchemaKeyColumnUsage;
|
||||||
use crate::system_schema::information_schema::partitions::InformationSchemaPartitions;
|
use crate::system_schema::information_schema::partitions::InformationSchemaPartitions;
|
||||||
use crate::system_schema::information_schema::region_peers::InformationSchemaRegionPeers;
|
use crate::system_schema::information_schema::region_peers::InformationSchemaRegionPeers;
|
||||||
use crate::system_schema::information_schema::runtime_metrics::InformationSchemaMetrics;
|
|
||||||
use crate::system_schema::information_schema::schemata::InformationSchemaSchemata;
|
use crate::system_schema::information_schema::schemata::InformationSchemaSchemata;
|
||||||
use crate::system_schema::information_schema::ssts::{
|
use crate::system_schema::information_schema::ssts::{
|
||||||
InformationSchemaSstsIndexMeta, InformationSchemaSstsManifest, InformationSchemaSstsStorage,
|
InformationSchemaSstsIndexMeta, InformationSchemaSstsManifest, InformationSchemaSstsStorage,
|
||||||
@@ -119,7 +117,6 @@ macro_rules! setup_memory_table {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub struct MakeInformationTableRequest {
|
pub struct MakeInformationTableRequest {
|
||||||
pub catalog_name: String,
|
pub catalog_name: String,
|
||||||
pub catalog_manager: Weak<dyn CatalogManager>,
|
pub catalog_manager: Weak<dyn CatalogManager>,
|
||||||
@@ -130,12 +127,10 @@ pub struct MakeInformationTableRequest {
|
|||||||
///
|
///
|
||||||
/// This trait allows for extensibility of the information schema by providing
|
/// This trait allows for extensibility of the information schema by providing
|
||||||
/// a way to dynamically create custom information schema tables.
|
/// a way to dynamically create custom information schema tables.
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub trait InformationSchemaTableFactory {
|
pub trait InformationSchemaTableFactory {
|
||||||
fn make_information_table(&self, req: MakeInformationTableRequest) -> SystemTableRef;
|
fn make_information_table(&self, req: MakeInformationTableRequest) -> SystemTableRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub type InformationSchemaTableFactoryRef = Arc<dyn InformationSchemaTableFactory + Send + Sync>;
|
pub type InformationSchemaTableFactoryRef = Arc<dyn InformationSchemaTableFactory + Send + Sync>;
|
||||||
|
|
||||||
/// The `information_schema` tables info provider.
|
/// The `information_schema` tables info provider.
|
||||||
@@ -145,9 +140,7 @@ pub struct InformationSchemaProvider {
|
|||||||
process_manager: Option<ProcessManagerRef>,
|
process_manager: Option<ProcessManagerRef>,
|
||||||
flow_metadata_manager: Arc<FlowMetadataManager>,
|
flow_metadata_manager: Arc<FlowMetadataManager>,
|
||||||
tables: HashMap<String, TableRef>,
|
tables: HashMap<String, TableRef>,
|
||||||
#[allow(dead_code)]
|
|
||||||
kv_backend: KvBackendRef,
|
kv_backend: KvBackendRef,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
extra_table_factories: HashMap<String, InformationSchemaTableFactoryRef>,
|
extra_table_factories: HashMap<String, InformationSchemaTableFactoryRef>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +161,6 @@ impl SystemSchemaProviderInner for InformationSchemaProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn system_table(&self, name: &str) -> Option<SystemTableRef> {
|
fn system_table(&self, name: &str) -> Option<SystemTableRef> {
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
if let Some(factory) = self.extra_table_factories.get(name) {
|
if let Some(factory) = self.extra_table_factories.get(name) {
|
||||||
let req = MakeInformationTableRequest {
|
let req = MakeInformationTableRequest {
|
||||||
catalog_name: self.catalog_name.clone(),
|
catalog_name: self.catalog_name.clone(),
|
||||||
@@ -216,7 +208,6 @@ impl SystemSchemaProviderInner for InformationSchemaProvider {
|
|||||||
self.catalog_name.clone(),
|
self.catalog_name.clone(),
|
||||||
self.catalog_manager.clone(),
|
self.catalog_manager.clone(),
|
||||||
)) as _),
|
)) as _),
|
||||||
RUNTIME_METRICS => Some(Arc::new(InformationSchemaMetrics::new())),
|
|
||||||
PARTITIONS => Some(Arc::new(InformationSchemaPartitions::new(
|
PARTITIONS => Some(Arc::new(InformationSchemaPartitions::new(
|
||||||
self.catalog_name.clone(),
|
self.catalog_name.clone(),
|
||||||
self.catalog_manager.clone(),
|
self.catalog_manager.clone(),
|
||||||
@@ -284,7 +275,6 @@ impl InformationSchemaProvider {
|
|||||||
process_manager,
|
process_manager,
|
||||||
tables: HashMap::new(),
|
tables: HashMap::new(),
|
||||||
kv_backend,
|
kv_backend,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
extra_table_factories: HashMap::new(),
|
extra_table_factories: HashMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -293,7 +283,6 @@ impl InformationSchemaProvider {
|
|||||||
provider
|
provider
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub(crate) fn with_extra_table_factories(
|
pub(crate) fn with_extra_table_factories(
|
||||||
mut self,
|
mut self,
|
||||||
factories: HashMap<String, InformationSchemaTableFactoryRef>,
|
factories: HashMap<String, InformationSchemaTableFactoryRef>,
|
||||||
@@ -311,10 +300,6 @@ impl InformationSchemaProvider {
|
|||||||
// authentication details, and other critical information.
|
// authentication details, and other critical information.
|
||||||
// Only put these tables under `greptime` catalog to prevent info leak.
|
// Only put these tables under `greptime` catalog to prevent info leak.
|
||||||
if self.catalog_name == DEFAULT_CATALOG_NAME {
|
if self.catalog_name == DEFAULT_CATALOG_NAME {
|
||||||
tables.insert(
|
|
||||||
RUNTIME_METRICS.to_string(),
|
|
||||||
self.build_table(RUNTIME_METRICS).unwrap(),
|
|
||||||
);
|
|
||||||
tables.insert(
|
tables.insert(
|
||||||
BUILD_INFO.to_string(),
|
BUILD_INFO.to_string(),
|
||||||
self.build_table(BUILD_INFO).unwrap(),
|
self.build_table(BUILD_INFO).unwrap(),
|
||||||
@@ -365,7 +350,6 @@ impl InformationSchemaProvider {
|
|||||||
if let Some(process_list) = self.build_table(PROCESS_LIST) {
|
if let Some(process_list) = self.build_table(PROCESS_LIST) {
|
||||||
tables.insert(PROCESS_LIST.to_string(), process_list);
|
tables.insert(PROCESS_LIST.to_string(), process_list);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
for name in self.extra_table_factories.keys() {
|
for name in self.extra_table_factories.keys() {
|
||||||
tables.insert(name.clone(), self.build_table(name).expect(name));
|
tables.insert(name.clone(), self.build_table(name).expect(name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ struct InformationSchemaPartitionsBuilder {
|
|||||||
partition_names: StringVectorBuilder,
|
partition_names: StringVectorBuilder,
|
||||||
partition_ordinal_positions: Int64VectorBuilder,
|
partition_ordinal_positions: Int64VectorBuilder,
|
||||||
partition_expressions: StringVectorBuilder,
|
partition_expressions: StringVectorBuilder,
|
||||||
|
partition_descriptions: StringVectorBuilder,
|
||||||
create_times: TimestampSecondVectorBuilder,
|
create_times: TimestampSecondVectorBuilder,
|
||||||
partition_ids: UInt64VectorBuilder,
|
partition_ids: UInt64VectorBuilder,
|
||||||
}
|
}
|
||||||
@@ -231,6 +232,7 @@ impl InformationSchemaPartitionsBuilder {
|
|||||||
partition_names: StringVectorBuilder::with_capacity(INIT_CAPACITY),
|
partition_names: StringVectorBuilder::with_capacity(INIT_CAPACITY),
|
||||||
partition_ordinal_positions: Int64VectorBuilder::with_capacity(INIT_CAPACITY),
|
partition_ordinal_positions: Int64VectorBuilder::with_capacity(INIT_CAPACITY),
|
||||||
partition_expressions: StringVectorBuilder::with_capacity(INIT_CAPACITY),
|
partition_expressions: StringVectorBuilder::with_capacity(INIT_CAPACITY),
|
||||||
|
partition_descriptions: StringVectorBuilder::with_capacity(INIT_CAPACITY),
|
||||||
create_times: TimestampSecondVectorBuilder::with_capacity(INIT_CAPACITY),
|
create_times: TimestampSecondVectorBuilder::with_capacity(INIT_CAPACITY),
|
||||||
partition_ids: UInt64VectorBuilder::with_capacity(INIT_CAPACITY),
|
partition_ids: UInt64VectorBuilder::with_capacity(INIT_CAPACITY),
|
||||||
}
|
}
|
||||||
@@ -319,6 +321,21 @@ impl InformationSchemaPartitionsBuilder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get partition column names (shared by all partitions)
|
||||||
|
// In MySQL, PARTITION_EXPRESSION is the partitioning function expression (e.g., column name)
|
||||||
|
let partition_columns: String = table_info
|
||||||
|
.meta
|
||||||
|
.partition_column_names()
|
||||||
|
.cloned()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
|
||||||
|
let partition_expr_str = if partition_columns.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(partition_columns)
|
||||||
|
};
|
||||||
|
|
||||||
for (index, partition) in partitions.iter().enumerate() {
|
for (index, partition) in partitions.iter().enumerate() {
|
||||||
let partition_name = format!("p{index}");
|
let partition_name = format!("p{index}");
|
||||||
|
|
||||||
@@ -328,8 +345,12 @@ impl InformationSchemaPartitionsBuilder {
|
|||||||
self.partition_names.push(Some(&partition_name));
|
self.partition_names.push(Some(&partition_name));
|
||||||
self.partition_ordinal_positions
|
self.partition_ordinal_positions
|
||||||
.push(Some((index + 1) as i64));
|
.push(Some((index + 1) as i64));
|
||||||
let expression = partition.partition_expr.as_ref().map(|e| e.to_string());
|
// PARTITION_EXPRESSION: partition column names (same for all partitions)
|
||||||
self.partition_expressions.push(expression.as_deref());
|
self.partition_expressions
|
||||||
|
.push(partition_expr_str.as_deref());
|
||||||
|
// PARTITION_DESCRIPTION: partition boundary expression (different for each partition)
|
||||||
|
let description = partition.partition_expr.as_ref().map(|e| e.to_string());
|
||||||
|
self.partition_descriptions.push(description.as_deref());
|
||||||
self.create_times.push(Some(TimestampSecond::from(
|
self.create_times.push(Some(TimestampSecond::from(
|
||||||
table_info.meta.created_on.timestamp(),
|
table_info.meta.created_on.timestamp(),
|
||||||
)));
|
)));
|
||||||
@@ -369,7 +390,7 @@ impl InformationSchemaPartitionsBuilder {
|
|||||||
null_string_vector.clone(),
|
null_string_vector.clone(),
|
||||||
Arc::new(self.partition_expressions.finish()),
|
Arc::new(self.partition_expressions.finish()),
|
||||||
null_string_vector.clone(),
|
null_string_vector.clone(),
|
||||||
null_string_vector.clone(),
|
Arc::new(self.partition_descriptions.finish()),
|
||||||
// TODO(dennis): rows and index statistics info
|
// TODO(dennis): rows and index statistics info
|
||||||
null_i64_vector.clone(),
|
null_i64_vector.clone(),
|
||||||
null_i64_vector.clone(),
|
null_i64_vector.clone(),
|
||||||
|
|||||||
@@ -1,265 +0,0 @@
|
|||||||
// Copyright 2023 Greptime Team
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use arrow_schema::SchemaRef as ArrowSchemaRef;
|
|
||||||
use common_catalog::consts::INFORMATION_SCHEMA_RUNTIME_METRICS_TABLE_ID;
|
|
||||||
use common_error::ext::BoxedError;
|
|
||||||
use common_recordbatch::adapter::RecordBatchStreamAdapter;
|
|
||||||
use common_recordbatch::{RecordBatch, SendableRecordBatchStream};
|
|
||||||
use common_time::util::current_time_millis;
|
|
||||||
use datafusion::execution::TaskContext;
|
|
||||||
use datafusion::physical_plan::SendableRecordBatchStream as DfSendableRecordBatchStream;
|
|
||||||
use datafusion::physical_plan::stream::RecordBatchStreamAdapter as DfRecordBatchStreamAdapter;
|
|
||||||
use datafusion::physical_plan::streaming::PartitionStream as DfPartitionStream;
|
|
||||||
use datatypes::prelude::{ConcreteDataType, MutableVector};
|
|
||||||
use datatypes::scalars::ScalarVectorBuilder;
|
|
||||||
use datatypes::schema::{ColumnSchema, Schema, SchemaRef};
|
|
||||||
use datatypes::vectors::{
|
|
||||||
ConstantVector, Float64VectorBuilder, StringVectorBuilder, TimestampMillisecondVector,
|
|
||||||
VectorRef,
|
|
||||||
};
|
|
||||||
use itertools::Itertools;
|
|
||||||
use snafu::ResultExt;
|
|
||||||
use store_api::storage::{ScanRequest, TableId};
|
|
||||||
|
|
||||||
use crate::error::{CreateRecordBatchSnafu, InternalSnafu, Result};
|
|
||||||
use crate::system_schema::information_schema::{InformationTable, RUNTIME_METRICS};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(super) struct InformationSchemaMetrics {
|
|
||||||
schema: SchemaRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
const METRIC_NAME: &str = "metric_name";
|
|
||||||
const METRIC_VALUE: &str = "value";
|
|
||||||
const METRIC_LABELS: &str = "labels";
|
|
||||||
const PEER_ADDR: &str = "peer_addr";
|
|
||||||
const PEER_TYPE: &str = "peer_type";
|
|
||||||
const TIMESTAMP: &str = "timestamp";
|
|
||||||
|
|
||||||
/// The `information_schema.runtime_metrics` virtual table.
|
|
||||||
/// It provides the GreptimeDB runtime metrics for the users by SQL.
|
|
||||||
impl InformationSchemaMetrics {
|
|
||||||
pub(super) fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
schema: Self::schema(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn schema() -> SchemaRef {
|
|
||||||
Arc::new(Schema::new(vec![
|
|
||||||
ColumnSchema::new(METRIC_NAME, ConcreteDataType::string_datatype(), false),
|
|
||||||
ColumnSchema::new(METRIC_VALUE, ConcreteDataType::float64_datatype(), false),
|
|
||||||
ColumnSchema::new(METRIC_LABELS, ConcreteDataType::string_datatype(), true),
|
|
||||||
ColumnSchema::new(PEER_ADDR, ConcreteDataType::string_datatype(), true),
|
|
||||||
ColumnSchema::new(PEER_TYPE, ConcreteDataType::string_datatype(), false),
|
|
||||||
ColumnSchema::new(
|
|
||||||
TIMESTAMP,
|
|
||||||
ConcreteDataType::timestamp_millisecond_datatype(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
]))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn builder(&self) -> InformationSchemaMetricsBuilder {
|
|
||||||
InformationSchemaMetricsBuilder::new(self.schema.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InformationTable for InformationSchemaMetrics {
|
|
||||||
fn table_id(&self) -> TableId {
|
|
||||||
INFORMATION_SCHEMA_RUNTIME_METRICS_TABLE_ID
|
|
||||||
}
|
|
||||||
|
|
||||||
fn table_name(&self) -> &'static str {
|
|
||||||
RUNTIME_METRICS
|
|
||||||
}
|
|
||||||
|
|
||||||
fn schema(&self) -> SchemaRef {
|
|
||||||
self.schema.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_stream(&self, request: ScanRequest) -> Result<SendableRecordBatchStream> {
|
|
||||||
let schema = self.schema.arrow_schema().clone();
|
|
||||||
let mut builder = self.builder();
|
|
||||||
let stream = Box::pin(DfRecordBatchStreamAdapter::new(
|
|
||||||
schema,
|
|
||||||
futures::stream::once(async move {
|
|
||||||
builder
|
|
||||||
.make_metrics(Some(request))
|
|
||||||
.await
|
|
||||||
.map(|x| x.into_df_record_batch())
|
|
||||||
.map_err(Into::into)
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
|
|
||||||
Ok(Box::pin(
|
|
||||||
RecordBatchStreamAdapter::try_new(stream)
|
|
||||||
.map_err(BoxedError::new)
|
|
||||||
.context(InternalSnafu)?,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct InformationSchemaMetricsBuilder {
|
|
||||||
schema: SchemaRef,
|
|
||||||
|
|
||||||
metric_names: StringVectorBuilder,
|
|
||||||
metric_values: Float64VectorBuilder,
|
|
||||||
metric_labels: StringVectorBuilder,
|
|
||||||
peer_addrs: StringVectorBuilder,
|
|
||||||
peer_types: StringVectorBuilder,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InformationSchemaMetricsBuilder {
|
|
||||||
fn new(schema: SchemaRef) -> Self {
|
|
||||||
Self {
|
|
||||||
schema,
|
|
||||||
metric_names: StringVectorBuilder::with_capacity(42),
|
|
||||||
metric_values: Float64VectorBuilder::with_capacity(42),
|
|
||||||
metric_labels: StringVectorBuilder::with_capacity(42),
|
|
||||||
peer_addrs: StringVectorBuilder::with_capacity(42),
|
|
||||||
peer_types: StringVectorBuilder::with_capacity(42),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_metric(
|
|
||||||
&mut self,
|
|
||||||
metric_name: &str,
|
|
||||||
labels: String,
|
|
||||||
metric_value: f64,
|
|
||||||
peer: Option<&str>,
|
|
||||||
peer_type: &str,
|
|
||||||
) {
|
|
||||||
self.metric_names.push(Some(metric_name));
|
|
||||||
self.metric_values.push(Some(metric_value));
|
|
||||||
self.metric_labels.push(Some(&labels));
|
|
||||||
self.peer_addrs.push(peer);
|
|
||||||
self.peer_types.push(Some(peer_type));
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn make_metrics(&mut self, _request: Option<ScanRequest>) -> Result<RecordBatch> {
|
|
||||||
let metric_families = prometheus::gather();
|
|
||||||
|
|
||||||
let write_request =
|
|
||||||
common_telemetry::metric::convert_metric_to_write_request(metric_families, None, 0);
|
|
||||||
|
|
||||||
for ts in write_request.timeseries {
|
|
||||||
//Safety: always has `__name__` label
|
|
||||||
let metric_name = ts
|
|
||||||
.labels
|
|
||||||
.iter()
|
|
||||||
.find_map(|label| {
|
|
||||||
if label.name == "__name__" {
|
|
||||||
Some(label.value.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
self.add_metric(
|
|
||||||
&metric_name,
|
|
||||||
ts.labels
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|label| {
|
|
||||||
if label.name == "__name__" {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(format!("{}={}", label.name, label.value))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.join(", "),
|
|
||||||
// Safety: always has a sample
|
|
||||||
ts.samples[0].value,
|
|
||||||
// The peer column is always `None` for standalone
|
|
||||||
None,
|
|
||||||
"STANDALONE",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME(dennis): fetching other peers metrics
|
|
||||||
self.finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(&mut self) -> Result<RecordBatch> {
|
|
||||||
let rows_num = self.metric_names.len();
|
|
||||||
|
|
||||||
let timestamps = Arc::new(ConstantVector::new(
|
|
||||||
Arc::new(TimestampMillisecondVector::from_slice([
|
|
||||||
current_time_millis(),
|
|
||||||
])),
|
|
||||||
rows_num,
|
|
||||||
));
|
|
||||||
|
|
||||||
let columns: Vec<VectorRef> = vec![
|
|
||||||
Arc::new(self.metric_names.finish()),
|
|
||||||
Arc::new(self.metric_values.finish()),
|
|
||||||
Arc::new(self.metric_labels.finish()),
|
|
||||||
Arc::new(self.peer_addrs.finish()),
|
|
||||||
Arc::new(self.peer_types.finish()),
|
|
||||||
timestamps,
|
|
||||||
];
|
|
||||||
|
|
||||||
RecordBatch::new(self.schema.clone(), columns).context(CreateRecordBatchSnafu)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DfPartitionStream for InformationSchemaMetrics {
|
|
||||||
fn schema(&self) -> &ArrowSchemaRef {
|
|
||||||
self.schema.arrow_schema()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn execute(&self, _: Arc<TaskContext>) -> DfSendableRecordBatchStream {
|
|
||||||
let schema = self.schema.arrow_schema().clone();
|
|
||||||
let mut builder = self.builder();
|
|
||||||
Box::pin(DfRecordBatchStreamAdapter::new(
|
|
||||||
schema,
|
|
||||||
futures::stream::once(async move {
|
|
||||||
builder
|
|
||||||
.make_metrics(None)
|
|
||||||
.await
|
|
||||||
.map(|x| x.into_df_record_batch())
|
|
||||||
.map_err(Into::into)
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use common_recordbatch::RecordBatches;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_make_metrics() {
|
|
||||||
let metrics = InformationSchemaMetrics::new();
|
|
||||||
|
|
||||||
let stream = metrics.to_stream(ScanRequest::default()).unwrap();
|
|
||||||
|
|
||||||
let batches = RecordBatches::try_collect(stream).await.unwrap();
|
|
||||||
|
|
||||||
let result_literal = batches.pretty_print().unwrap();
|
|
||||||
|
|
||||||
assert!(result_literal.contains(METRIC_NAME));
|
|
||||||
assert!(result_literal.contains(METRIC_VALUE));
|
|
||||||
assert!(result_literal.contains(METRIC_LABELS));
|
|
||||||
assert!(result_literal.contains(PEER_ADDR));
|
|
||||||
assert!(result_literal.contains(PEER_TYPE));
|
|
||||||
assert!(result_literal.contains(TIMESTAMP));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,6 @@ pub const TABLE_PRIVILEGES: &str = "table_privileges";
|
|||||||
pub const TRIGGERS: &str = "triggers";
|
pub const TRIGGERS: &str = "triggers";
|
||||||
pub const GLOBAL_STATUS: &str = "global_status";
|
pub const GLOBAL_STATUS: &str = "global_status";
|
||||||
pub const SESSION_STATUS: &str = "session_status";
|
pub const SESSION_STATUS: &str = "session_status";
|
||||||
pub const RUNTIME_METRICS: &str = "runtime_metrics";
|
|
||||||
pub const PARTITIONS: &str = "partitions";
|
pub const PARTITIONS: &str = "partitions";
|
||||||
pub const REGION_PEERS: &str = "region_peers";
|
pub const REGION_PEERS: &str = "region_peers";
|
||||||
pub const TABLE_CONSTRAINTS: &str = "table_constraints";
|
pub const TABLE_CONSTRAINTS: &str = "table_constraints";
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
use arrow_schema::SchemaRef as ArrowSchemaRef;
|
use arrow_schema::SchemaRef as ArrowSchemaRef;
|
||||||
@@ -255,14 +254,17 @@ impl InformationSchemaTablesBuilder {
|
|||||||
// TODO(dennis): `region_stats` API is not stable in distributed cluster because of network issue etc.
|
// TODO(dennis): `region_stats` API is not stable in distributed cluster because of network issue etc.
|
||||||
// But we don't want the statements such as `show tables` fail,
|
// But we don't want the statements such as `show tables` fail,
|
||||||
// so using `unwrap_or_else` here instead of `?` operator.
|
// so using `unwrap_or_else` here instead of `?` operator.
|
||||||
let region_stats = information_extension
|
let region_stats = {
|
||||||
.region_stats()
|
let mut x = information_extension
|
||||||
.await
|
.region_stats()
|
||||||
.map_err(|e| {
|
.await
|
||||||
error!(e; "Failed to call region_stats");
|
.unwrap_or_else(|e| {
|
||||||
e
|
error!(e; "Failed to find region stats in information_schema, fallback to all empty");
|
||||||
})
|
vec![]
|
||||||
.unwrap_or_else(|_| vec![]);
|
});
|
||||||
|
x.sort_unstable_by_key(|x| x.id);
|
||||||
|
x
|
||||||
|
};
|
||||||
|
|
||||||
for schema_name in catalog_manager.schema_names(&catalog_name, None).await? {
|
for schema_name in catalog_manager.schema_names(&catalog_name, None).await? {
|
||||||
let mut stream = catalog_manager.tables(&catalog_name, &schema_name, None);
|
let mut stream = catalog_manager.tables(&catalog_name, &schema_name, None);
|
||||||
@@ -273,16 +275,16 @@ impl InformationSchemaTablesBuilder {
|
|||||||
// TODO(dennis): make it working for metric engine
|
// TODO(dennis): make it working for metric engine
|
||||||
let table_region_stats =
|
let table_region_stats =
|
||||||
if table_info.meta.engine == MITO_ENGINE || table_info.is_physical_table() {
|
if table_info.meta.engine == MITO_ENGINE || table_info.is_physical_table() {
|
||||||
let region_ids = table_info
|
table_info
|
||||||
.meta
|
.meta
|
||||||
.region_numbers
|
.region_numbers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|n| RegionId::new(table_info.ident.table_id, *n))
|
.map(|n| RegionId::new(table_info.ident.table_id, *n))
|
||||||
.collect::<HashSet<_>>();
|
.flat_map(|region_id| {
|
||||||
|
region_stats
|
||||||
region_stats
|
.binary_search_by_key(®ion_id, |x| x.id)
|
||||||
.iter()
|
.map(|i| ®ion_stats[i])
|
||||||
.filter(|stat| region_ids.contains(&stat.id))
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
|
|||||||
@@ -67,9 +67,17 @@ pub struct ExportCommand {
|
|||||||
#[clap(long, default_value_t = default_database())]
|
#[clap(long, default_value_t = default_database())]
|
||||||
database: String,
|
database: String,
|
||||||
|
|
||||||
/// Parallelism of the export.
|
/// The number of databases exported in parallel.
|
||||||
#[clap(long, short = 'j', default_value = "1")]
|
/// For example, if there are 20 databases and `db_parallelism` is 4,
|
||||||
export_jobs: usize,
|
/// 4 databases will be exported concurrently.
|
||||||
|
#[clap(long, short = 'j', default_value = "1", alias = "export-jobs")]
|
||||||
|
db_parallelism: usize,
|
||||||
|
|
||||||
|
/// The number of tables exported in parallel within a single database.
|
||||||
|
/// For example, if a database has 30 tables and `parallelism` is 8,
|
||||||
|
/// 8 tables will be exported concurrently.
|
||||||
|
#[clap(long, default_value = "4")]
|
||||||
|
table_parallelism: usize,
|
||||||
|
|
||||||
/// Max retry times for each job.
|
/// Max retry times for each job.
|
||||||
#[clap(long, default_value = "3")]
|
#[clap(long, default_value = "3")]
|
||||||
@@ -210,10 +218,11 @@ impl ExportCommand {
|
|||||||
schema,
|
schema,
|
||||||
database_client,
|
database_client,
|
||||||
output_dir: self.output_dir.clone(),
|
output_dir: self.output_dir.clone(),
|
||||||
parallelism: self.export_jobs,
|
export_jobs: self.db_parallelism,
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
start_time: self.start_time.clone(),
|
start_time: self.start_time.clone(),
|
||||||
end_time: self.end_time.clone(),
|
end_time: self.end_time.clone(),
|
||||||
|
parallelism: self.table_parallelism,
|
||||||
s3: self.s3,
|
s3: self.s3,
|
||||||
ddl_local_dir: self.ddl_local_dir.clone(),
|
ddl_local_dir: self.ddl_local_dir.clone(),
|
||||||
s3_bucket: self.s3_bucket.clone(),
|
s3_bucket: self.s3_bucket.clone(),
|
||||||
@@ -251,10 +260,11 @@ pub struct Export {
|
|||||||
schema: Option<String>,
|
schema: Option<String>,
|
||||||
database_client: DatabaseClient,
|
database_client: DatabaseClient,
|
||||||
output_dir: Option<String>,
|
output_dir: Option<String>,
|
||||||
parallelism: usize,
|
export_jobs: usize,
|
||||||
target: ExportTarget,
|
target: ExportTarget,
|
||||||
start_time: Option<String>,
|
start_time: Option<String>,
|
||||||
end_time: Option<String>,
|
end_time: Option<String>,
|
||||||
|
parallelism: usize,
|
||||||
s3: bool,
|
s3: bool,
|
||||||
ddl_local_dir: Option<String>,
|
ddl_local_dir: Option<String>,
|
||||||
s3_bucket: Option<String>,
|
s3_bucket: Option<String>,
|
||||||
@@ -464,7 +474,7 @@ impl Export {
|
|||||||
|
|
||||||
async fn export_create_table(&self) -> Result<()> {
|
async fn export_create_table(&self) -> Result<()> {
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
let semaphore = Arc::new(Semaphore::new(self.parallelism));
|
let semaphore = Arc::new(Semaphore::new(self.export_jobs));
|
||||||
let db_names = self.get_db_names().await?;
|
let db_names = self.get_db_names().await?;
|
||||||
let db_count = db_names.len();
|
let db_count = db_names.len();
|
||||||
let operator = Arc::new(self.build_prefer_fs_operator().await?);
|
let operator = Arc::new(self.build_prefer_fs_operator().await?);
|
||||||
@@ -625,13 +635,13 @@ impl Export {
|
|||||||
|
|
||||||
async fn export_database_data(&self) -> Result<()> {
|
async fn export_database_data(&self) -> Result<()> {
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
let semaphore = Arc::new(Semaphore::new(self.parallelism));
|
let semaphore = Arc::new(Semaphore::new(self.export_jobs));
|
||||||
let db_names = self.get_db_names().await?;
|
let db_names = self.get_db_names().await?;
|
||||||
let db_count = db_names.len();
|
let db_count = db_names.len();
|
||||||
let mut tasks = Vec::with_capacity(db_count);
|
let mut tasks = Vec::with_capacity(db_count);
|
||||||
let operator = Arc::new(self.build_operator().await?);
|
let operator = Arc::new(self.build_operator().await?);
|
||||||
let fs_first_operator = Arc::new(self.build_prefer_fs_operator().await?);
|
let fs_first_operator = Arc::new(self.build_prefer_fs_operator().await?);
|
||||||
let with_options = build_with_options(&self.start_time, &self.end_time);
|
let with_options = build_with_options(&self.start_time, &self.end_time, self.parallelism);
|
||||||
|
|
||||||
for schema in db_names {
|
for schema in db_names {
|
||||||
let semaphore_moved = semaphore.clone();
|
let semaphore_moved = semaphore.clone();
|
||||||
@@ -888,7 +898,11 @@ impl Tool for Export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the WITH options string for SQL commands, assuming consistent syntax across S3 and local exports.
|
/// Builds the WITH options string for SQL commands, assuming consistent syntax across S3 and local exports.
|
||||||
fn build_with_options(start_time: &Option<String>, end_time: &Option<String>) -> String {
|
fn build_with_options(
|
||||||
|
start_time: &Option<String>,
|
||||||
|
end_time: &Option<String>,
|
||||||
|
parallelism: usize,
|
||||||
|
) -> String {
|
||||||
let mut options = vec!["format = 'parquet'".to_string()];
|
let mut options = vec!["format = 'parquet'".to_string()];
|
||||||
if let Some(start) = start_time {
|
if let Some(start) = start_time {
|
||||||
options.push(format!("start_time = '{}'", start));
|
options.push(format!("start_time = '{}'", start));
|
||||||
@@ -896,5 +910,6 @@ fn build_with_options(start_time: &Option<String>, end_time: &Option<String>) ->
|
|||||||
if let Some(end) = end_time {
|
if let Some(end) = end_time {
|
||||||
options.push(format!("end_time = '{}'", end));
|
options.push(format!("end_time = '{}'", end));
|
||||||
}
|
}
|
||||||
|
options.push(format!("parallelism = {}", parallelism));
|
||||||
options.join(", ")
|
options.join(", ")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,11 @@ pub struct ImportCommand {
|
|||||||
#[clap(long, default_value_t = default_database())]
|
#[clap(long, default_value_t = default_database())]
|
||||||
database: String,
|
database: String,
|
||||||
|
|
||||||
/// Parallelism of the import.
|
/// The number of databases imported in parallel.
|
||||||
#[clap(long, short = 'j', default_value = "1")]
|
/// For example, if there are 20 databases and `db_parallelism` is 4,
|
||||||
import_jobs: usize,
|
/// 4 databases will be imported concurrently.
|
||||||
|
#[clap(long, short = 'j', default_value = "1", alias = "import-jobs")]
|
||||||
|
db_parallelism: usize,
|
||||||
|
|
||||||
/// Max retry times for each job.
|
/// Max retry times for each job.
|
||||||
#[clap(long, default_value = "3")]
|
#[clap(long, default_value = "3")]
|
||||||
@@ -109,7 +111,7 @@ impl ImportCommand {
|
|||||||
schema,
|
schema,
|
||||||
database_client,
|
database_client,
|
||||||
input_dir: self.input_dir.clone(),
|
input_dir: self.input_dir.clone(),
|
||||||
parallelism: self.import_jobs,
|
parallelism: self.db_parallelism,
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use api::v1::prometheus_gateway_client::PrometheusGatewayClient;
|
|||||||
use api::v1::region::region_client::RegionClient as PbRegionClient;
|
use api::v1::region::region_client::RegionClient as PbRegionClient;
|
||||||
use arrow_flight::flight_service_client::FlightServiceClient;
|
use arrow_flight::flight_service_client::FlightServiceClient;
|
||||||
use common_grpc::channel_manager::{
|
use common_grpc::channel_manager::{
|
||||||
ChannelConfig, ChannelManager, ClientTlsOption, load_tls_config,
|
ChannelConfig, ChannelManager, ClientTlsOption, load_client_tls_config,
|
||||||
};
|
};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use snafu::{OptionExt, ResultExt};
|
use snafu::{OptionExt, ResultExt};
|
||||||
@@ -95,9 +95,9 @@ impl Client {
|
|||||||
U: AsRef<str>,
|
U: AsRef<str>,
|
||||||
A: AsRef<[U]>,
|
A: AsRef<[U]>,
|
||||||
{
|
{
|
||||||
let channel_config = ChannelConfig::default().client_tls_config(client_tls);
|
let channel_config = ChannelConfig::default().client_tls_config(client_tls.clone());
|
||||||
let tls_config = load_tls_config(channel_config.client_tls.as_ref())
|
let tls_config =
|
||||||
.context(error::CreateTlsChannelSnafu)?;
|
load_client_tls_config(Some(client_tls)).context(error::CreateTlsChannelSnafu)?;
|
||||||
let channel_manager = ChannelManager::with_config(channel_config, tls_config);
|
let channel_manager = ChannelManager::with_config(channel_config, tls_config);
|
||||||
Ok(Self::with_manager_and_urls(channel_manager, urls))
|
Ok(Self::with_manager_and_urls(channel_manager, urls))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -435,10 +435,10 @@ impl Database {
|
|||||||
.context(ExternalSnafu)?;
|
.context(ExternalSnafu)?;
|
||||||
match flight_message {
|
match flight_message {
|
||||||
FlightMessage::RecordBatch(arrow_batch) => {
|
FlightMessage::RecordBatch(arrow_batch) => {
|
||||||
yield RecordBatch::try_from_df_record_batch(
|
yield Ok(RecordBatch::from_df_record_batch(
|
||||||
schema_cloned.clone(),
|
schema_cloned.clone(),
|
||||||
arrow_batch,
|
arrow_batch,
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
FlightMessage::Metrics(_) => {}
|
FlightMessage::Metrics(_) => {}
|
||||||
FlightMessage::AffectedRows(_) | FlightMessage::Schema(_) => {
|
FlightMessage::AffectedRows(_) | FlightMessage::Schema(_) => {
|
||||||
|
|||||||
@@ -182,10 +182,8 @@ impl RegionRequester {
|
|||||||
|
|
||||||
match flight_message {
|
match flight_message {
|
||||||
FlightMessage::RecordBatch(record_batch) => {
|
FlightMessage::RecordBatch(record_batch) => {
|
||||||
let result_to_yield = RecordBatch::try_from_df_record_batch(
|
let result_to_yield =
|
||||||
schema_cloned.clone(),
|
RecordBatch::from_df_record_batch(schema_cloned.clone(), record_batch);
|
||||||
record_batch,
|
|
||||||
);
|
|
||||||
|
|
||||||
// get the next message from the stream. normally it should be a metrics message.
|
// get the next message from the stream. normally it should be a metrics message.
|
||||||
if let Some(next_flight_message_result) = flight_message_stream.next().await
|
if let Some(next_flight_message_result) = flight_message_stream.next().await
|
||||||
@@ -219,7 +217,7 @@ impl RegionRequester {
|
|||||||
stream_ended = true;
|
stream_ended = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield result_to_yield;
|
yield Ok(result_to_yield);
|
||||||
}
|
}
|
||||||
FlightMessage::Metrics(s) => {
|
FlightMessage::Metrics(s) => {
|
||||||
// just a branch in case of some metrics message comes after other things.
|
// just a branch in case of some metrics message comes after other things.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ default = [
|
|||||||
"meta-srv/pg_kvbackend",
|
"meta-srv/pg_kvbackend",
|
||||||
"meta-srv/mysql_kvbackend",
|
"meta-srv/mysql_kvbackend",
|
||||||
]
|
]
|
||||||
enterprise = ["common-meta/enterprise", "frontend/enterprise", "meta-srv/enterprise", "catalog/enterprise"]
|
enterprise = ["common-meta/enterprise", "frontend/enterprise", "meta-srv/enterprise"]
|
||||||
tokio-console = ["common-telemetry/tokio-console"]
|
tokio-console = ["common-telemetry/tokio-console"]
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ impl ObjbenchCommand {
|
|||||||
level: 0,
|
level: 0,
|
||||||
file_size,
|
file_size,
|
||||||
available_indexes: Default::default(),
|
available_indexes: Default::default(),
|
||||||
|
indexes: Default::default(),
|
||||||
index_file_size: 0,
|
index_file_size: 0,
|
||||||
index_file_id: None,
|
index_file_id: None,
|
||||||
num_rows,
|
num_rows,
|
||||||
|
|||||||
@@ -99,13 +99,6 @@ pub enum Error {
|
|||||||
source: flow::Error,
|
source: flow::Error,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[snafu(display("Servers error"))]
|
|
||||||
Servers {
|
|
||||||
#[snafu(implicit)]
|
|
||||||
location: Location,
|
|
||||||
source: servers::error::Error,
|
|
||||||
},
|
|
||||||
|
|
||||||
#[snafu(display("Failed to start frontend"))]
|
#[snafu(display("Failed to start frontend"))]
|
||||||
StartFrontend {
|
StartFrontend {
|
||||||
#[snafu(implicit)]
|
#[snafu(implicit)]
|
||||||
@@ -336,7 +329,6 @@ impl ErrorExt for Error {
|
|||||||
Error::ShutdownFrontend { source, .. } => source.status_code(),
|
Error::ShutdownFrontend { source, .. } => source.status_code(),
|
||||||
Error::StartMetaServer { source, .. } => source.status_code(),
|
Error::StartMetaServer { source, .. } => source.status_code(),
|
||||||
Error::ShutdownMetaServer { source, .. } => source.status_code(),
|
Error::ShutdownMetaServer { source, .. } => source.status_code(),
|
||||||
Error::Servers { source, .. } => source.status_code(),
|
|
||||||
Error::BuildMetaServer { source, .. } => source.status_code(),
|
Error::BuildMetaServer { source, .. } => source.status_code(),
|
||||||
Error::UnsupportedSelectorType { source, .. } => source.status_code(),
|
Error::UnsupportedSelectorType { source, .. } => source.status_code(),
|
||||||
Error::BuildCli { source, .. } => source.status_code(),
|
Error::BuildCli { source, .. } => source.status_code(),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -39,12 +40,14 @@ use flow::{
|
|||||||
get_flow_auth_options,
|
get_flow_auth_options,
|
||||||
};
|
};
|
||||||
use meta_client::{MetaClientOptions, MetaClientType};
|
use meta_client::{MetaClientOptions, MetaClientType};
|
||||||
|
use plugins::flownode::context::GrpcConfigureContext;
|
||||||
|
use servers::configurator::GrpcBuilderConfiguratorRef;
|
||||||
use snafu::{OptionExt, ResultExt, ensure};
|
use snafu::{OptionExt, ResultExt, ensure};
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
|
|
||||||
use crate::error::{
|
use crate::error::{
|
||||||
BuildCacheRegistrySnafu, InitMetadataSnafu, LoadLayeredConfigSnafu, MetaClientInitSnafu,
|
BuildCacheRegistrySnafu, InitMetadataSnafu, LoadLayeredConfigSnafu, MetaClientInitSnafu,
|
||||||
MissingConfigSnafu, Result, ShutdownFlownodeSnafu, StartFlownodeSnafu,
|
MissingConfigSnafu, OtherSnafu, Result, ShutdownFlownodeSnafu, StartFlownodeSnafu,
|
||||||
};
|
};
|
||||||
use crate::options::{GlobalOptions, GreptimeOptions};
|
use crate::options::{GlobalOptions, GreptimeOptions};
|
||||||
use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_heap_profile};
|
use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_heap_profile};
|
||||||
@@ -55,33 +58,14 @@ type FlownodeOptions = GreptimeOptions<flow::FlownodeOptions>;
|
|||||||
|
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
flownode: FlownodeInstance,
|
flownode: FlownodeInstance,
|
||||||
|
|
||||||
// The components of flownode, which make it easier to expand based
|
|
||||||
// on the components.
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
components: Components,
|
|
||||||
|
|
||||||
// Keep the logging guard to prevent the worker from being dropped.
|
// Keep the logging guard to prevent the worker from being dropped.
|
||||||
_guard: Vec<WorkerGuard>,
|
_guard: Vec<WorkerGuard>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub struct Components {
|
|
||||||
pub catalog_manager: catalog::CatalogManagerRef,
|
|
||||||
pub fe_client: Arc<FrontendClient>,
|
|
||||||
pub kv_backend: common_meta::kv_backend::KvBackendRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
pub fn new(
|
pub fn new(flownode: FlownodeInstance, guard: Vec<WorkerGuard>) -> Self {
|
||||||
flownode: FlownodeInstance,
|
|
||||||
#[cfg(feature = "enterprise")] components: Components,
|
|
||||||
guard: Vec<WorkerGuard>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
flownode,
|
flownode,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
components,
|
|
||||||
_guard: guard,
|
_guard: guard,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,11 +78,6 @@ impl Instance {
|
|||||||
pub fn flownode_mut(&mut self) -> &mut FlownodeInstance {
|
pub fn flownode_mut(&mut self) -> &mut FlownodeInstance {
|
||||||
&mut self.flownode
|
&mut self.flownode
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub fn components(&self) -> &Components {
|
|
||||||
&self.components
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
@@ -396,7 +375,7 @@ impl StartCommand {
|
|||||||
let frontend_client = Arc::new(frontend_client);
|
let frontend_client = Arc::new(frontend_client);
|
||||||
let flownode_builder = FlownodeBuilder::new(
|
let flownode_builder = FlownodeBuilder::new(
|
||||||
opts.clone(),
|
opts.clone(),
|
||||||
plugins,
|
plugins.clone(),
|
||||||
table_metadata_manager,
|
table_metadata_manager,
|
||||||
catalog_manager.clone(),
|
catalog_manager.clone(),
|
||||||
flow_metadata_manager,
|
flow_metadata_manager,
|
||||||
@@ -405,8 +384,29 @@ impl StartCommand {
|
|||||||
.with_heartbeat_task(heartbeat_task);
|
.with_heartbeat_task(heartbeat_task);
|
||||||
|
|
||||||
let mut flownode = flownode_builder.build().await.context(StartFlownodeSnafu)?;
|
let mut flownode = flownode_builder.build().await.context(StartFlownodeSnafu)?;
|
||||||
|
|
||||||
|
let builder =
|
||||||
|
FlownodeServiceBuilder::grpc_server_builder(&opts, flownode.flownode_server());
|
||||||
|
let builder = if let Some(configurator) =
|
||||||
|
plugins.get::<GrpcBuilderConfiguratorRef<GrpcConfigureContext>>()
|
||||||
|
{
|
||||||
|
let context = GrpcConfigureContext {
|
||||||
|
kv_backend: cached_meta_backend.clone(),
|
||||||
|
fe_client: frontend_client.clone(),
|
||||||
|
flownode_id: member_id,
|
||||||
|
catalog_manager: catalog_manager.clone(),
|
||||||
|
};
|
||||||
|
configurator
|
||||||
|
.configure(builder, context)
|
||||||
|
.await
|
||||||
|
.context(OtherSnafu)?
|
||||||
|
} else {
|
||||||
|
builder
|
||||||
|
};
|
||||||
|
let grpc_server = builder.build();
|
||||||
|
|
||||||
let services = FlownodeServiceBuilder::new(&opts)
|
let services = FlownodeServiceBuilder::new(&opts)
|
||||||
.with_default_grpc_server(flownode.flownode_server())
|
.with_grpc_server(grpc_server)
|
||||||
.enable_http_service()
|
.enable_http_service()
|
||||||
.build()
|
.build()
|
||||||
.context(StartFlownodeSnafu)?;
|
.context(StartFlownodeSnafu)?;
|
||||||
@@ -430,16 +430,6 @@ impl StartCommand {
|
|||||||
.set_frontend_invoker(invoker)
|
.set_frontend_invoker(invoker)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
Ok(Instance::new(flownode, guard))
|
||||||
let components = Components {
|
|
||||||
catalog_manager: catalog_manager.clone(),
|
|
||||||
fe_client: frontend_client,
|
|
||||||
kv_backend: cached_meta_backend,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(feature = "enterprise"))]
|
|
||||||
return Ok(Instance::new(flownode, guard));
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
Ok(Instance::new(flownode, components, guard))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -19,7 +20,10 @@ use std::time::Duration;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cache::{build_fundamental_cache_registry, with_default_composite_cache_registry};
|
use cache::{build_fundamental_cache_registry, with_default_composite_cache_registry};
|
||||||
use catalog::information_extension::DistributedInformationExtension;
|
use catalog::information_extension::DistributedInformationExtension;
|
||||||
use catalog::kvbackend::{CachedKvBackendBuilder, KvBackendCatalogManagerBuilder, MetaKvBackend};
|
use catalog::kvbackend::{
|
||||||
|
CachedKvBackendBuilder, CatalogManagerConfiguratorRef, KvBackendCatalogManagerBuilder,
|
||||||
|
MetaKvBackend,
|
||||||
|
};
|
||||||
use catalog::process_manager::ProcessManager;
|
use catalog::process_manager::ProcessManager;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use client::client_manager::NodeClients;
|
use client::client_manager::NodeClients;
|
||||||
@@ -42,14 +46,16 @@ use frontend::heartbeat::HeartbeatTask;
|
|||||||
use frontend::instance::builder::FrontendBuilder;
|
use frontend::instance::builder::FrontendBuilder;
|
||||||
use frontend::server::Services;
|
use frontend::server::Services;
|
||||||
use meta_client::{MetaClientOptions, MetaClientType};
|
use meta_client::{MetaClientOptions, MetaClientType};
|
||||||
|
use plugins::frontend::context::{
|
||||||
|
CatalogManagerConfigureContext, DistributedCatalogManagerConfigureContext,
|
||||||
|
};
|
||||||
use servers::addrs;
|
use servers::addrs;
|
||||||
use servers::export_metrics::ExportMetricsTask;
|
|
||||||
use servers::grpc::GrpcOptions;
|
use servers::grpc::GrpcOptions;
|
||||||
use servers::tls::{TlsMode, TlsOption};
|
use servers::tls::{TlsMode, TlsOption};
|
||||||
use snafu::{OptionExt, ResultExt};
|
use snafu::{OptionExt, ResultExt};
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
|
|
||||||
use crate::error::{self, Result};
|
use crate::error::{self, OtherSnafu, Result};
|
||||||
use crate::options::{GlobalOptions, GreptimeOptions};
|
use crate::options::{GlobalOptions, GreptimeOptions};
|
||||||
use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_heap_profile};
|
use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_heap_profile};
|
||||||
|
|
||||||
@@ -177,6 +183,8 @@ pub struct StartCommand {
|
|||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
tls_key_path: Option<String>,
|
tls_key_path: Option<String>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
|
tls_watch: bool,
|
||||||
|
#[clap(long)]
|
||||||
user_provider: Option<String>,
|
user_provider: Option<String>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
disable_dashboard: Option<bool>,
|
disable_dashboard: Option<bool>,
|
||||||
@@ -230,6 +238,7 @@ impl StartCommand {
|
|||||||
self.tls_mode.clone(),
|
self.tls_mode.clone(),
|
||||||
self.tls_cert_path.clone(),
|
self.tls_cert_path.clone(),
|
||||||
self.tls_key_path.clone(),
|
self.tls_key_path.clone(),
|
||||||
|
self.tls_watch,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(addr) = &self.http_addr {
|
if let Some(addr) = &self.http_addr {
|
||||||
@@ -414,9 +423,18 @@ impl StartCommand {
|
|||||||
layered_cache_registry.clone(),
|
layered_cache_registry.clone(),
|
||||||
)
|
)
|
||||||
.with_process_manager(process_manager.clone());
|
.with_process_manager(process_manager.clone());
|
||||||
#[cfg(feature = "enterprise")]
|
let builder = if let Some(configurator) =
|
||||||
let builder = if let Some(factories) = plugins.get() {
|
plugins.get::<CatalogManagerConfiguratorRef<CatalogManagerConfigureContext>>()
|
||||||
builder.with_extra_information_table_factories(factories)
|
{
|
||||||
|
let ctx = DistributedCatalogManagerConfigureContext {
|
||||||
|
meta_client: meta_client.clone(),
|
||||||
|
};
|
||||||
|
let ctx = CatalogManagerConfigureContext::Distributed(ctx);
|
||||||
|
|
||||||
|
configurator
|
||||||
|
.configure(builder, ctx)
|
||||||
|
.await
|
||||||
|
.context(OtherSnafu)?
|
||||||
} else {
|
} else {
|
||||||
builder
|
builder
|
||||||
};
|
};
|
||||||
@@ -455,9 +473,6 @@ impl StartCommand {
|
|||||||
.context(error::StartFrontendSnafu)?;
|
.context(error::StartFrontendSnafu)?;
|
||||||
let instance = Arc::new(instance);
|
let instance = Arc::new(instance);
|
||||||
|
|
||||||
let export_metrics_task = ExportMetricsTask::try_new(&opts.export_metrics, Some(&plugins))
|
|
||||||
.context(error::ServersSnafu)?;
|
|
||||||
|
|
||||||
let servers = Services::new(opts, instance.clone(), plugins)
|
let servers = Services::new(opts, instance.clone(), plugins)
|
||||||
.build()
|
.build()
|
||||||
.context(error::StartFrontendSnafu)?;
|
.context(error::StartFrontendSnafu)?;
|
||||||
@@ -466,7 +481,6 @@ impl StartCommand {
|
|||||||
instance,
|
instance,
|
||||||
servers,
|
servers,
|
||||||
heartbeat_task,
|
heartbeat_task,
|
||||||
export_metrics_task,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Instance::new(frontend, guard))
|
Ok(Instance::new(frontend, guard))
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt::{self, Debug};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ use common_config::Configurable;
|
|||||||
use common_telemetry::info;
|
use common_telemetry::info;
|
||||||
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
|
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
|
||||||
use common_version::{short_version, verbose_version};
|
use common_version::{short_version, verbose_version};
|
||||||
use meta_srv::bootstrap::MetasrvInstance;
|
use meta_srv::bootstrap::{MetasrvInstance, metasrv_builder};
|
||||||
use meta_srv::metasrv::BackendImpl;
|
use meta_srv::metasrv::BackendImpl;
|
||||||
use snafu::ResultExt;
|
use snafu::ResultExt;
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
@@ -177,7 +177,7 @@ pub struct StartCommand {
|
|||||||
backend: Option<BackendImpl>,
|
backend: Option<BackendImpl>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for StartCommand {
|
impl Debug for StartCommand {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("StartCommand")
|
f.debug_struct("StartCommand")
|
||||||
.field("rpc_bind_addr", &self.rpc_bind_addr)
|
.field("rpc_bind_addr", &self.rpc_bind_addr)
|
||||||
@@ -341,7 +341,7 @@ impl StartCommand {
|
|||||||
.await
|
.await
|
||||||
.context(StartMetaServerSnafu)?;
|
.context(StartMetaServerSnafu)?;
|
||||||
|
|
||||||
let builder = meta_srv::bootstrap::metasrv_builder(&opts, plugins, None)
|
let builder = metasrv_builder(&opts, plugins, None)
|
||||||
.await
|
.await
|
||||||
.context(error::BuildMetaServerSnafu)?;
|
.context(error::BuildMetaServerSnafu)?;
|
||||||
let metasrv = builder.build().await.context(error::BuildMetaServerSnafu)?;
|
let metasrv = builder.build().await.context(error::BuildMetaServerSnafu)?;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -20,7 +21,7 @@ use std::{fs, path};
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cache::{build_fundamental_cache_registry, with_default_composite_cache_registry};
|
use cache::{build_fundamental_cache_registry, with_default_composite_cache_registry};
|
||||||
use catalog::information_schema::InformationExtensionRef;
|
use catalog::information_schema::InformationExtensionRef;
|
||||||
use catalog::kvbackend::KvBackendCatalogManagerBuilder;
|
use catalog::kvbackend::{CatalogManagerConfiguratorRef, KvBackendCatalogManagerBuilder};
|
||||||
use catalog::process_manager::ProcessManager;
|
use catalog::process_manager::ProcessManager;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use common_base::Plugins;
|
use common_base::Plugins;
|
||||||
@@ -31,7 +32,7 @@ use common_meta::cache::LayeredCacheRegistryBuilder;
|
|||||||
use common_meta::ddl::flow_meta::FlowMetadataAllocator;
|
use common_meta::ddl::flow_meta::FlowMetadataAllocator;
|
||||||
use common_meta::ddl::table_meta::TableMetadataAllocator;
|
use common_meta::ddl::table_meta::TableMetadataAllocator;
|
||||||
use common_meta::ddl::{DdlContext, NoopRegionFailureDetectorControl};
|
use common_meta::ddl::{DdlContext, NoopRegionFailureDetectorControl};
|
||||||
use common_meta::ddl_manager::DdlManager;
|
use common_meta::ddl_manager::{DdlManager, DdlManagerConfiguratorRef};
|
||||||
use common_meta::key::flow::FlowMetadataManager;
|
use common_meta::key::flow::FlowMetadataManager;
|
||||||
use common_meta::key::{TableMetadataManager, TableMetadataManagerRef};
|
use common_meta::key::{TableMetadataManager, TableMetadataManagerRef};
|
||||||
use common_meta::kv_backend::KvBackendRef;
|
use common_meta::kv_backend::KvBackendRef;
|
||||||
@@ -57,14 +58,17 @@ use frontend::instance::StandaloneDatanodeManager;
|
|||||||
use frontend::instance::builder::FrontendBuilder;
|
use frontend::instance::builder::FrontendBuilder;
|
||||||
use frontend::server::Services;
|
use frontend::server::Services;
|
||||||
use meta_srv::metasrv::{FLOW_ID_SEQ, TABLE_ID_SEQ};
|
use meta_srv::metasrv::{FLOW_ID_SEQ, TABLE_ID_SEQ};
|
||||||
use servers::export_metrics::ExportMetricsTask;
|
use plugins::frontend::context::{
|
||||||
|
CatalogManagerConfigureContext, StandaloneCatalogManagerConfigureContext,
|
||||||
|
};
|
||||||
|
use plugins::standalone::context::DdlManagerConfigureContext;
|
||||||
use servers::tls::{TlsMode, TlsOption};
|
use servers::tls::{TlsMode, TlsOption};
|
||||||
use snafu::ResultExt;
|
use snafu::ResultExt;
|
||||||
use standalone::StandaloneInformationExtension;
|
use standalone::StandaloneInformationExtension;
|
||||||
use standalone::options::StandaloneOptions;
|
use standalone::options::StandaloneOptions;
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
|
|
||||||
use crate::error::{Result, StartFlownodeSnafu};
|
use crate::error::{OtherSnafu, Result, StartFlownodeSnafu};
|
||||||
use crate::options::{GlobalOptions, GreptimeOptions};
|
use crate::options::{GlobalOptions, GreptimeOptions};
|
||||||
use crate::{App, create_resource_limit_metrics, error, log_versions, maybe_activate_heap_profile};
|
use crate::{App, create_resource_limit_metrics, error, log_versions, maybe_activate_heap_profile};
|
||||||
|
|
||||||
@@ -117,34 +121,15 @@ pub struct Instance {
|
|||||||
flownode: FlownodeInstance,
|
flownode: FlownodeInstance,
|
||||||
procedure_manager: ProcedureManagerRef,
|
procedure_manager: ProcedureManagerRef,
|
||||||
wal_options_allocator: WalOptionsAllocatorRef,
|
wal_options_allocator: WalOptionsAllocatorRef,
|
||||||
|
|
||||||
// The components of standalone, which make it easier to expand based
|
|
||||||
// on the components.
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
components: Components,
|
|
||||||
|
|
||||||
// Keep the logging guard to prevent the worker from being dropped.
|
// Keep the logging guard to prevent the worker from being dropped.
|
||||||
_guard: Vec<WorkerGuard>,
|
_guard: Vec<WorkerGuard>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub struct Components {
|
|
||||||
pub plugins: Plugins,
|
|
||||||
pub kv_backend: KvBackendRef,
|
|
||||||
pub frontend_client: Arc<FrontendClient>,
|
|
||||||
pub catalog_manager: catalog::CatalogManagerRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
/// Find the socket addr of a server by its `name`.
|
/// Find the socket addr of a server by its `name`.
|
||||||
pub fn server_addr(&self, name: &str) -> Option<SocketAddr> {
|
pub fn server_addr(&self, name: &str) -> Option<SocketAddr> {
|
||||||
self.frontend.server_handlers().addr(name)
|
self.frontend.server_handlers().addr(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
pub fn components(&self) -> &Components {
|
|
||||||
&self.components
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -228,6 +213,8 @@ pub struct StartCommand {
|
|||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
tls_key_path: Option<String>,
|
tls_key_path: Option<String>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
|
tls_watch: bool,
|
||||||
|
#[clap(long)]
|
||||||
user_provider: Option<String>,
|
user_provider: Option<String>,
|
||||||
#[clap(long, default_value = "GREPTIMEDB_STANDALONE")]
|
#[clap(long, default_value = "GREPTIMEDB_STANDALONE")]
|
||||||
pub env_prefix: String,
|
pub env_prefix: String,
|
||||||
@@ -277,6 +264,7 @@ impl StartCommand {
|
|||||||
self.tls_mode.clone(),
|
self.tls_mode.clone(),
|
||||||
self.tls_cert_path.clone(),
|
self.tls_cert_path.clone(),
|
||||||
self.tls_key_path.clone(),
|
self.tls_key_path.clone(),
|
||||||
|
self.tls_watch,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(addr) = &self.http_addr {
|
if let Some(addr) = &self.http_addr {
|
||||||
@@ -413,6 +401,13 @@ impl StartCommand {
|
|||||||
plugins.insert::<InformationExtensionRef>(information_extension.clone());
|
plugins.insert::<InformationExtensionRef>(information_extension.clone());
|
||||||
|
|
||||||
let process_manager = Arc::new(ProcessManager::new(opts.grpc.server_addr.clone(), None));
|
let process_manager = Arc::new(ProcessManager::new(opts.grpc.server_addr.clone(), None));
|
||||||
|
|
||||||
|
// for standalone not use grpc, but get a handler to frontend grpc client without
|
||||||
|
// actually make a connection
|
||||||
|
let (frontend_client, frontend_instance_handler) =
|
||||||
|
FrontendClient::from_empty_grpc_handler(opts.query.clone());
|
||||||
|
let frontend_client = Arc::new(frontend_client);
|
||||||
|
|
||||||
let builder = KvBackendCatalogManagerBuilder::new(
|
let builder = KvBackendCatalogManagerBuilder::new(
|
||||||
information_extension.clone(),
|
information_extension.clone(),
|
||||||
kv_backend.clone(),
|
kv_backend.clone(),
|
||||||
@@ -420,9 +415,17 @@ impl StartCommand {
|
|||||||
)
|
)
|
||||||
.with_procedure_manager(procedure_manager.clone())
|
.with_procedure_manager(procedure_manager.clone())
|
||||||
.with_process_manager(process_manager.clone());
|
.with_process_manager(process_manager.clone());
|
||||||
#[cfg(feature = "enterprise")]
|
let builder = if let Some(configurator) =
|
||||||
let builder = if let Some(factories) = plugins.get() {
|
plugins.get::<CatalogManagerConfiguratorRef<CatalogManagerConfigureContext>>()
|
||||||
builder.with_extra_information_table_factories(factories)
|
{
|
||||||
|
let ctx = StandaloneCatalogManagerConfigureContext {
|
||||||
|
fe_client: frontend_client.clone(),
|
||||||
|
};
|
||||||
|
let ctx = CatalogManagerConfigureContext::Standalone(ctx);
|
||||||
|
configurator
|
||||||
|
.configure(builder, ctx)
|
||||||
|
.await
|
||||||
|
.context(OtherSnafu)?
|
||||||
} else {
|
} else {
|
||||||
builder
|
builder
|
||||||
};
|
};
|
||||||
@@ -437,11 +440,6 @@ impl StartCommand {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// for standalone not use grpc, but get a handler to frontend grpc client without
|
|
||||||
// actually make a connection
|
|
||||||
let (frontend_client, frontend_instance_handler) =
|
|
||||||
FrontendClient::from_empty_grpc_handler(opts.query.clone());
|
|
||||||
let frontend_client = Arc::new(frontend_client);
|
|
||||||
let flow_builder = FlownodeBuilder::new(
|
let flow_builder = FlownodeBuilder::new(
|
||||||
flownode_options,
|
flownode_options,
|
||||||
plugins.clone(),
|
plugins.clone(),
|
||||||
@@ -512,11 +510,21 @@ impl StartCommand {
|
|||||||
|
|
||||||
let ddl_manager = DdlManager::try_new(ddl_context, procedure_manager.clone(), true)
|
let ddl_manager = DdlManager::try_new(ddl_context, procedure_manager.clone(), true)
|
||||||
.context(error::InitDdlManagerSnafu)?;
|
.context(error::InitDdlManagerSnafu)?;
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
let ddl_manager = {
|
let ddl_manager = if let Some(configurator) =
|
||||||
let trigger_ddl_manager: Option<common_meta::ddl_manager::TriggerDdlManagerRef> =
|
plugins.get::<DdlManagerConfiguratorRef<DdlManagerConfigureContext>>()
|
||||||
plugins.get();
|
{
|
||||||
ddl_manager.with_trigger_ddl_manager(trigger_ddl_manager)
|
let ctx = DdlManagerConfigureContext {
|
||||||
|
kv_backend: kv_backend.clone(),
|
||||||
|
fe_client: frontend_client.clone(),
|
||||||
|
catalog_manager: catalog_manager.clone(),
|
||||||
|
};
|
||||||
|
configurator
|
||||||
|
.configure(ddl_manager, ctx)
|
||||||
|
.await
|
||||||
|
.context(OtherSnafu)?
|
||||||
|
} else {
|
||||||
|
ddl_manager
|
||||||
};
|
};
|
||||||
|
|
||||||
let procedure_executor = Arc::new(LocalProcedureExecutor::new(
|
let procedure_executor = Arc::new(LocalProcedureExecutor::new(
|
||||||
@@ -562,9 +570,6 @@ impl StartCommand {
|
|||||||
.context(StartFlownodeSnafu)?;
|
.context(StartFlownodeSnafu)?;
|
||||||
flow_streaming_engine.set_frontend_invoker(invoker).await;
|
flow_streaming_engine.set_frontend_invoker(invoker).await;
|
||||||
|
|
||||||
let export_metrics_task = ExportMetricsTask::try_new(&opts.export_metrics, Some(&plugins))
|
|
||||||
.context(error::ServersSnafu)?;
|
|
||||||
|
|
||||||
let servers = Services::new(opts, fe_instance.clone(), plugins.clone())
|
let servers = Services::new(opts, fe_instance.clone(), plugins.clone())
|
||||||
.build()
|
.build()
|
||||||
.context(error::StartFrontendSnafu)?;
|
.context(error::StartFrontendSnafu)?;
|
||||||
@@ -573,15 +578,6 @@ impl StartCommand {
|
|||||||
instance: fe_instance,
|
instance: fe_instance,
|
||||||
servers,
|
servers,
|
||||||
heartbeat_task: None,
|
heartbeat_task: None,
|
||||||
export_metrics_task,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
let components = Components {
|
|
||||||
plugins,
|
|
||||||
kv_backend,
|
|
||||||
frontend_client,
|
|
||||||
catalog_manager,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Instance {
|
Ok(Instance {
|
||||||
@@ -590,8 +586,6 @@ impl StartCommand {
|
|||||||
flownode,
|
flownode,
|
||||||
procedure_manager,
|
procedure_manager,
|
||||||
wal_options_allocator,
|
wal_options_allocator,
|
||||||
#[cfg(feature = "enterprise")]
|
|
||||||
components,
|
|
||||||
_guard: guard,
|
_guard: guard,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -769,6 +763,9 @@ mod tests {
|
|||||||
fn test_load_log_options_from_cli() {
|
fn test_load_log_options_from_cli() {
|
||||||
let cmd = StartCommand {
|
let cmd = StartCommand {
|
||||||
user_provider: Some("static_user_provider:cmd:test=test".to_string()),
|
user_provider: Some("static_user_provider:cmd:test=test".to_string()),
|
||||||
|
mysql_addr: Some("127.0.0.1:4002".to_string()),
|
||||||
|
postgres_addr: Some("127.0.0.1:4003".to_string()),
|
||||||
|
tls_watch: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -785,6 +782,8 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!("./greptimedb_data/test/logs", opts.logging.dir);
|
assert_eq!("./greptimedb_data/test/logs", opts.logging.dir);
|
||||||
assert_eq!("debug", opts.logging.level.unwrap());
|
assert_eq!("debug", opts.logging.level.unwrap());
|
||||||
|
assert!(opts.mysql.tls.watch);
|
||||||
|
assert!(opts.postgres.tls.watch);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ use meta_srv::selector::SelectorType;
|
|||||||
use metric_engine::config::EngineConfig as MetricEngineConfig;
|
use metric_engine::config::EngineConfig as MetricEngineConfig;
|
||||||
use mito2::config::MitoConfig;
|
use mito2::config::MitoConfig;
|
||||||
use query::options::QueryOptions;
|
use query::options::QueryOptions;
|
||||||
use servers::export_metrics::ExportMetricsOption;
|
|
||||||
use servers::grpc::GrpcOptions;
|
use servers::grpc::GrpcOptions;
|
||||||
use servers::http::HttpOptions;
|
use servers::http::HttpOptions;
|
||||||
use servers::tls::{TlsMode, TlsOption};
|
use servers::tls::{TlsMode, TlsOption};
|
||||||
@@ -95,11 +94,6 @@ fn test_load_datanode_example_config() {
|
|||||||
tracing_sample_ratio: Some(Default::default()),
|
tracing_sample_ratio: Some(Default::default()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
export_metrics: ExportMetricsOption {
|
|
||||||
self_import: None,
|
|
||||||
remote_write: Some(Default::default()),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
grpc: GrpcOptions::default()
|
grpc: GrpcOptions::default()
|
||||||
.with_bind_addr("127.0.0.1:3001")
|
.with_bind_addr("127.0.0.1:3001")
|
||||||
.with_server_addr("127.0.0.1:3001"),
|
.with_server_addr("127.0.0.1:3001"),
|
||||||
@@ -146,11 +140,6 @@ fn test_load_frontend_example_config() {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
export_metrics: ExportMetricsOption {
|
|
||||||
self_import: None,
|
|
||||||
remote_write: Some(Default::default()),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
grpc: GrpcOptions {
|
grpc: GrpcOptions {
|
||||||
bind_addr: "127.0.0.1:4001".to_string(),
|
bind_addr: "127.0.0.1:4001".to_string(),
|
||||||
server_addr: "127.0.0.1:4001".to_string(),
|
server_addr: "127.0.0.1:4001".to_string(),
|
||||||
@@ -201,11 +190,6 @@ fn test_load_metasrv_example_config() {
|
|||||||
tcp_nodelay: true,
|
tcp_nodelay: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
export_metrics: ExportMetricsOption {
|
|
||||||
self_import: None,
|
|
||||||
remote_write: Some(Default::default()),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
backend_tls: Some(TlsOption {
|
backend_tls: Some(TlsOption {
|
||||||
mode: TlsMode::Prefer,
|
mode: TlsMode::Prefer,
|
||||||
cert_path: String::new(),
|
cert_path: String::new(),
|
||||||
@@ -317,11 +301,6 @@ fn test_load_standalone_example_config() {
|
|||||||
tracing_sample_ratio: Some(Default::default()),
|
tracing_sample_ratio: Some(Default::default()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
export_metrics: ExportMetricsOption {
|
|
||||||
self_import: Some(Default::default()),
|
|
||||||
remote_write: Some(Default::default()),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
http: HttpOptions {
|
http: HttpOptions {
|
||||||
cors_allowed_origins: vec!["https://example.com".to_string()],
|
cors_allowed_origins: vec!["https://example.com".to_string()],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
@@ -32,7 +32,12 @@ impl Plugins {
|
|||||||
|
|
||||||
pub fn insert<T: 'static + Send + Sync>(&self, value: T) {
|
pub fn insert<T: 'static + Send + Sync>(&self, value: T) {
|
||||||
let last = self.write().insert(value);
|
let last = self.write().insert(value);
|
||||||
assert!(last.is_none(), "each type of plugins must be one and only");
|
if last.is_some() {
|
||||||
|
panic!(
|
||||||
|
"Plugin of type {} already exists",
|
||||||
|
std::any::type_name::<T>()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get<T: 'static + Send + Sync + Clone>(&self) -> Option<T> {
|
pub fn get<T: 'static + Send + Sync + Clone>(&self) -> Option<T> {
|
||||||
@@ -140,7 +145,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "each type of plugins must be one and only")]
|
#[should_panic(expected = "Plugin of type i32 already exists")]
|
||||||
fn test_plugin_uniqueness() {
|
fn test_plugin_uniqueness() {
|
||||||
let plugins = Plugins::new();
|
let plugins = Plugins::new();
|
||||||
plugins.insert(1i32);
|
plugins.insert(1i32);
|
||||||
|
|||||||
@@ -86,8 +86,6 @@ pub const INFORMATION_SCHEMA_TRIGGERS_TABLE_ID: u32 = 24;
|
|||||||
pub const INFORMATION_SCHEMA_GLOBAL_STATUS_TABLE_ID: u32 = 25;
|
pub const INFORMATION_SCHEMA_GLOBAL_STATUS_TABLE_ID: u32 = 25;
|
||||||
/// id for information_schema.SESSION_STATUS
|
/// id for information_schema.SESSION_STATUS
|
||||||
pub const INFORMATION_SCHEMA_SESSION_STATUS_TABLE_ID: u32 = 26;
|
pub const INFORMATION_SCHEMA_SESSION_STATUS_TABLE_ID: u32 = 26;
|
||||||
/// id for information_schema.RUNTIME_METRICS
|
|
||||||
pub const INFORMATION_SCHEMA_RUNTIME_METRICS_TABLE_ID: u32 = 27;
|
|
||||||
/// id for information_schema.PARTITIONS
|
/// id for information_schema.PARTITIONS
|
||||||
pub const INFORMATION_SCHEMA_PARTITIONS_TABLE_ID: u32 = 28;
|
pub const INFORMATION_SCHEMA_PARTITIONS_TABLE_ID: u32 = 28;
|
||||||
/// id for information_schema.REGION_PEERS
|
/// id for information_schema.REGION_PEERS
|
||||||
@@ -112,6 +110,8 @@ pub const INFORMATION_SCHEMA_SSTS_MANIFEST_TABLE_ID: u32 = 37;
|
|||||||
pub const INFORMATION_SCHEMA_SSTS_STORAGE_TABLE_ID: u32 = 38;
|
pub const INFORMATION_SCHEMA_SSTS_STORAGE_TABLE_ID: u32 = 38;
|
||||||
/// id for information_schema.ssts_index_meta
|
/// id for information_schema.ssts_index_meta
|
||||||
pub const INFORMATION_SCHEMA_SSTS_INDEX_META_TABLE_ID: u32 = 39;
|
pub const INFORMATION_SCHEMA_SSTS_INDEX_META_TABLE_ID: u32 = 39;
|
||||||
|
/// id for information_schema.alerts
|
||||||
|
pub const INFORMATION_SCHEMA_ALERTS_TABLE_ID: u32 = 40;
|
||||||
|
|
||||||
// ----- End of information_schema tables -----
|
// ----- End of information_schema tables -----
|
||||||
|
|
||||||
|
|||||||
@@ -12,28 +12,11 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::future::Future;
|
|
||||||
|
|
||||||
use arrow::record_batch::RecordBatch;
|
use arrow::record_batch::RecordBatch;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use datafusion::parquet::format::FileMetaData;
|
use datafusion::parquet::format::FileMetaData;
|
||||||
use snafu::{OptionExt, ResultExt};
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
|
||||||
|
|
||||||
use crate::error::{self, Result};
|
use crate::error::Result;
|
||||||
use crate::share_buffer::SharedBuffer;
|
|
||||||
|
|
||||||
pub struct LazyBufferedWriter<T, U, F> {
|
|
||||||
path: String,
|
|
||||||
writer_factory: F,
|
|
||||||
writer: Option<T>,
|
|
||||||
/// None stands for [`LazyBufferedWriter`] closed.
|
|
||||||
encoder: Option<U>,
|
|
||||||
buffer: SharedBuffer,
|
|
||||||
rows_written: usize,
|
|
||||||
bytes_written: u64,
|
|
||||||
threshold: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait DfRecordBatchEncoder {
|
pub trait DfRecordBatchEncoder {
|
||||||
fn write(&mut self, batch: &RecordBatch) -> Result<()>;
|
fn write(&mut self, batch: &RecordBatch) -> Result<()>;
|
||||||
@@ -43,126 +26,3 @@ pub trait DfRecordBatchEncoder {
|
|||||||
pub trait ArrowWriterCloser {
|
pub trait ArrowWriterCloser {
|
||||||
async fn close(mut self) -> Result<FileMetaData>;
|
async fn close(mut self) -> Result<FileMetaData>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
|
||||||
T: AsyncWrite + Send + Unpin,
|
|
||||||
U: DfRecordBatchEncoder + ArrowWriterCloser,
|
|
||||||
F: Fn(String) -> Fut,
|
|
||||||
Fut: Future<Output = Result<T>>,
|
|
||||||
> LazyBufferedWriter<T, U, F>
|
|
||||||
{
|
|
||||||
/// Closes `LazyBufferedWriter` and optionally flushes all data to underlying storage
|
|
||||||
/// if any row's been written.
|
|
||||||
pub async fn close_with_arrow_writer(mut self) -> Result<(FileMetaData, u64)> {
|
|
||||||
let encoder = self
|
|
||||||
.encoder
|
|
||||||
.take()
|
|
||||||
.context(error::BufferedWriterClosedSnafu)?;
|
|
||||||
let metadata = encoder.close().await?;
|
|
||||||
|
|
||||||
// It's important to shut down! flushes all pending writes
|
|
||||||
self.close_inner_writer().await?;
|
|
||||||
Ok((metadata, self.bytes_written))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<
|
|
||||||
T: AsyncWrite + Send + Unpin,
|
|
||||||
U: DfRecordBatchEncoder,
|
|
||||||
F: Fn(String) -> Fut,
|
|
||||||
Fut: Future<Output = Result<T>>,
|
|
||||||
> LazyBufferedWriter<T, U, F>
|
|
||||||
{
|
|
||||||
/// Closes the writer and flushes the buffer data.
|
|
||||||
pub async fn close_inner_writer(&mut self) -> Result<()> {
|
|
||||||
// Use `rows_written` to keep a track of if any rows have been written.
|
|
||||||
// If no row's been written, then we can simply close the underlying
|
|
||||||
// writer without flush so that no file will be actually created.
|
|
||||||
if self.rows_written != 0 {
|
|
||||||
self.bytes_written += self.try_flush(true).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(writer) = &mut self.writer {
|
|
||||||
writer.shutdown().await.context(error::AsyncWriteSnafu)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(
|
|
||||||
threshold: usize,
|
|
||||||
buffer: SharedBuffer,
|
|
||||||
encoder: U,
|
|
||||||
path: impl AsRef<str>,
|
|
||||||
writer_factory: F,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
path: path.as_ref().to_string(),
|
|
||||||
threshold,
|
|
||||||
encoder: Some(encoder),
|
|
||||||
buffer,
|
|
||||||
rows_written: 0,
|
|
||||||
bytes_written: 0,
|
|
||||||
writer_factory,
|
|
||||||
writer: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn write(&mut self, batch: &RecordBatch) -> Result<()> {
|
|
||||||
let encoder = self
|
|
||||||
.encoder
|
|
||||||
.as_mut()
|
|
||||||
.context(error::BufferedWriterClosedSnafu)?;
|
|
||||||
encoder.write(batch)?;
|
|
||||||
self.rows_written += batch.num_rows();
|
|
||||||
self.bytes_written += self.try_flush(false).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn try_flush(&mut self, all: bool) -> Result<u64> {
|
|
||||||
let mut bytes_written: u64 = 0;
|
|
||||||
|
|
||||||
// Once buffered data size reaches threshold, split the data in chunks (typically 4MB)
|
|
||||||
// and write to underlying storage.
|
|
||||||
while self.buffer.buffer.lock().unwrap().len() >= self.threshold {
|
|
||||||
let chunk = {
|
|
||||||
let mut buffer = self.buffer.buffer.lock().unwrap();
|
|
||||||
buffer.split_to(self.threshold)
|
|
||||||
};
|
|
||||||
let size = chunk.len();
|
|
||||||
|
|
||||||
self.maybe_init_writer()
|
|
||||||
.await?
|
|
||||||
.write_all(&chunk)
|
|
||||||
.await
|
|
||||||
.context(error::AsyncWriteSnafu)?;
|
|
||||||
|
|
||||||
bytes_written += size as u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
if all {
|
|
||||||
bytes_written += self.try_flush_all().await?;
|
|
||||||
}
|
|
||||||
Ok(bytes_written)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Only initiates underlying file writer when rows have been written.
|
|
||||||
async fn maybe_init_writer(&mut self) -> Result<&mut T> {
|
|
||||||
if let Some(ref mut writer) = self.writer {
|
|
||||||
Ok(writer)
|
|
||||||
} else {
|
|
||||||
let writer = (self.writer_factory)(self.path.clone()).await?;
|
|
||||||
Ok(self.writer.insert(writer))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn try_flush_all(&mut self) -> Result<u64> {
|
|
||||||
let remain = self.buffer.buffer.lock().unwrap().split();
|
|
||||||
let size = remain.len();
|
|
||||||
self.maybe_init_writer()
|
|
||||||
.await?
|
|
||||||
.write_all(&remain)
|
|
||||||
.await
|
|
||||||
.context(error::AsyncWriteSnafu)?;
|
|
||||||
Ok(size as u64)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
202
src/common/datasource/src/compressed_writer.rs
Normal file
202
src/common/datasource/src/compressed_writer.rs
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
// Copyright 2023 Greptime Team
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
use std::pin::Pin;
|
||||||
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
|
use async_compression::tokio::write::{BzEncoder, GzipEncoder, XzEncoder, ZstdEncoder};
|
||||||
|
use snafu::ResultExt;
|
||||||
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
|
use crate::compression::CompressionType;
|
||||||
|
use crate::error::{self, Result};
|
||||||
|
|
||||||
|
/// A compressed writer that wraps an underlying async writer with compression.
|
||||||
|
///
|
||||||
|
/// This writer supports multiple compression formats including GZIP, BZIP2, XZ, and ZSTD.
|
||||||
|
/// It provides transparent compression for any async writer implementation.
|
||||||
|
pub struct CompressedWriter {
|
||||||
|
inner: Box<dyn AsyncWrite + Unpin + Send>,
|
||||||
|
compression_type: CompressionType,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompressedWriter {
|
||||||
|
/// Creates a new compressed writer with the specified compression type.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `writer` - The underlying writer to wrap with compression
|
||||||
|
/// * `compression_type` - The type of compression to apply
|
||||||
|
pub fn new(
|
||||||
|
writer: impl AsyncWrite + Unpin + Send + 'static,
|
||||||
|
compression_type: CompressionType,
|
||||||
|
) -> Self {
|
||||||
|
let inner: Box<dyn AsyncWrite + Unpin + Send> = match compression_type {
|
||||||
|
CompressionType::Gzip => Box::new(GzipEncoder::new(writer)),
|
||||||
|
CompressionType::Bzip2 => Box::new(BzEncoder::new(writer)),
|
||||||
|
CompressionType::Xz => Box::new(XzEncoder::new(writer)),
|
||||||
|
CompressionType::Zstd => Box::new(ZstdEncoder::new(writer)),
|
||||||
|
CompressionType::Uncompressed => Box::new(writer),
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
compression_type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the compression type used by this writer.
|
||||||
|
pub fn compression_type(&self) -> CompressionType {
|
||||||
|
self.compression_type
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flush the writer and shutdown compression
|
||||||
|
pub async fn shutdown(mut self) -> Result<()> {
|
||||||
|
self.inner
|
||||||
|
.shutdown()
|
||||||
|
.await
|
||||||
|
.context(error::AsyncWriteSnafu)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsyncWrite for CompressedWriter {
|
||||||
|
fn poll_write(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
buf: &[u8],
|
||||||
|
) -> Poll<io::Result<usize>> {
|
||||||
|
Pin::new(&mut self.inner).poll_write(cx, buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||||
|
Pin::new(&mut self.inner).poll_flush(cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||||
|
Pin::new(&mut self.inner).poll_shutdown(cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trait for converting async writers into compressed writers.
|
||||||
|
///
|
||||||
|
/// This trait is automatically implemented for all types that implement [`AsyncWrite`].
|
||||||
|
pub trait IntoCompressedWriter {
|
||||||
|
/// Converts this writer into a [`CompressedWriter`] with the specified compression type.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `self` - The underlying writer to wrap with compression
|
||||||
|
/// * `compression_type` - The type of compression to apply
|
||||||
|
fn into_compressed_writer(self, compression_type: CompressionType) -> CompressedWriter
|
||||||
|
where
|
||||||
|
Self: AsyncWrite + Unpin + Send + 'static + Sized,
|
||||||
|
{
|
||||||
|
CompressedWriter::new(self, compression_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<W: AsyncWrite + Unpin + Send + 'static> IntoCompressedWriter for W {}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use tokio::io::{AsyncReadExt, AsyncWriteExt, duplex};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_writer_gzip() {
|
||||||
|
let (duplex_writer, mut duplex_reader) = duplex(1024);
|
||||||
|
let mut writer = duplex_writer.into_compressed_writer(CompressionType::Gzip);
|
||||||
|
let original = b"test data for gzip compression";
|
||||||
|
|
||||||
|
writer.write_all(original).await.unwrap();
|
||||||
|
writer.shutdown().await.unwrap();
|
||||||
|
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
duplex_reader.read_to_end(&mut buffer).await.unwrap();
|
||||||
|
|
||||||
|
// The compressed data should be different from the original
|
||||||
|
assert_ne!(buffer, original);
|
||||||
|
assert!(!buffer.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_writer_bzip2() {
|
||||||
|
let (duplex_writer, mut duplex_reader) = duplex(1024);
|
||||||
|
let mut writer = duplex_writer.into_compressed_writer(CompressionType::Bzip2);
|
||||||
|
let original = b"test data for bzip2 compression";
|
||||||
|
|
||||||
|
writer.write_all(original).await.unwrap();
|
||||||
|
writer.shutdown().await.unwrap();
|
||||||
|
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
duplex_reader.read_to_end(&mut buffer).await.unwrap();
|
||||||
|
|
||||||
|
// The compressed data should be different from the original
|
||||||
|
assert_ne!(buffer, original);
|
||||||
|
assert!(!buffer.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_writer_xz() {
|
||||||
|
let (duplex_writer, mut duplex_reader) = duplex(1024);
|
||||||
|
let mut writer = duplex_writer.into_compressed_writer(CompressionType::Xz);
|
||||||
|
let original = b"test data for xz compression";
|
||||||
|
|
||||||
|
writer.write_all(original).await.unwrap();
|
||||||
|
writer.shutdown().await.unwrap();
|
||||||
|
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
duplex_reader.read_to_end(&mut buffer).await.unwrap();
|
||||||
|
|
||||||
|
// The compressed data should be different from the original
|
||||||
|
assert_ne!(buffer, original);
|
||||||
|
assert!(!buffer.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_writer_zstd() {
|
||||||
|
let (duplex_writer, mut duplex_reader) = duplex(1024);
|
||||||
|
let mut writer = duplex_writer.into_compressed_writer(CompressionType::Zstd);
|
||||||
|
let original = b"test data for zstd compression";
|
||||||
|
|
||||||
|
writer.write_all(original).await.unwrap();
|
||||||
|
writer.shutdown().await.unwrap();
|
||||||
|
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
duplex_reader.read_to_end(&mut buffer).await.unwrap();
|
||||||
|
|
||||||
|
// The compressed data should be different from the original
|
||||||
|
assert_ne!(buffer, original);
|
||||||
|
assert!(!buffer.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_writer_uncompressed() {
|
||||||
|
let (duplex_writer, mut duplex_reader) = duplex(1024);
|
||||||
|
let mut writer = duplex_writer.into_compressed_writer(CompressionType::Uncompressed);
|
||||||
|
let original = b"test data for uncompressed";
|
||||||
|
|
||||||
|
writer.write_all(original).await.unwrap();
|
||||||
|
writer.shutdown().await.unwrap();
|
||||||
|
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
duplex_reader.read_to_end(&mut buffer).await.unwrap();
|
||||||
|
|
||||||
|
// Uncompressed data should be the same as the original
|
||||||
|
assert_eq!(buffer, original);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -194,12 +194,6 @@ pub enum Error {
|
|||||||
location: Location,
|
location: Location,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[snafu(display("Buffered writer closed"))]
|
|
||||||
BufferedWriterClosed {
|
|
||||||
#[snafu(implicit)]
|
|
||||||
location: Location,
|
|
||||||
},
|
|
||||||
|
|
||||||
#[snafu(display("Failed to write parquet file, path: {}", path))]
|
#[snafu(display("Failed to write parquet file, path: {}", path))]
|
||||||
WriteParquet {
|
WriteParquet {
|
||||||
path: String,
|
path: String,
|
||||||
@@ -208,6 +202,14 @@ pub enum Error {
|
|||||||
#[snafu(source)]
|
#[snafu(source)]
|
||||||
error: parquet::errors::ParquetError,
|
error: parquet::errors::ParquetError,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#[snafu(display("Failed to build file stream"))]
|
||||||
|
BuildFileStream {
|
||||||
|
#[snafu(implicit)]
|
||||||
|
location: Location,
|
||||||
|
#[snafu(source)]
|
||||||
|
error: datafusion::error::DataFusionError,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -239,7 +241,7 @@ impl ErrorExt for Error {
|
|||||||
| ReadRecordBatch { .. }
|
| ReadRecordBatch { .. }
|
||||||
| WriteRecordBatch { .. }
|
| WriteRecordBatch { .. }
|
||||||
| EncodeRecordBatch { .. }
|
| EncodeRecordBatch { .. }
|
||||||
| BufferedWriterClosed { .. }
|
| BuildFileStream { .. }
|
||||||
| OrcReader { .. } => StatusCode::Unexpected,
|
| OrcReader { .. } => StatusCode::Unexpected,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,22 @@ use arrow::record_batch::RecordBatch;
|
|||||||
use arrow_schema::{ArrowError, Schema as ArrowSchema};
|
use arrow_schema::{ArrowError, Schema as ArrowSchema};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use bytes::{Buf, Bytes};
|
use bytes::{Buf, Bytes};
|
||||||
use datafusion::datasource::physical_plan::FileOpenFuture;
|
use common_recordbatch::DfSendableRecordBatchStream;
|
||||||
|
use datafusion::datasource::file_format::file_compression_type::FileCompressionType as DfCompressionType;
|
||||||
|
use datafusion::datasource::listing::PartitionedFile;
|
||||||
|
use datafusion::datasource::object_store::ObjectStoreUrl;
|
||||||
|
use datafusion::datasource::physical_plan::{
|
||||||
|
FileGroup, FileOpenFuture, FileScanConfigBuilder, FileSource, FileStream,
|
||||||
|
};
|
||||||
use datafusion::error::{DataFusionError, Result as DataFusionResult};
|
use datafusion::error::{DataFusionError, Result as DataFusionResult};
|
||||||
use datafusion::physical_plan::SendableRecordBatchStream;
|
use datafusion::physical_plan::SendableRecordBatchStream;
|
||||||
|
use datafusion::physical_plan::metrics::ExecutionPlanMetricsSet;
|
||||||
|
use datatypes::arrow::datatypes::SchemaRef;
|
||||||
use futures::{StreamExt, TryStreamExt};
|
use futures::{StreamExt, TryStreamExt};
|
||||||
use object_store::ObjectStore;
|
use object_store::ObjectStore;
|
||||||
|
use object_store_opendal::OpendalStore;
|
||||||
use snafu::ResultExt;
|
use snafu::ResultExt;
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio_util::compat::FuturesAsyncWriteCompatExt;
|
use tokio_util::compat::FuturesAsyncWriteCompatExt;
|
||||||
|
|
||||||
use self::csv::CsvFormat;
|
use self::csv::CsvFormat;
|
||||||
@@ -43,7 +53,8 @@ use self::json::JsonFormat;
|
|||||||
use self::orc::OrcFormat;
|
use self::orc::OrcFormat;
|
||||||
use self::parquet::ParquetFormat;
|
use self::parquet::ParquetFormat;
|
||||||
use crate::DEFAULT_WRITE_BUFFER_SIZE;
|
use crate::DEFAULT_WRITE_BUFFER_SIZE;
|
||||||
use crate::buffered_writer::{DfRecordBatchEncoder, LazyBufferedWriter};
|
use crate::buffered_writer::DfRecordBatchEncoder;
|
||||||
|
use crate::compressed_writer::{CompressedWriter, IntoCompressedWriter};
|
||||||
use crate::compression::CompressionType;
|
use crate::compression::CompressionType;
|
||||||
use crate::error::{self, Result};
|
use crate::error::{self, Result};
|
||||||
use crate::share_buffer::SharedBuffer;
|
use crate::share_buffer::SharedBuffer;
|
||||||
@@ -195,33 +206,128 @@ pub async fn infer_schemas(
|
|||||||
ArrowSchema::try_merge(schemas).context(error::MergeSchemaSnafu)
|
ArrowSchema::try_merge(schemas).context(error::MergeSchemaSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stream_to_file<T: DfRecordBatchEncoder, U: Fn(SharedBuffer) -> T>(
|
/// Writes data to a compressed writer if the data is not empty.
|
||||||
|
///
|
||||||
|
/// Does nothing if `data` is empty; otherwise writes all data and returns any error.
|
||||||
|
async fn write_to_compressed_writer(
|
||||||
|
compressed_writer: &mut CompressedWriter,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
if !data.is_empty() {
|
||||||
|
compressed_writer
|
||||||
|
.write_all(data)
|
||||||
|
.await
|
||||||
|
.context(error::AsyncWriteSnafu)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Streams [SendableRecordBatchStream] to a file with optional compression support.
|
||||||
|
/// Data is buffered and flushed according to the given `threshold`.
|
||||||
|
/// Ensures that writer resources are cleanly released and that an empty file is not
|
||||||
|
/// created if no rows are written.
|
||||||
|
///
|
||||||
|
/// Returns the total number of rows successfully written.
|
||||||
|
pub async fn stream_to_file<E>(
|
||||||
mut stream: SendableRecordBatchStream,
|
mut stream: SendableRecordBatchStream,
|
||||||
store: ObjectStore,
|
store: ObjectStore,
|
||||||
path: &str,
|
path: &str,
|
||||||
threshold: usize,
|
threshold: usize,
|
||||||
concurrency: usize,
|
concurrency: usize,
|
||||||
encoder_factory: U,
|
compression_type: CompressionType,
|
||||||
) -> Result<usize> {
|
encoder_factory: impl Fn(SharedBuffer) -> E,
|
||||||
|
) -> Result<usize>
|
||||||
|
where
|
||||||
|
E: DfRecordBatchEncoder,
|
||||||
|
{
|
||||||
|
// Create the file writer with OpenDAL's built-in buffering
|
||||||
|
let writer = store
|
||||||
|
.writer_with(path)
|
||||||
|
.concurrent(concurrency)
|
||||||
|
.chunk(DEFAULT_WRITE_BUFFER_SIZE.as_bytes() as usize)
|
||||||
|
.await
|
||||||
|
.with_context(|_| error::WriteObjectSnafu { path })?
|
||||||
|
.into_futures_async_write()
|
||||||
|
.compat_write();
|
||||||
|
|
||||||
|
// Apply compression if needed
|
||||||
|
let mut compressed_writer = writer.into_compressed_writer(compression_type);
|
||||||
|
|
||||||
|
// Create a buffer for the encoder
|
||||||
let buffer = SharedBuffer::with_capacity(threshold);
|
let buffer = SharedBuffer::with_capacity(threshold);
|
||||||
let encoder = encoder_factory(buffer.clone());
|
let mut encoder = encoder_factory(buffer.clone());
|
||||||
let mut writer = LazyBufferedWriter::new(threshold, buffer, encoder, path, |path| async {
|
|
||||||
store
|
|
||||||
.writer_with(&path)
|
|
||||||
.concurrent(concurrency)
|
|
||||||
.chunk(DEFAULT_WRITE_BUFFER_SIZE.as_bytes() as usize)
|
|
||||||
.await
|
|
||||||
.map(|v| v.into_futures_async_write().compat_write())
|
|
||||||
.context(error::WriteObjectSnafu { path })
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut rows = 0;
|
let mut rows = 0;
|
||||||
|
|
||||||
|
// Process each record batch
|
||||||
while let Some(batch) = stream.next().await {
|
while let Some(batch) = stream.next().await {
|
||||||
let batch = batch.context(error::ReadRecordBatchSnafu)?;
|
let batch = batch.context(error::ReadRecordBatchSnafu)?;
|
||||||
writer.write(&batch).await?;
|
|
||||||
|
// Write batch using the encoder
|
||||||
|
encoder.write(&batch)?;
|
||||||
rows += batch.num_rows();
|
rows += batch.num_rows();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let chunk = {
|
||||||
|
let mut buffer_guard = buffer.buffer.lock().unwrap();
|
||||||
|
if buffer_guard.len() < threshold {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer_guard.split_to(threshold)
|
||||||
|
};
|
||||||
|
write_to_compressed_writer(&mut compressed_writer, &chunk).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writer.close_inner_writer().await?;
|
|
||||||
|
// If no row's been written, just simply close the underlying writer
|
||||||
|
// without flush so that no file will be actually created.
|
||||||
|
if rows != 0 {
|
||||||
|
// Final flush of any remaining data
|
||||||
|
let final_data = {
|
||||||
|
let mut buffer_guard = buffer.buffer.lock().unwrap();
|
||||||
|
buffer_guard.split()
|
||||||
|
};
|
||||||
|
write_to_compressed_writer(&mut compressed_writer, &final_data).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shutdown compression and close writer
|
||||||
|
compressed_writer.shutdown().await?;
|
||||||
|
|
||||||
Ok(rows)
|
Ok(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a [FileStream] for reading data from a file with optional column projection
|
||||||
|
/// and compression support.
|
||||||
|
///
|
||||||
|
/// Returns [SendableRecordBatchStream].
|
||||||
|
pub async fn file_to_stream(
|
||||||
|
store: &ObjectStore,
|
||||||
|
filename: &str,
|
||||||
|
file_schema: SchemaRef,
|
||||||
|
file_source: Arc<dyn FileSource>,
|
||||||
|
projection: Option<Vec<usize>>,
|
||||||
|
compression_type: CompressionType,
|
||||||
|
) -> Result<DfSendableRecordBatchStream> {
|
||||||
|
let df_compression: DfCompressionType = compression_type.into();
|
||||||
|
let config = FileScanConfigBuilder::new(
|
||||||
|
ObjectStoreUrl::local_filesystem(),
|
||||||
|
file_schema,
|
||||||
|
file_source.clone(),
|
||||||
|
)
|
||||||
|
.with_file_group(FileGroup::new(vec![PartitionedFile::new(
|
||||||
|
filename.to_string(),
|
||||||
|
0,
|
||||||
|
)]))
|
||||||
|
.with_projection(projection)
|
||||||
|
.with_file_compression_type(df_compression)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let store = Arc::new(OpendalStore::new(store.clone()));
|
||||||
|
let file_opener = file_source
|
||||||
|
.with_projection(&config)
|
||||||
|
.create_file_opener(store, &config, 0);
|
||||||
|
let stream = FileStream::new(&config, 0, file_opener, &ExecutionPlanMetricsSet::new())
|
||||||
|
.context(error::BuildFileStreamSnafu)?;
|
||||||
|
|
||||||
|
Ok(Box::pin(stream))
|
||||||
|
}
|
||||||
|
|||||||
@@ -157,19 +157,27 @@ pub async fn stream_to_csv(
|
|||||||
concurrency: usize,
|
concurrency: usize,
|
||||||
format: &CsvFormat,
|
format: &CsvFormat,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
stream_to_file(stream, store, path, threshold, concurrency, |buffer| {
|
stream_to_file(
|
||||||
let mut builder = WriterBuilder::new();
|
stream,
|
||||||
if let Some(timestamp_format) = &format.timestamp_format {
|
store,
|
||||||
builder = builder.with_timestamp_format(timestamp_format.to_owned())
|
path,
|
||||||
}
|
threshold,
|
||||||
if let Some(date_format) = &format.date_format {
|
concurrency,
|
||||||
builder = builder.with_date_format(date_format.to_owned())
|
format.compression_type,
|
||||||
}
|
|buffer| {
|
||||||
if let Some(time_format) = &format.time_format {
|
let mut builder = WriterBuilder::new();
|
||||||
builder = builder.with_time_format(time_format.to_owned())
|
if let Some(timestamp_format) = &format.timestamp_format {
|
||||||
}
|
builder = builder.with_timestamp_format(timestamp_format.to_owned())
|
||||||
builder.build(buffer)
|
}
|
||||||
})
|
if let Some(date_format) = &format.date_format {
|
||||||
|
builder = builder.with_date_format(date_format.to_owned())
|
||||||
|
}
|
||||||
|
if let Some(time_format) = &format.time_format {
|
||||||
|
builder = builder.with_time_format(time_format.to_owned())
|
||||||
|
}
|
||||||
|
builder.build(buffer)
|
||||||
|
},
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,13 +189,21 @@ impl DfRecordBatchEncoder for csv::Writer<SharedBuffer> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use common_recordbatch::adapter::DfRecordBatchStreamAdapter;
|
||||||
|
use common_recordbatch::{RecordBatch, RecordBatches};
|
||||||
use common_test_util::find_workspace_path;
|
use common_test_util::find_workspace_path;
|
||||||
|
use datafusion::datasource::physical_plan::{CsvSource, FileSource};
|
||||||
|
use datatypes::prelude::ConcreteDataType;
|
||||||
|
use datatypes::schema::{ColumnSchema, Schema};
|
||||||
|
use datatypes::vectors::{Float64Vector, StringVector, UInt32Vector, VectorRef};
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::file_format::{
|
use crate::file_format::{
|
||||||
FORMAT_COMPRESSION_TYPE, FORMAT_DELIMITER, FORMAT_HAS_HEADER,
|
FORMAT_COMPRESSION_TYPE, FORMAT_DELIMITER, FORMAT_HAS_HEADER,
|
||||||
FORMAT_SCHEMA_INFER_MAX_RECORD, FileFormat,
|
FORMAT_SCHEMA_INFER_MAX_RECORD, FileFormat, file_to_stream,
|
||||||
};
|
};
|
||||||
use crate::test_util::{format_schema, test_store};
|
use crate::test_util::{format_schema, test_store};
|
||||||
|
|
||||||
@@ -297,4 +313,166 @@ mod tests {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_csv() {
|
||||||
|
// Create test data
|
||||||
|
let column_schemas = vec![
|
||||||
|
ColumnSchema::new("id", ConcreteDataType::uint32_datatype(), false),
|
||||||
|
ColumnSchema::new("name", ConcreteDataType::string_datatype(), false),
|
||||||
|
ColumnSchema::new("value", ConcreteDataType::float64_datatype(), false),
|
||||||
|
];
|
||||||
|
let schema = Arc::new(Schema::new(column_schemas));
|
||||||
|
|
||||||
|
// Create multiple record batches with different data
|
||||||
|
let batch1_columns: Vec<VectorRef> = vec![
|
||||||
|
Arc::new(UInt32Vector::from_slice(vec![1, 2, 3])),
|
||||||
|
Arc::new(StringVector::from(vec!["Alice", "Bob", "Charlie"])),
|
||||||
|
Arc::new(Float64Vector::from_slice(vec![10.5, 20.3, 30.7])),
|
||||||
|
];
|
||||||
|
let batch1 = RecordBatch::new(schema.clone(), batch1_columns).unwrap();
|
||||||
|
|
||||||
|
let batch2_columns: Vec<VectorRef> = vec![
|
||||||
|
Arc::new(UInt32Vector::from_slice(vec![4, 5, 6])),
|
||||||
|
Arc::new(StringVector::from(vec!["David", "Eva", "Frank"])),
|
||||||
|
Arc::new(Float64Vector::from_slice(vec![40.1, 50.2, 60.3])),
|
||||||
|
];
|
||||||
|
let batch2 = RecordBatch::new(schema.clone(), batch2_columns).unwrap();
|
||||||
|
|
||||||
|
let batch3_columns: Vec<VectorRef> = vec![
|
||||||
|
Arc::new(UInt32Vector::from_slice(vec![7, 8, 9])),
|
||||||
|
Arc::new(StringVector::from(vec!["Grace", "Henry", "Ivy"])),
|
||||||
|
Arc::new(Float64Vector::from_slice(vec![70.4, 80.5, 90.6])),
|
||||||
|
];
|
||||||
|
let batch3 = RecordBatch::new(schema.clone(), batch3_columns).unwrap();
|
||||||
|
|
||||||
|
// Combine all batches into a RecordBatches collection
|
||||||
|
let recordbatches = RecordBatches::try_new(schema, vec![batch1, batch2, batch3]).unwrap();
|
||||||
|
|
||||||
|
// Test with different compression types
|
||||||
|
let compression_types = vec![
|
||||||
|
CompressionType::Gzip,
|
||||||
|
CompressionType::Bzip2,
|
||||||
|
CompressionType::Xz,
|
||||||
|
CompressionType::Zstd,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Create a temporary file path
|
||||||
|
let temp_dir = common_test_util::temp_dir::create_temp_dir("test_compressed_csv");
|
||||||
|
for compression_type in compression_types {
|
||||||
|
let format = CsvFormat {
|
||||||
|
compression_type,
|
||||||
|
..CsvFormat::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use correct format without Debug formatter
|
||||||
|
let compressed_file_name =
|
||||||
|
format!("test_compressed_csv.{}", compression_type.file_extension());
|
||||||
|
let compressed_file_path = temp_dir.path().join(&compressed_file_name);
|
||||||
|
let compressed_file_path_str = compressed_file_path.to_str().unwrap();
|
||||||
|
|
||||||
|
// Create a simple file store for testing
|
||||||
|
let store = test_store("/");
|
||||||
|
|
||||||
|
// Export CSV with compression
|
||||||
|
let rows = stream_to_csv(
|
||||||
|
Box::pin(DfRecordBatchStreamAdapter::new(recordbatches.as_stream())),
|
||||||
|
store,
|
||||||
|
compressed_file_path_str,
|
||||||
|
1024,
|
||||||
|
1,
|
||||||
|
&format,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(rows, 9);
|
||||||
|
|
||||||
|
// Verify compressed file was created and has content
|
||||||
|
assert!(compressed_file_path.exists());
|
||||||
|
let file_size = std::fs::metadata(&compressed_file_path).unwrap().len();
|
||||||
|
assert!(file_size > 0);
|
||||||
|
|
||||||
|
// Verify the file is actually compressed
|
||||||
|
let file_content = std::fs::read(&compressed_file_path).unwrap();
|
||||||
|
// Compressed files should not start with CSV header
|
||||||
|
// They should have compression magic bytes
|
||||||
|
match compression_type {
|
||||||
|
CompressionType::Gzip => {
|
||||||
|
// Gzip magic bytes: 0x1f 0x8b
|
||||||
|
assert_eq!(file_content[0], 0x1f, "Gzip file should start with 0x1f");
|
||||||
|
assert_eq!(
|
||||||
|
file_content[1], 0x8b,
|
||||||
|
"Gzip file should have 0x8b as second byte"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CompressionType::Bzip2 => {
|
||||||
|
// Bzip2 magic bytes: 'BZ'
|
||||||
|
assert_eq!(file_content[0], b'B', "Bzip2 file should start with 'B'");
|
||||||
|
assert_eq!(
|
||||||
|
file_content[1], b'Z',
|
||||||
|
"Bzip2 file should have 'Z' as second byte"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CompressionType::Xz => {
|
||||||
|
// XZ magic bytes: 0xFD '7zXZ'
|
||||||
|
assert_eq!(file_content[0], 0xFD, "XZ file should start with 0xFD");
|
||||||
|
}
|
||||||
|
CompressionType::Zstd => {
|
||||||
|
// Zstd magic bytes: 0x28 0xB5 0x2F 0xFD
|
||||||
|
assert_eq!(file_content[0], 0x28, "Zstd file should start with 0x28");
|
||||||
|
assert_eq!(
|
||||||
|
file_content[1], 0xB5,
|
||||||
|
"Zstd file should have 0xB5 as second byte"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the compressed file can be decompressed and content matches original data
|
||||||
|
let store = test_store("/");
|
||||||
|
let schema = Arc::new(
|
||||||
|
CsvFormat {
|
||||||
|
compression_type,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.infer_schema(&store, compressed_file_path_str)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let csv_source = CsvSource::new(true, b',', b'"')
|
||||||
|
.with_schema(schema.clone())
|
||||||
|
.with_batch_size(8192);
|
||||||
|
|
||||||
|
let stream = file_to_stream(
|
||||||
|
&store,
|
||||||
|
compressed_file_path_str,
|
||||||
|
schema.clone(),
|
||||||
|
csv_source.clone(),
|
||||||
|
None,
|
||||||
|
compression_type,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let batches = stream.try_collect::<Vec<_>>().await.unwrap();
|
||||||
|
let pretty_print = arrow::util::pretty::pretty_format_batches(&batches)
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
let expected = r#"+----+---------+-------+
|
||||||
|
| id | name | value |
|
||||||
|
+----+---------+-------+
|
||||||
|
| 1 | Alice | 10.5 |
|
||||||
|
| 2 | Bob | 20.3 |
|
||||||
|
| 3 | Charlie | 30.7 |
|
||||||
|
| 4 | David | 40.1 |
|
||||||
|
| 5 | Eva | 50.2 |
|
||||||
|
| 6 | Frank | 60.3 |
|
||||||
|
| 7 | Grace | 70.4 |
|
||||||
|
| 8 | Henry | 80.5 |
|
||||||
|
| 9 | Ivy | 90.6 |
|
||||||
|
+----+---------+-------+"#;
|
||||||
|
assert_eq!(expected, pretty_print);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,10 +115,17 @@ pub async fn stream_to_json(
|
|||||||
path: &str,
|
path: &str,
|
||||||
threshold: usize,
|
threshold: usize,
|
||||||
concurrency: usize,
|
concurrency: usize,
|
||||||
|
format: &JsonFormat,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
stream_to_file(stream, store, path, threshold, concurrency, |buffer| {
|
stream_to_file(
|
||||||
json::LineDelimitedWriter::new(buffer)
|
stream,
|
||||||
})
|
store,
|
||||||
|
path,
|
||||||
|
threshold,
|
||||||
|
concurrency,
|
||||||
|
format.compression_type,
|
||||||
|
json::LineDelimitedWriter::new,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +137,21 @@ impl DfRecordBatchEncoder for json::Writer<SharedBuffer, LineDelimited> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use common_recordbatch::adapter::DfRecordBatchStreamAdapter;
|
||||||
|
use common_recordbatch::{RecordBatch, RecordBatches};
|
||||||
use common_test_util::find_workspace_path;
|
use common_test_util::find_workspace_path;
|
||||||
|
use datafusion::datasource::physical_plan::{FileSource, JsonSource};
|
||||||
|
use datatypes::prelude::ConcreteDataType;
|
||||||
|
use datatypes::schema::{ColumnSchema, Schema};
|
||||||
|
use datatypes::vectors::{Float64Vector, StringVector, UInt32Vector, VectorRef};
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::file_format::{FORMAT_COMPRESSION_TYPE, FORMAT_SCHEMA_INFER_MAX_RECORD, FileFormat};
|
use crate::file_format::{
|
||||||
|
FORMAT_COMPRESSION_TYPE, FORMAT_SCHEMA_INFER_MAX_RECORD, FileFormat, file_to_stream,
|
||||||
|
};
|
||||||
use crate::test_util::{format_schema, test_store};
|
use crate::test_util::{format_schema, test_store};
|
||||||
|
|
||||||
fn test_data_root() -> String {
|
fn test_data_root() -> String {
|
||||||
@@ -203,4 +221,165 @@ mod tests {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_compressed_json() {
|
||||||
|
// Create test data
|
||||||
|
let column_schemas = vec![
|
||||||
|
ColumnSchema::new("id", ConcreteDataType::uint32_datatype(), false),
|
||||||
|
ColumnSchema::new("name", ConcreteDataType::string_datatype(), false),
|
||||||
|
ColumnSchema::new("value", ConcreteDataType::float64_datatype(), false),
|
||||||
|
];
|
||||||
|
let schema = Arc::new(Schema::new(column_schemas));
|
||||||
|
|
||||||
|
// Create multiple record batches with different data
|
||||||
|
let batch1_columns: Vec<VectorRef> = vec![
|
||||||
|
Arc::new(UInt32Vector::from_slice(vec![1, 2, 3])),
|
||||||
|
Arc::new(StringVector::from(vec!["Alice", "Bob", "Charlie"])),
|
||||||
|
Arc::new(Float64Vector::from_slice(vec![10.5, 20.3, 30.7])),
|
||||||
|
];
|
||||||
|
let batch1 = RecordBatch::new(schema.clone(), batch1_columns).unwrap();
|
||||||
|
|
||||||
|
let batch2_columns: Vec<VectorRef> = vec![
|
||||||
|
Arc::new(UInt32Vector::from_slice(vec![4, 5, 6])),
|
||||||
|
Arc::new(StringVector::from(vec!["David", "Eva", "Frank"])),
|
||||||
|
Arc::new(Float64Vector::from_slice(vec![40.1, 50.2, 60.3])),
|
||||||
|
];
|
||||||
|
let batch2 = RecordBatch::new(schema.clone(), batch2_columns).unwrap();
|
||||||
|
|
||||||
|
let batch3_columns: Vec<VectorRef> = vec![
|
||||||
|
Arc::new(UInt32Vector::from_slice(vec![7, 8, 9])),
|
||||||
|
Arc::new(StringVector::from(vec!["Grace", "Henry", "Ivy"])),
|
||||||
|
Arc::new(Float64Vector::from_slice(vec![70.4, 80.5, 90.6])),
|
||||||
|
];
|
||||||
|
let batch3 = RecordBatch::new(schema.clone(), batch3_columns).unwrap();
|
||||||
|
|
||||||
|
// Combine all batches into a RecordBatches collection
|
||||||
|
let recordbatches = RecordBatches::try_new(schema, vec![batch1, batch2, batch3]).unwrap();
|
||||||
|
|
||||||
|
// Test with different compression types
|
||||||
|
let compression_types = vec![
|
||||||
|
CompressionType::Gzip,
|
||||||
|
CompressionType::Bzip2,
|
||||||
|
CompressionType::Xz,
|
||||||
|
CompressionType::Zstd,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Create a temporary file path
|
||||||
|
let temp_dir = common_test_util::temp_dir::create_temp_dir("test_compressed_json");
|
||||||
|
for compression_type in compression_types {
|
||||||
|
let format = JsonFormat {
|
||||||
|
compression_type,
|
||||||
|
..JsonFormat::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let compressed_file_name =
|
||||||
|
format!("test_compressed_json.{}", compression_type.file_extension());
|
||||||
|
let compressed_file_path = temp_dir.path().join(&compressed_file_name);
|
||||||
|
let compressed_file_path_str = compressed_file_path.to_str().unwrap();
|
||||||
|
|
||||||
|
// Create a simple file store for testing
|
||||||
|
let store = test_store("/");
|
||||||
|
|
||||||
|
// Export JSON with compression
|
||||||
|
let rows = stream_to_json(
|
||||||
|
Box::pin(DfRecordBatchStreamAdapter::new(recordbatches.as_stream())),
|
||||||
|
store,
|
||||||
|
compressed_file_path_str,
|
||||||
|
1024,
|
||||||
|
1,
|
||||||
|
&format,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(rows, 9);
|
||||||
|
|
||||||
|
// Verify compressed file was created and has content
|
||||||
|
assert!(compressed_file_path.exists());
|
||||||
|
let file_size = std::fs::metadata(&compressed_file_path).unwrap().len();
|
||||||
|
assert!(file_size > 0);
|
||||||
|
|
||||||
|
// Verify the file is actually compressed
|
||||||
|
let file_content = std::fs::read(&compressed_file_path).unwrap();
|
||||||
|
// Compressed files should not start with '{' (JSON character)
|
||||||
|
// They should have compression magic bytes
|
||||||
|
match compression_type {
|
||||||
|
CompressionType::Gzip => {
|
||||||
|
// Gzip magic bytes: 0x1f 0x8b
|
||||||
|
assert_eq!(file_content[0], 0x1f, "Gzip file should start with 0x1f");
|
||||||
|
assert_eq!(
|
||||||
|
file_content[1], 0x8b,
|
||||||
|
"Gzip file should have 0x8b as second byte"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CompressionType::Bzip2 => {
|
||||||
|
// Bzip2 magic bytes: 'BZ'
|
||||||
|
assert_eq!(file_content[0], b'B', "Bzip2 file should start with 'B'");
|
||||||
|
assert_eq!(
|
||||||
|
file_content[1], b'Z',
|
||||||
|
"Bzip2 file should have 'Z' as second byte"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CompressionType::Xz => {
|
||||||
|
// XZ magic bytes: 0xFD '7zXZ'
|
||||||
|
assert_eq!(file_content[0], 0xFD, "XZ file should start with 0xFD");
|
||||||
|
}
|
||||||
|
CompressionType::Zstd => {
|
||||||
|
// Zstd magic bytes: 0x28 0xB5 0x2F 0xFD
|
||||||
|
assert_eq!(file_content[0], 0x28, "Zstd file should start with 0x28");
|
||||||
|
assert_eq!(
|
||||||
|
file_content[1], 0xB5,
|
||||||
|
"Zstd file should have 0xB5 as second byte"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the compressed file can be decompressed and content matches original data
|
||||||
|
let store = test_store("/");
|
||||||
|
let schema = Arc::new(
|
||||||
|
JsonFormat {
|
||||||
|
compression_type,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.infer_schema(&store, compressed_file_path_str)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let json_source = JsonSource::new()
|
||||||
|
.with_schema(schema.clone())
|
||||||
|
.with_batch_size(8192);
|
||||||
|
|
||||||
|
let stream = file_to_stream(
|
||||||
|
&store,
|
||||||
|
compressed_file_path_str,
|
||||||
|
schema.clone(),
|
||||||
|
json_source.clone(),
|
||||||
|
None,
|
||||||
|
compression_type,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let batches = stream.try_collect::<Vec<_>>().await.unwrap();
|
||||||
|
let pretty_print = arrow::util::pretty::pretty_format_batches(&batches)
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
let expected = r#"+----+---------+-------+
|
||||||
|
| id | name | value |
|
||||||
|
+----+---------+-------+
|
||||||
|
| 1 | Alice | 10.5 |
|
||||||
|
| 2 | Bob | 20.3 |
|
||||||
|
| 3 | Charlie | 30.7 |
|
||||||
|
| 4 | David | 40.1 |
|
||||||
|
| 5 | Eva | 50.2 |
|
||||||
|
| 6 | Frank | 60.3 |
|
||||||
|
| 7 | Grace | 70.4 |
|
||||||
|
| 8 | Henry | 80.5 |
|
||||||
|
| 9 | Ivy | 90.6 |
|
||||||
|
+----+---------+-------+"#;
|
||||||
|
assert_eq!(expected, pretty_print);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
pub mod buffered_writer;
|
pub mod buffered_writer;
|
||||||
|
pub mod compressed_writer;
|
||||||
pub mod compression;
|
pub mod compression;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod file_format;
|
pub mod file_format;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ use object_store::ObjectStore;
|
|||||||
use object_store::services::Fs;
|
use object_store::services::Fs;
|
||||||
|
|
||||||
use crate::file_format::csv::{CsvFormat, stream_to_csv};
|
use crate::file_format::csv::{CsvFormat, stream_to_csv};
|
||||||
use crate::file_format::json::stream_to_json;
|
use crate::file_format::json::{JsonFormat, stream_to_json};
|
||||||
use crate::test_util;
|
use crate::test_util;
|
||||||
|
|
||||||
pub const TEST_BATCH_SIZE: usize = 100;
|
pub const TEST_BATCH_SIZE: usize = 100;
|
||||||
@@ -122,13 +122,16 @@ pub async fn setup_stream_to_json_test(origin_path: &str, threshold: impl Fn(usi
|
|||||||
|
|
||||||
let output_path = format!("{}/{}", dir.path().display(), "output");
|
let output_path = format!("{}/{}", dir.path().display(), "output");
|
||||||
|
|
||||||
|
let json_format = JsonFormat::default();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
stream_to_json(
|
stream_to_json(
|
||||||
Box::pin(stream),
|
Box::pin(stream),
|
||||||
tmp_store.clone(),
|
tmp_store.clone(),
|
||||||
&output_path,
|
&output_path,
|
||||||
threshold(size),
|
threshold(size),
|
||||||
8
|
8,
|
||||||
|
&json_format,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ pub trait Event: Send + Sync + Debug {
|
|||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the extra row to the event with the default row.
|
/// Add the extra rows to the event with the default row.
|
||||||
fn extra_row(&self) -> Result<Row> {
|
fn extra_rows(&self) -> Result<Vec<Row>> {
|
||||||
Ok(Row { values: vec![] })
|
Ok(vec![Row { values: vec![] }])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the event as any type.
|
/// Returns the event as any type.
|
||||||
@@ -159,15 +159,17 @@ pub fn build_row_inserts_request(events: &[&Box<dyn Event>]) -> Result<RowInsert
|
|||||||
|
|
||||||
let mut rows: Vec<Row> = Vec::with_capacity(events.len());
|
let mut rows: Vec<Row> = Vec::with_capacity(events.len());
|
||||||
for event in events {
|
for event in events {
|
||||||
let extra_row = event.extra_row()?;
|
let extra_rows = event.extra_rows()?;
|
||||||
let mut values = Vec::with_capacity(3 + extra_row.values.len());
|
for extra_row in extra_rows {
|
||||||
values.extend([
|
let mut values = Vec::with_capacity(3 + extra_row.values.len());
|
||||||
ValueData::StringValue(event.event_type().to_string()).into(),
|
values.extend([
|
||||||
ValueData::BinaryValue(event.json_payload()?.into_bytes()).into(),
|
ValueData::StringValue(event.event_type().to_string()).into(),
|
||||||
ValueData::TimestampNanosecondValue(event.timestamp().value()).into(),
|
ValueData::BinaryValue(event.json_payload()?.into_bytes()).into(),
|
||||||
]);
|
ValueData::TimestampNanosecondValue(event.timestamp().value()).into(),
|
||||||
values.extend(extra_row.values);
|
]);
|
||||||
rows.push(Row { values });
|
values.extend(extra_row.values);
|
||||||
|
rows.push(Row { values });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RowInsertRequests {
|
Ok(RowInsertRequests {
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ impl Event for SlowQueryEvent {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_row(&self) -> Result<Row> {
|
fn extra_rows(&self) -> Result<Vec<Row>> {
|
||||||
Ok(Row {
|
Ok(vec![Row {
|
||||||
values: vec![
|
values: vec![
|
||||||
ValueData::U64Value(self.cost).into(),
|
ValueData::U64Value(self.cost).into(),
|
||||||
ValueData::U64Value(self.threshold).into(),
|
ValueData::U64Value(self.threshold).into(),
|
||||||
@@ -119,7 +119,7 @@ impl Event for SlowQueryEvent {
|
|||||||
ValueData::TimestampMillisecondValue(self.promql_start.unwrap_or(0)).into(),
|
ValueData::TimestampMillisecondValue(self.promql_start.unwrap_or(0)).into(),
|
||||||
ValueData::TimestampMillisecondValue(self.promql_end.unwrap_or(0)).into(),
|
ValueData::TimestampMillisecondValue(self.promql_end.unwrap_or(0)).into(),
|
||||||
],
|
],
|
||||||
})
|
}])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_payload(&self) -> Result<String> {
|
fn json_payload(&self) -> Result<String> {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ h3o = { version = "0.6", optional = true }
|
|||||||
hyperloglogplus = "0.4"
|
hyperloglogplus = "0.4"
|
||||||
jsonb.workspace = true
|
jsonb.workspace = true
|
||||||
memchr = "2.7"
|
memchr = "2.7"
|
||||||
|
mito-codec.workspace = true
|
||||||
nalgebra.workspace = true
|
nalgebra.workspace = true
|
||||||
num = "0.4"
|
num = "0.4"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
mod build_index_table;
|
||||||
mod flush_compact_region;
|
mod flush_compact_region;
|
||||||
mod flush_compact_table;
|
mod flush_compact_table;
|
||||||
mod migrate_region;
|
mod migrate_region;
|
||||||
@@ -26,6 +27,7 @@ use reconcile_catalog::ReconcileCatalogFunction;
|
|||||||
use reconcile_database::ReconcileDatabaseFunction;
|
use reconcile_database::ReconcileDatabaseFunction;
|
||||||
use reconcile_table::ReconcileTableFunction;
|
use reconcile_table::ReconcileTableFunction;
|
||||||
|
|
||||||
|
use crate::admin::build_index_table::BuildIndexFunction;
|
||||||
use crate::flush_flow::FlushFlowFunction;
|
use crate::flush_flow::FlushFlowFunction;
|
||||||
use crate::function_registry::FunctionRegistry;
|
use crate::function_registry::FunctionRegistry;
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ impl AdminFunction {
|
|||||||
registry.register(CompactRegionFunction::factory());
|
registry.register(CompactRegionFunction::factory());
|
||||||
registry.register(FlushTableFunction::factory());
|
registry.register(FlushTableFunction::factory());
|
||||||
registry.register(CompactTableFunction::factory());
|
registry.register(CompactTableFunction::factory());
|
||||||
|
registry.register(BuildIndexFunction::factory());
|
||||||
registry.register(FlushFlowFunction::factory());
|
registry.register(FlushFlowFunction::factory());
|
||||||
registry.register(ReconcileCatalogFunction::factory());
|
registry.register(ReconcileCatalogFunction::factory());
|
||||||
registry.register(ReconcileDatabaseFunction::factory());
|
registry.register(ReconcileDatabaseFunction::factory());
|
||||||
|
|||||||
80
src/common/function/src/admin/build_index_table.rs
Normal file
80
src/common/function/src/admin/build_index_table.rs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2023 Greptime Team
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use arrow::datatypes::DataType as ArrowDataType;
|
||||||
|
use common_error::ext::BoxedError;
|
||||||
|
use common_macro::admin_fn;
|
||||||
|
use common_query::error::{
|
||||||
|
InvalidFuncArgsSnafu, MissingTableMutationHandlerSnafu, Result, TableMutationSnafu,
|
||||||
|
UnsupportedInputDataTypeSnafu,
|
||||||
|
};
|
||||||
|
use datafusion_expr::{Signature, Volatility};
|
||||||
|
use datatypes::prelude::*;
|
||||||
|
use session::context::QueryContextRef;
|
||||||
|
use session::table_name::table_name_to_full_name;
|
||||||
|
use snafu::{ResultExt, ensure};
|
||||||
|
use table::requests::BuildIndexTableRequest;
|
||||||
|
|
||||||
|
use crate::handlers::TableMutationHandlerRef;
|
||||||
|
|
||||||
|
#[admin_fn(
|
||||||
|
name = BuildIndexFunction,
|
||||||
|
display_name = build_index,
|
||||||
|
sig_fn = build_index_signature,
|
||||||
|
ret = uint64
|
||||||
|
)]
|
||||||
|
pub(crate) async fn build_index(
|
||||||
|
table_mutation_handler: &TableMutationHandlerRef,
|
||||||
|
query_ctx: &QueryContextRef,
|
||||||
|
params: &[ValueRef<'_>],
|
||||||
|
) -> Result<Value> {
|
||||||
|
ensure!(
|
||||||
|
params.len() == 1,
|
||||||
|
InvalidFuncArgsSnafu {
|
||||||
|
err_msg: format!(
|
||||||
|
"The length of the args is not correct, expect 1, have: {}",
|
||||||
|
params.len()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let ValueRef::String(table_name) = params[0] else {
|
||||||
|
return UnsupportedInputDataTypeSnafu {
|
||||||
|
function: "build_index",
|
||||||
|
datatypes: params.iter().map(|v| v.data_type()).collect::<Vec<_>>(),
|
||||||
|
}
|
||||||
|
.fail();
|
||||||
|
};
|
||||||
|
|
||||||
|
let (catalog_name, schema_name, table_name) = table_name_to_full_name(table_name, query_ctx)
|
||||||
|
.map_err(BoxedError::new)
|
||||||
|
.context(TableMutationSnafu)?;
|
||||||
|
|
||||||
|
let affected_rows = table_mutation_handler
|
||||||
|
.build_index(
|
||||||
|
BuildIndexTableRequest {
|
||||||
|
catalog_name,
|
||||||
|
schema_name,
|
||||||
|
table_name,
|
||||||
|
},
|
||||||
|
query_ctx.clone(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Value::from(affected_rows as u64))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_index_signature() -> Signature {
|
||||||
|
Signature::uniform(1, vec![ArrowDataType::Utf8], Volatility::Immutable)
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ use crate::scalars::json::JsonFunction;
|
|||||||
use crate::scalars::matches::MatchesFunction;
|
use crate::scalars::matches::MatchesFunction;
|
||||||
use crate::scalars::matches_term::MatchesTermFunction;
|
use crate::scalars::matches_term::MatchesTermFunction;
|
||||||
use crate::scalars::math::MathFunction;
|
use crate::scalars::math::MathFunction;
|
||||||
|
use crate::scalars::primary_key::DecodePrimaryKeyFunction;
|
||||||
use crate::scalars::string::register_string_functions;
|
use crate::scalars::string::register_string_functions;
|
||||||
use crate::scalars::timestamp::TimestampFunction;
|
use crate::scalars::timestamp::TimestampFunction;
|
||||||
use crate::scalars::uddsketch_calc::UddSketchCalcFunction;
|
use crate::scalars::uddsketch_calc::UddSketchCalcFunction;
|
||||||
@@ -143,6 +144,7 @@ pub static FUNCTION_REGISTRY: LazyLock<Arc<FunctionRegistry>> = LazyLock::new(||
|
|||||||
ExpressionFunction::register(&function_registry);
|
ExpressionFunction::register(&function_registry);
|
||||||
UddSketchCalcFunction::register(&function_registry);
|
UddSketchCalcFunction::register(&function_registry);
|
||||||
HllCalcFunction::register(&function_registry);
|
HllCalcFunction::register(&function_registry);
|
||||||
|
DecodePrimaryKeyFunction::register(&function_registry);
|
||||||
|
|
||||||
// Full text search function
|
// Full text search function
|
||||||
MatchesFunction::register(&function_registry);
|
MatchesFunction::register(&function_registry);
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ use common_query::Output;
|
|||||||
use common_query::error::Result;
|
use common_query::error::Result;
|
||||||
use session::context::QueryContextRef;
|
use session::context::QueryContextRef;
|
||||||
use store_api::storage::RegionId;
|
use store_api::storage::RegionId;
|
||||||
use table::requests::{CompactTableRequest, DeleteRequest, FlushTableRequest, InsertRequest};
|
use table::requests::{
|
||||||
|
BuildIndexTableRequest, CompactTableRequest, DeleteRequest, FlushTableRequest, InsertRequest,
|
||||||
|
};
|
||||||
|
|
||||||
/// A trait for handling table mutations in `QueryEngine`.
|
/// A trait for handling table mutations in `QueryEngine`.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -47,6 +49,13 @@ pub trait TableMutationHandler: Send + Sync {
|
|||||||
ctx: QueryContextRef,
|
ctx: QueryContextRef,
|
||||||
) -> Result<AffectedRows>;
|
) -> Result<AffectedRows>;
|
||||||
|
|
||||||
|
/// Trigger an index build task for the table.
|
||||||
|
async fn build_index(
|
||||||
|
&self,
|
||||||
|
request: BuildIndexTableRequest,
|
||||||
|
ctx: QueryContextRef,
|
||||||
|
) -> Result<AffectedRows>;
|
||||||
|
|
||||||
/// Trigger a flush task for a table region.
|
/// Trigger a flush task for a table region.
|
||||||
async fn flush_region(&self, region_id: RegionId, ctx: QueryContextRef)
|
async fn flush_region(&self, region_id: RegionId, ctx: QueryContextRef)
|
||||||
-> Result<AffectedRows>;
|
-> Result<AffectedRows>;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ pub mod json;
|
|||||||
pub mod matches;
|
pub mod matches;
|
||||||
pub mod matches_term;
|
pub mod matches_term;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
|
pub mod primary_key;
|
||||||
pub(crate) mod string;
|
pub(crate) mod string;
|
||||||
pub mod vector;
|
pub mod vector;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
mod binary;
|
mod binary;
|
||||||
mod ctx;
|
mod ctx;
|
||||||
|
mod if_func;
|
||||||
mod is_null;
|
mod is_null;
|
||||||
mod unary;
|
mod unary;
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ pub use ctx::EvalContext;
|
|||||||
pub use unary::scalar_unary_op;
|
pub use unary::scalar_unary_op;
|
||||||
|
|
||||||
use crate::function_registry::FunctionRegistry;
|
use crate::function_registry::FunctionRegistry;
|
||||||
|
use crate::scalars::expression::if_func::IfFunction;
|
||||||
use crate::scalars::expression::is_null::IsNullFunction;
|
use crate::scalars::expression::is_null::IsNullFunction;
|
||||||
|
|
||||||
pub(crate) struct ExpressionFunction;
|
pub(crate) struct ExpressionFunction;
|
||||||
@@ -29,5 +31,6 @@ pub(crate) struct ExpressionFunction;
|
|||||||
impl ExpressionFunction {
|
impl ExpressionFunction {
|
||||||
pub fn register(registry: &FunctionRegistry) {
|
pub fn register(registry: &FunctionRegistry) {
|
||||||
registry.register_scalar(IsNullFunction::default());
|
registry.register_scalar(IsNullFunction::default());
|
||||||
|
registry.register_scalar(IfFunction::default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
404
src/common/function/src/scalars/expression/if_func.rs
Normal file
404
src/common/function/src/scalars/expression/if_func.rs
Normal file
@@ -0,0 +1,404 @@
|
|||||||
|
// Copyright 2023 Greptime Team
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use arrow::array::ArrowNativeTypeOp;
|
||||||
|
use arrow::datatypes::ArrowPrimitiveType;
|
||||||
|
use datafusion::arrow::array::{Array, ArrayRef, AsArray, BooleanArray, PrimitiveArray};
|
||||||
|
use datafusion::arrow::compute::kernels::zip::zip;
|
||||||
|
use datafusion::arrow::datatypes::DataType;
|
||||||
|
use datafusion_common::DataFusionError;
|
||||||
|
use datafusion_expr::type_coercion::binary::comparison_coercion;
|
||||||
|
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
|
||||||
|
|
||||||
|
use crate::function::Function;
|
||||||
|
|
||||||
|
const NAME: &str = "if";
|
||||||
|
|
||||||
|
/// MySQL-compatible IF function: IF(condition, true_value, false_value)
|
||||||
|
///
|
||||||
|
/// Returns true_value if condition is TRUE (not NULL and not 0),
|
||||||
|
/// otherwise returns false_value.
|
||||||
|
///
|
||||||
|
/// MySQL truthy rules:
|
||||||
|
/// - NULL -> false
|
||||||
|
/// - 0 (numeric zero) -> false
|
||||||
|
/// - Any non-zero numeric -> true
|
||||||
|
/// - Boolean true/false -> use directly
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct IfFunction {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for IfFunction {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: Signature::any(3, Volatility::Immutable),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for IfFunction {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}", NAME.to_ascii_uppercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Function for IfFunction {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, input_types: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
// Return the common type of true_value and false_value (args[1] and args[2])
|
||||||
|
if input_types.len() < 3 {
|
||||||
|
return Err(DataFusionError::Plan(format!(
|
||||||
|
"{} requires 3 arguments, got {}",
|
||||||
|
NAME,
|
||||||
|
input_types.len()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
let true_type = &input_types[1];
|
||||||
|
let false_type = &input_types[2];
|
||||||
|
|
||||||
|
// Use comparison_coercion to find common type
|
||||||
|
comparison_coercion(true_type, false_type).ok_or_else(|| {
|
||||||
|
DataFusionError::Plan(format!(
|
||||||
|
"Cannot find common type for IF function between {:?} and {:?}",
|
||||||
|
true_type, false_type
|
||||||
|
))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
if args.args.len() != 3 {
|
||||||
|
return Err(DataFusionError::Plan(format!(
|
||||||
|
"{} requires exactly 3 arguments, got {}",
|
||||||
|
NAME,
|
||||||
|
args.args.len()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let condition = &args.args[0];
|
||||||
|
let true_value = &args.args[1];
|
||||||
|
let false_value = &args.args[2];
|
||||||
|
|
||||||
|
// Convert condition to boolean array using MySQL truthy rules
|
||||||
|
let bool_array = to_boolean_array(condition, args.number_rows)?;
|
||||||
|
|
||||||
|
// Convert true and false values to arrays
|
||||||
|
let true_array = true_value.to_array(args.number_rows)?;
|
||||||
|
let false_array = false_value.to_array(args.number_rows)?;
|
||||||
|
|
||||||
|
// Use zip to select values based on condition
|
||||||
|
// zip expects &dyn Datum, and ArrayRef (Arc<dyn Array>) implements Datum
|
||||||
|
let result = zip(&bool_array, &true_array, &false_array)?;
|
||||||
|
Ok(ColumnarValue::Array(result))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a ColumnarValue to a BooleanArray using MySQL truthy rules:
|
||||||
|
/// - NULL -> false
|
||||||
|
/// - 0 (any numeric zero) -> false
|
||||||
|
/// - Non-zero numeric -> true
|
||||||
|
/// - Boolean -> use directly
|
||||||
|
fn to_boolean_array(
|
||||||
|
value: &ColumnarValue,
|
||||||
|
num_rows: usize,
|
||||||
|
) -> datafusion_common::Result<BooleanArray> {
|
||||||
|
let array = value.to_array(num_rows)?;
|
||||||
|
array_to_bool(array)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert an integer PrimitiveArray to BooleanArray using MySQL truthy rules:
|
||||||
|
/// NULL -> false, 0 -> false, non-zero -> true
|
||||||
|
fn int_array_to_bool<T>(array: &PrimitiveArray<T>) -> BooleanArray
|
||||||
|
where
|
||||||
|
T: ArrowPrimitiveType,
|
||||||
|
T::Native: ArrowNativeTypeOp,
|
||||||
|
{
|
||||||
|
BooleanArray::from_iter(
|
||||||
|
array
|
||||||
|
.iter()
|
||||||
|
.map(|opt| Some(opt.is_some_and(|v| !v.is_zero()))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a float PrimitiveArray to BooleanArray using MySQL truthy rules:
|
||||||
|
/// NULL -> false, 0 (including -0.0) -> false, NaN -> true, other non-zero -> true
|
||||||
|
fn float_array_to_bool<T>(array: &PrimitiveArray<T>) -> BooleanArray
|
||||||
|
where
|
||||||
|
T: ArrowPrimitiveType,
|
||||||
|
T::Native: ArrowNativeTypeOp + num_traits::Float,
|
||||||
|
{
|
||||||
|
use num_traits::Float;
|
||||||
|
BooleanArray::from_iter(
|
||||||
|
array
|
||||||
|
.iter()
|
||||||
|
.map(|opt| Some(opt.is_some_and(|v| v.is_nan() || !v.is_zero()))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert an Array to BooleanArray using MySQL truthy rules
|
||||||
|
fn array_to_bool(array: ArrayRef) -> datafusion_common::Result<BooleanArray> {
|
||||||
|
use arrow::datatypes::*;
|
||||||
|
|
||||||
|
match array.data_type() {
|
||||||
|
DataType::Boolean => {
|
||||||
|
let bool_array = array.as_boolean();
|
||||||
|
Ok(BooleanArray::from_iter(
|
||||||
|
bool_array.iter().map(|opt| Some(opt.unwrap_or(false))),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
DataType::Int8 => Ok(int_array_to_bool(array.as_primitive::<Int8Type>())),
|
||||||
|
DataType::Int16 => Ok(int_array_to_bool(array.as_primitive::<Int16Type>())),
|
||||||
|
DataType::Int32 => Ok(int_array_to_bool(array.as_primitive::<Int32Type>())),
|
||||||
|
DataType::Int64 => Ok(int_array_to_bool(array.as_primitive::<Int64Type>())),
|
||||||
|
DataType::UInt8 => Ok(int_array_to_bool(array.as_primitive::<UInt8Type>())),
|
||||||
|
DataType::UInt16 => Ok(int_array_to_bool(array.as_primitive::<UInt16Type>())),
|
||||||
|
DataType::UInt32 => Ok(int_array_to_bool(array.as_primitive::<UInt32Type>())),
|
||||||
|
DataType::UInt64 => Ok(int_array_to_bool(array.as_primitive::<UInt64Type>())),
|
||||||
|
// Float16 needs special handling since half::f16 doesn't implement num_traits::Float
|
||||||
|
DataType::Float16 => {
|
||||||
|
let typed_array = array.as_primitive::<Float16Type>();
|
||||||
|
Ok(BooleanArray::from_iter(typed_array.iter().map(|opt| {
|
||||||
|
Some(opt.is_some_and(|v| {
|
||||||
|
let f = v.to_f32();
|
||||||
|
f.is_nan() || !f.is_zero()
|
||||||
|
}))
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
DataType::Float32 => Ok(float_array_to_bool(array.as_primitive::<Float32Type>())),
|
||||||
|
DataType::Float64 => Ok(float_array_to_bool(array.as_primitive::<Float64Type>())),
|
||||||
|
// Null type is always false.
|
||||||
|
// Note: NullArray::is_null() returns false (physical null), so we must handle it explicitly.
|
||||||
|
// See: https://github.com/apache/arrow-rs/issues/4840
|
||||||
|
DataType::Null => Ok(BooleanArray::from(vec![false; array.len()])),
|
||||||
|
// For other types, treat non-null as true
|
||||||
|
_ => {
|
||||||
|
let len = array.len();
|
||||||
|
Ok(BooleanArray::from_iter(
|
||||||
|
(0..len).map(|i| Some(!array.is_null(i))),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arrow_schema::Field;
|
||||||
|
use datafusion_common::ScalarValue;
|
||||||
|
use datafusion_common::arrow::array::{AsArray, Int32Array, StringArray};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_function_basic() {
|
||||||
|
let if_func = IfFunction::default();
|
||||||
|
assert_eq!("if", if_func.name());
|
||||||
|
|
||||||
|
// Test IF(true, 'yes', 'no') -> 'yes'
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Boolean(Some(true))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("yes".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("no".to_string()))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 1,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "yes");
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_function_false() {
|
||||||
|
let if_func = IfFunction::default();
|
||||||
|
|
||||||
|
// Test IF(false, 'yes', 'no') -> 'no'
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Boolean(Some(false))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("yes".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("no".to_string()))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 1,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "no");
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_function_null_is_false() {
|
||||||
|
let if_func = IfFunction::default();
|
||||||
|
|
||||||
|
// Test IF(NULL, 'yes', 'no') -> 'no' (NULL is treated as false)
|
||||||
|
// Using Boolean(None) - typed null
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Boolean(None)),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("yes".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("no".to_string()))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 1,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "no");
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test IF(NULL, 'yes', 'no') -> 'no' using ScalarValue::Null (untyped null from SQL NULL literal)
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Null),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("yes".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("no".to_string()))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 1,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "no");
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_function_numeric_truthy() {
|
||||||
|
let if_func = IfFunction::default();
|
||||||
|
|
||||||
|
// Test IF(1, 'yes', 'no') -> 'yes' (non-zero is true)
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Int32(Some(1))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("yes".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("no".to_string()))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 1,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "yes");
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test IF(0, 'yes', 'no') -> 'no' (zero is false)
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Int32(Some(0))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("yes".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("no".to_string()))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 1,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "no");
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_function_with_arrays() {
|
||||||
|
let if_func = IfFunction::default();
|
||||||
|
|
||||||
|
// Test with array condition
|
||||||
|
let condition = Int32Array::from(vec![Some(1), Some(0), None, Some(5)]);
|
||||||
|
let true_val = StringArray::from(vec!["yes", "yes", "yes", "yes"]);
|
||||||
|
let false_val = StringArray::from(vec!["no", "no", "no", "no"]);
|
||||||
|
|
||||||
|
let result = if_func
|
||||||
|
.invoke_with_args(ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Array(Arc::new(condition)),
|
||||||
|
ColumnarValue::Array(Arc::new(true_val)),
|
||||||
|
ColumnarValue::Array(Arc::new(false_val)),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows: 4,
|
||||||
|
return_field: Arc::new(Field::new("", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
let str_arr = arr.as_string::<i32>();
|
||||||
|
assert_eq!(str_arr.value(0), "yes"); // 1 is true
|
||||||
|
assert_eq!(str_arr.value(1), "no"); // 0 is false
|
||||||
|
assert_eq!(str_arr.value(2), "no"); // NULL is false
|
||||||
|
assert_eq!(str_arr.value(3), "yes"); // 5 is true
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ mod json_path_match;
|
|||||||
mod json_to_string;
|
mod json_to_string;
|
||||||
mod parse_json;
|
mod parse_json;
|
||||||
|
|
||||||
use json_get::{JsonGetBool, JsonGetFloat, JsonGetInt, JsonGetString};
|
use json_get::{JsonGetBool, JsonGetFloat, JsonGetInt, JsonGetObject, JsonGetString};
|
||||||
use json_is::{
|
use json_is::{
|
||||||
JsonIsArray, JsonIsBool, JsonIsFloat, JsonIsInt, JsonIsNull, JsonIsObject, JsonIsString,
|
JsonIsArray, JsonIsBool, JsonIsFloat, JsonIsInt, JsonIsNull, JsonIsObject, JsonIsString,
|
||||||
};
|
};
|
||||||
@@ -39,6 +39,7 @@ impl JsonFunction {
|
|||||||
registry.register_scalar(JsonGetFloat::default());
|
registry.register_scalar(JsonGetFloat::default());
|
||||||
registry.register_scalar(JsonGetString::default());
|
registry.register_scalar(JsonGetString::default());
|
||||||
registry.register_scalar(JsonGetBool::default());
|
registry.register_scalar(JsonGetBool::default());
|
||||||
|
registry.register_scalar(JsonGetObject::default());
|
||||||
|
|
||||||
registry.register_scalar(JsonIsNull::default());
|
registry.register_scalar(JsonIsNull::default());
|
||||||
registry.register_scalar(JsonIsInt::default());
|
registry.register_scalar(JsonIsInt::default());
|
||||||
|
|||||||
@@ -16,10 +16,13 @@ use std::fmt::{self, Display};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use arrow::compute;
|
use arrow::compute;
|
||||||
|
use datafusion_common::DataFusionError;
|
||||||
use datafusion_common::arrow::array::{
|
use datafusion_common::arrow::array::{
|
||||||
Array, AsArray, BooleanBuilder, Float64Builder, Int64Builder, StringViewBuilder,
|
Array, AsArray, BinaryViewBuilder, BooleanBuilder, Float64Builder, Int64Builder,
|
||||||
|
StringViewBuilder,
|
||||||
};
|
};
|
||||||
use datafusion_common::arrow::datatypes::DataType;
|
use datafusion_common::arrow::datatypes::DataType;
|
||||||
|
use datafusion_expr::type_coercion::aggregates::STRINGS;
|
||||||
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature};
|
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature};
|
||||||
|
|
||||||
use crate::function::{Function, extract_args};
|
use crate::function::{Function, extract_args};
|
||||||
@@ -212,13 +215,92 @@ impl Display for JsonGetString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the object from JSON value by path.
|
||||||
|
pub(super) struct JsonGetObject {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JsonGetObject {
|
||||||
|
const NAME: &'static str = "json_get_object";
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for JsonGetObject {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: helper::one_of_sigs2(
|
||||||
|
vec![
|
||||||
|
DataType::Binary,
|
||||||
|
DataType::LargeBinary,
|
||||||
|
DataType::BinaryView,
|
||||||
|
],
|
||||||
|
STRINGS.to_vec(),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Function for JsonGetObject {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
Self::NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
Ok(DataType::BinaryView)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
let [arg0, arg1] = extract_args(self.name(), &args)?;
|
||||||
|
let arg0 = compute::cast(&arg0, &DataType::BinaryView)?;
|
||||||
|
let jsons = arg0.as_binary_view();
|
||||||
|
let arg1 = compute::cast(&arg1, &DataType::Utf8View)?;
|
||||||
|
let paths = arg1.as_string_view();
|
||||||
|
|
||||||
|
let len = jsons.len();
|
||||||
|
let mut builder = BinaryViewBuilder::with_capacity(len);
|
||||||
|
|
||||||
|
for i in 0..len {
|
||||||
|
let json = jsons.is_valid(i).then(|| jsons.value(i));
|
||||||
|
let path = paths.is_valid(i).then(|| paths.value(i));
|
||||||
|
let result = if let (Some(json), Some(path)) = (json, path) {
|
||||||
|
let result = jsonb::jsonpath::parse_json_path(path.as_bytes()).and_then(|path| {
|
||||||
|
let mut data = Vec::new();
|
||||||
|
let mut offset = Vec::new();
|
||||||
|
jsonb::get_by_path(json, path, &mut data, &mut offset)
|
||||||
|
.map(|()| jsonb::is_object(&data).then_some(data))
|
||||||
|
});
|
||||||
|
result.map_err(|e| DataFusionError::Execution(e.to_string()))?
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
builder.append_option(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ColumnarValue::Array(Arc::new(builder.finish())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for JsonGetObject {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}", Self::NAME.to_ascii_uppercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use arrow_schema::Field;
|
use arrow_schema::Field;
|
||||||
use datafusion_common::arrow::array::{BinaryArray, StringArray};
|
use datafusion_common::ScalarValue;
|
||||||
|
use datafusion_common::arrow::array::{BinaryArray, BinaryViewArray, StringArray};
|
||||||
use datafusion_common::arrow::datatypes::{Float64Type, Int64Type};
|
use datafusion_common::arrow::datatypes::{Float64Type, Int64Type};
|
||||||
|
use datatypes::types::parse_string_to_jsonb;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@@ -425,4 +507,49 @@ mod tests {
|
|||||||
assert_eq!(*gt, result);
|
assert_eq!(*gt, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_json_get_object() -> datafusion_common::Result<()> {
|
||||||
|
let udf = JsonGetObject::default();
|
||||||
|
assert_eq!("json_get_object", udf.name());
|
||||||
|
assert_eq!(
|
||||||
|
DataType::BinaryView,
|
||||||
|
udf.return_type(&[DataType::BinaryView, DataType::Utf8View])?
|
||||||
|
);
|
||||||
|
|
||||||
|
let json_value = parse_string_to_jsonb(r#"{"a": {"b": {"c": {"d": 1}}}}"#).unwrap();
|
||||||
|
let paths = vec!["$", "$.a", "$.a.b", "$.a.b.c", "$.a.b.c.d", "$.e", "$.a.e"];
|
||||||
|
let number_rows = paths.len();
|
||||||
|
|
||||||
|
let args = ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Binary(Some(json_value))),
|
||||||
|
ColumnarValue::Array(Arc::new(StringArray::from_iter_values(paths))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows,
|
||||||
|
return_field: Arc::new(Field::new("x", DataType::Binary, false)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
};
|
||||||
|
let result = udf
|
||||||
|
.invoke_with_args(args)
|
||||||
|
.and_then(|x| x.to_array(number_rows))?;
|
||||||
|
let result = result.as_binary_view();
|
||||||
|
|
||||||
|
let expected = &BinaryViewArray::from_iter(
|
||||||
|
vec![
|
||||||
|
Some(r#"{"a": {"b": {"c": {"d": 1}}}}"#),
|
||||||
|
Some(r#"{"b": {"c": {"d": 1}}}"#),
|
||||||
|
Some(r#"{"c": {"d": 1}}"#),
|
||||||
|
Some(r#"{"d": 1}"#),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.and_then(|s| parse_string_to_jsonb(s).ok())),
|
||||||
|
);
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,15 @@ impl Default for JsonToStringFunction {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
// TODO(LFC): Use a more clear type here instead of "Binary" for Json input, once we have a "Json" type.
|
// TODO(LFC): Use a more clear type here instead of "Binary" for Json input, once we have a "Json" type.
|
||||||
signature: Signature::exact(vec![DataType::Binary], Volatility::Immutable),
|
signature: Signature::uniform(
|
||||||
|
1,
|
||||||
|
vec![
|
||||||
|
DataType::Binary,
|
||||||
|
DataType::LargeBinary,
|
||||||
|
DataType::BinaryView,
|
||||||
|
],
|
||||||
|
Volatility::Immutable,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +65,8 @@ impl Function for JsonToStringFunction {
|
|||||||
args: ScalarFunctionArgs,
|
args: ScalarFunctionArgs,
|
||||||
) -> datafusion_common::Result<ColumnarValue> {
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
let [arg0] = extract_args(self.name(), &args)?;
|
let [arg0] = extract_args(self.name(), &args)?;
|
||||||
let jsons = arg0.as_binary::<i32>();
|
let arg0 = arrow::compute::cast(&arg0, &DataType::BinaryView)?;
|
||||||
|
let jsons = arg0.as_binary_view();
|
||||||
|
|
||||||
let size = jsons.len();
|
let size = jsons.len();
|
||||||
let mut builder = StringViewBuilder::with_capacity(size);
|
let mut builder = StringViewBuilder::with_capacity(size);
|
||||||
|
|||||||
521
src/common/function/src/scalars/primary_key.rs
Normal file
521
src/common/function/src/scalars/primary_key.rs
Normal file
@@ -0,0 +1,521 @@
|
|||||||
|
// Copyright 2023 Greptime Team
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::{self, Display};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use datafusion_common::arrow::array::{
|
||||||
|
Array, ArrayRef, BinaryArray, BinaryViewArray, DictionaryArray, ListBuilder, StringBuilder,
|
||||||
|
};
|
||||||
|
use datafusion_common::arrow::datatypes::{DataType, Field};
|
||||||
|
use datafusion_common::{DataFusionError, ScalarValue};
|
||||||
|
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
|
||||||
|
use datatypes::arrow::datatypes::UInt32Type;
|
||||||
|
use datatypes::value::Value;
|
||||||
|
use mito_codec::row_converter::{
|
||||||
|
CompositeValues, PrimaryKeyCodec, SortField, build_primary_key_codec_with_fields,
|
||||||
|
};
|
||||||
|
use store_api::codec::PrimaryKeyEncoding;
|
||||||
|
use store_api::metadata::RegionMetadata;
|
||||||
|
use store_api::storage::ColumnId;
|
||||||
|
use store_api::storage::consts::{PRIMARY_KEY_COLUMN_NAME, ReservedColumnId};
|
||||||
|
|
||||||
|
use crate::function::{Function, extract_args};
|
||||||
|
use crate::function_registry::FunctionRegistry;
|
||||||
|
|
||||||
|
type NameValuePair = (String, Option<String>);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub(crate) struct DecodePrimaryKeyFunction {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
const NAME: &str = "decode_primary_key";
|
||||||
|
const NULL_VALUE_LITERAL: &str = "null";
|
||||||
|
|
||||||
|
impl Default for DecodePrimaryKeyFunction {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: Signature::any(3, Volatility::Immutable),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DecodePrimaryKeyFunction {
|
||||||
|
pub fn register(registry: &FunctionRegistry) {
|
||||||
|
registry.register_scalar(Self::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_data_type() -> DataType {
|
||||||
|
DataType::List(Arc::new(Field::new("item", DataType::Utf8, true)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Function for DecodePrimaryKeyFunction {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
Ok(Self::return_data_type())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
let [encoded, _, _] = extract_args(self.name(), &args)?;
|
||||||
|
let number_rows = args.number_rows;
|
||||||
|
|
||||||
|
let encoding = parse_encoding(&args.args[1])?;
|
||||||
|
let metadata = parse_region_metadata(&args.args[2])?;
|
||||||
|
let codec = build_codec(&metadata, encoding);
|
||||||
|
let name_lookup: HashMap<_, _> = metadata
|
||||||
|
.column_metadatas
|
||||||
|
.iter()
|
||||||
|
.map(|c| (c.column_id, c.column_schema.name.clone()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let decoded_rows = decode_primary_keys(encoded, number_rows, codec.as_ref(), &name_lookup)?;
|
||||||
|
let array = build_list_array(&decoded_rows)?;
|
||||||
|
|
||||||
|
Ok(ColumnarValue::Array(array))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for DecodePrimaryKeyFunction {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "DECODE_PRIMARY_KEY")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_encoding(arg: &ColumnarValue) -> datafusion_common::Result<PrimaryKeyEncoding> {
|
||||||
|
let encoding = match arg {
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some(v)))
|
||||||
|
| ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(v))) => v.as_str(),
|
||||||
|
ColumnarValue::Scalar(value) => {
|
||||||
|
return Err(DataFusionError::Execution(format!(
|
||||||
|
"encoding must be a string literal, got {value:?}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
ColumnarValue::Array(_) => {
|
||||||
|
return Err(DataFusionError::Execution(
|
||||||
|
"encoding must be a scalar string".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match encoding.to_ascii_lowercase().as_str() {
|
||||||
|
"dense" => Ok(PrimaryKeyEncoding::Dense),
|
||||||
|
"sparse" => Ok(PrimaryKeyEncoding::Sparse),
|
||||||
|
_ => Err(DataFusionError::Execution(format!(
|
||||||
|
"unsupported primary key encoding: {encoding}"
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_codec(
|
||||||
|
metadata: &RegionMetadata,
|
||||||
|
encoding: PrimaryKeyEncoding,
|
||||||
|
) -> Arc<dyn PrimaryKeyCodec> {
|
||||||
|
let fields = metadata.primary_key_columns().map(|c| {
|
||||||
|
(
|
||||||
|
c.column_id,
|
||||||
|
SortField::new(c.column_schema.data_type.clone()),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
build_primary_key_codec_with_fields(encoding, fields)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_region_metadata(arg: &ColumnarValue) -> datafusion_common::Result<RegionMetadata> {
|
||||||
|
let json = match arg {
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some(v)))
|
||||||
|
| ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(v))) => v.as_str(),
|
||||||
|
ColumnarValue::Scalar(value) => {
|
||||||
|
return Err(DataFusionError::Execution(format!(
|
||||||
|
"region metadata must be a string literal, got {value:?}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
ColumnarValue::Array(_) => {
|
||||||
|
return Err(DataFusionError::Execution(
|
||||||
|
"region metadata must be a scalar string".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RegionMetadata::from_json(json)
|
||||||
|
.map_err(|e| DataFusionError::Execution(format!("failed to parse region metadata: {e:?}")))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_primary_keys(
|
||||||
|
encoded: ArrayRef,
|
||||||
|
number_rows: usize,
|
||||||
|
codec: &dyn PrimaryKeyCodec,
|
||||||
|
name_lookup: &HashMap<ColumnId, String>,
|
||||||
|
) -> datafusion_common::Result<Vec<Vec<NameValuePair>>> {
|
||||||
|
if let Some(dict) = encoded
|
||||||
|
.as_any()
|
||||||
|
.downcast_ref::<DictionaryArray<UInt32Type>>()
|
||||||
|
{
|
||||||
|
decode_dictionary(dict, number_rows, codec, name_lookup)
|
||||||
|
} else if let Some(array) = encoded.as_any().downcast_ref::<BinaryArray>() {
|
||||||
|
decode_binary_array(array, codec, name_lookup)
|
||||||
|
} else if let Some(array) = encoded.as_any().downcast_ref::<BinaryViewArray>() {
|
||||||
|
decode_binary_view_array(array, codec, name_lookup)
|
||||||
|
} else {
|
||||||
|
Err(DataFusionError::Execution(format!(
|
||||||
|
"column {PRIMARY_KEY_COLUMN_NAME} must be binary or dictionary(binary) array"
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_dictionary(
|
||||||
|
dict: &DictionaryArray<UInt32Type>,
|
||||||
|
number_rows: usize,
|
||||||
|
codec: &dyn PrimaryKeyCodec,
|
||||||
|
name_lookup: &HashMap<ColumnId, String>,
|
||||||
|
) -> datafusion_common::Result<Vec<Vec<NameValuePair>>> {
|
||||||
|
let values = dict
|
||||||
|
.values()
|
||||||
|
.as_any()
|
||||||
|
.downcast_ref::<BinaryArray>()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DataFusionError::Execution("primary key dictionary values are not binary".to_string())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let mut decoded_values = Vec::with_capacity(values.len());
|
||||||
|
for i in 0..values.len() {
|
||||||
|
let pk = values.value(i);
|
||||||
|
let pairs = decode_one(pk, codec, name_lookup)?;
|
||||||
|
decoded_values.push(pairs);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut rows = Vec::with_capacity(number_rows);
|
||||||
|
let keys = dict.keys();
|
||||||
|
for i in 0..number_rows {
|
||||||
|
let dict_index = keys.value(i) as usize;
|
||||||
|
rows.push(decoded_values[dict_index].clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_binary_array(
|
||||||
|
array: &BinaryArray,
|
||||||
|
codec: &dyn PrimaryKeyCodec,
|
||||||
|
name_lookup: &HashMap<ColumnId, String>,
|
||||||
|
) -> datafusion_common::Result<Vec<Vec<NameValuePair>>> {
|
||||||
|
(0..array.len())
|
||||||
|
.map(|i| decode_one(array.value(i), codec, name_lookup))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_binary_view_array(
|
||||||
|
array: &BinaryViewArray,
|
||||||
|
codec: &dyn PrimaryKeyCodec,
|
||||||
|
name_lookup: &HashMap<ColumnId, String>,
|
||||||
|
) -> datafusion_common::Result<Vec<Vec<NameValuePair>>> {
|
||||||
|
(0..array.len())
|
||||||
|
.map(|i| decode_one(array.value(i), codec, name_lookup))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_one(
|
||||||
|
pk: &[u8],
|
||||||
|
codec: &dyn PrimaryKeyCodec,
|
||||||
|
name_lookup: &HashMap<ColumnId, String>,
|
||||||
|
) -> datafusion_common::Result<Vec<NameValuePair>> {
|
||||||
|
let decoded = codec
|
||||||
|
.decode(pk)
|
||||||
|
.map_err(|e| DataFusionError::Execution(format!("failed to decode primary key: {e}")))?;
|
||||||
|
|
||||||
|
Ok(match decoded {
|
||||||
|
CompositeValues::Dense(values) => values
|
||||||
|
.into_iter()
|
||||||
|
.map(|(column_id, value)| (column_name(column_id, name_lookup), value_to_string(value)))
|
||||||
|
.collect(),
|
||||||
|
CompositeValues::Sparse(values) => {
|
||||||
|
let mut values: Vec<_> = values
|
||||||
|
.iter()
|
||||||
|
.map(|(column_id, value)| {
|
||||||
|
(
|
||||||
|
*column_id,
|
||||||
|
column_name(*column_id, name_lookup),
|
||||||
|
value_to_string(value.clone()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
values.sort_by_key(|(column_id, _, _)| {
|
||||||
|
(ReservedColumnId::is_reserved(*column_id), *column_id)
|
||||||
|
});
|
||||||
|
values
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_, name, value)| (name, value))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn column_name(column_id: ColumnId, name_lookup: &HashMap<ColumnId, String>) -> String {
|
||||||
|
if let Some(name) = name_lookup.get(&column_id) {
|
||||||
|
return name.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
if column_id == ReservedColumnId::table_id() {
|
||||||
|
return "__table_id".to_string();
|
||||||
|
}
|
||||||
|
if column_id == ReservedColumnId::tsid() {
|
||||||
|
return "__tsid".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
column_id.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value_to_string(value: Value) -> Option<String> {
|
||||||
|
match value {
|
||||||
|
Value::Null => None,
|
||||||
|
_ => Some(value.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_list_array(rows: &[Vec<NameValuePair>]) -> datafusion_common::Result<ArrayRef> {
|
||||||
|
let mut builder = ListBuilder::new(StringBuilder::new());
|
||||||
|
|
||||||
|
for row in rows {
|
||||||
|
for (key, value) in row {
|
||||||
|
let value = value.as_deref().unwrap_or(NULL_VALUE_LITERAL);
|
||||||
|
builder.values().append_value(format!("{key} : {value}"));
|
||||||
|
}
|
||||||
|
builder.append(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Arc::new(builder.finish()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use api::v1::SemanticType;
|
||||||
|
use datafusion_common::ScalarValue;
|
||||||
|
use datatypes::arrow::array::builder::BinaryDictionaryBuilder;
|
||||||
|
use datatypes::arrow::array::{BinaryArray, ListArray, StringArray};
|
||||||
|
use datatypes::arrow::datatypes::UInt32Type;
|
||||||
|
use datatypes::prelude::ConcreteDataType;
|
||||||
|
use datatypes::schema::ColumnSchema;
|
||||||
|
use datatypes::value::Value;
|
||||||
|
use mito_codec::row_converter::{
|
||||||
|
DensePrimaryKeyCodec, PrimaryKeyCodecExt, SortField, SparsePrimaryKeyCodec,
|
||||||
|
};
|
||||||
|
use store_api::codec::PrimaryKeyEncoding;
|
||||||
|
use store_api::metadata::{ColumnMetadata, RegionMetadataBuilder};
|
||||||
|
use store_api::storage::consts::ReservedColumnId;
|
||||||
|
use store_api::storage::{ColumnId, RegionId};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn pk_field() -> Arc<Field> {
|
||||||
|
Arc::new(Field::new_dictionary(
|
||||||
|
PRIMARY_KEY_COLUMN_NAME,
|
||||||
|
DataType::UInt32,
|
||||||
|
DataType::Binary,
|
||||||
|
false,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn region_metadata_json(
|
||||||
|
columns: &[(ColumnId, &str, ConcreteDataType)],
|
||||||
|
encoding: PrimaryKeyEncoding,
|
||||||
|
) -> String {
|
||||||
|
let mut builder = RegionMetadataBuilder::new(RegionId::new(1, 1));
|
||||||
|
builder.push_column_metadata(ColumnMetadata {
|
||||||
|
column_schema: ColumnSchema::new(
|
||||||
|
"ts",
|
||||||
|
ConcreteDataType::timestamp_millisecond_datatype(),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
semantic_type: SemanticType::Timestamp,
|
||||||
|
column_id: 100,
|
||||||
|
});
|
||||||
|
builder.primary_key_encoding(encoding);
|
||||||
|
for (id, name, ty) in columns {
|
||||||
|
builder.push_column_metadata(ColumnMetadata {
|
||||||
|
column_schema: ColumnSchema::new((*name).to_string(), ty.clone(), true),
|
||||||
|
semantic_type: SemanticType::Tag,
|
||||||
|
column_id: *id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
builder.primary_key(columns.iter().map(|(id, _, _)| *id).collect());
|
||||||
|
|
||||||
|
builder.build().unwrap().to_json().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list_row(list: &ListArray, row_idx: usize) -> Vec<String> {
|
||||||
|
let values = list.value(row_idx);
|
||||||
|
let values = values.as_any().downcast_ref::<StringArray>().unwrap();
|
||||||
|
(0..values.len())
|
||||||
|
.map(|i| values.value(i).to_string())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_decode_dense_primary_key() {
|
||||||
|
let columns = vec![
|
||||||
|
(0, "host", ConcreteDataType::string_datatype()),
|
||||||
|
(1, "core", ConcreteDataType::int64_datatype()),
|
||||||
|
];
|
||||||
|
let metadata_json = region_metadata_json(&columns, PrimaryKeyEncoding::Dense);
|
||||||
|
let codec = DensePrimaryKeyCodec::with_fields(
|
||||||
|
columns
|
||||||
|
.iter()
|
||||||
|
.map(|(id, _, ty)| (*id, SortField::new(ty.clone())))
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rows = vec![
|
||||||
|
vec![Value::from("a"), Value::from(1_i64)],
|
||||||
|
vec![Value::from("b"), Value::from(2_i64)],
|
||||||
|
vec![Value::from("a"), Value::from(1_i64)],
|
||||||
|
];
|
||||||
|
|
||||||
|
let mut builder = BinaryDictionaryBuilder::<UInt32Type>::new();
|
||||||
|
for row in &rows {
|
||||||
|
let encoded = codec.encode(row.iter().map(|v| v.as_value_ref())).unwrap();
|
||||||
|
builder.append(encoded.as_slice()).unwrap();
|
||||||
|
}
|
||||||
|
let dict_array: ArrayRef = Arc::new(builder.finish());
|
||||||
|
|
||||||
|
let args = ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Array(dict_array),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("dense".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some(metadata_json))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![
|
||||||
|
pk_field(),
|
||||||
|
Arc::new(Field::new("encoding", DataType::Utf8, false)),
|
||||||
|
Arc::new(Field::new("region_metadata", DataType::Utf8, false)),
|
||||||
|
],
|
||||||
|
number_rows: 3,
|
||||||
|
return_field: Arc::new(Field::new(
|
||||||
|
"decoded",
|
||||||
|
DecodePrimaryKeyFunction::return_data_type(),
|
||||||
|
false,
|
||||||
|
)),
|
||||||
|
config_options: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let func = DecodePrimaryKeyFunction::default();
|
||||||
|
let result = func
|
||||||
|
.invoke_with_args(args)
|
||||||
|
.and_then(|v| v.to_array(3))
|
||||||
|
.unwrap();
|
||||||
|
let list = result.as_any().downcast_ref::<ListArray>().unwrap();
|
||||||
|
|
||||||
|
let expected = [
|
||||||
|
vec!["host : a".to_string(), "core : 1".to_string()],
|
||||||
|
vec!["host : b".to_string(), "core : 2".to_string()],
|
||||||
|
vec!["host : a".to_string(), "core : 1".to_string()],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (row_idx, expected_row) in expected.iter().enumerate() {
|
||||||
|
assert_eq!(*expected_row, list_row(list, row_idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_decode_sparse_primary_key() {
|
||||||
|
let columns = vec![
|
||||||
|
(10, "k0", ConcreteDataType::string_datatype()),
|
||||||
|
(11, "k1", ConcreteDataType::string_datatype()),
|
||||||
|
];
|
||||||
|
let metadata_json = region_metadata_json(&columns, PrimaryKeyEncoding::Sparse);
|
||||||
|
let codec = SparsePrimaryKeyCodec::schemaless();
|
||||||
|
|
||||||
|
let rows = vec![
|
||||||
|
vec![
|
||||||
|
(ReservedColumnId::table_id(), Value::UInt32(1)),
|
||||||
|
(ReservedColumnId::tsid(), Value::UInt64(100)),
|
||||||
|
(10, Value::from("a")),
|
||||||
|
(11, Value::from("b")),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
(ReservedColumnId::table_id(), Value::UInt32(1)),
|
||||||
|
(ReservedColumnId::tsid(), Value::UInt64(200)),
|
||||||
|
(10, Value::from("c")),
|
||||||
|
(11, Value::from("d")),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
let mut encoded_values = Vec::with_capacity(rows.len());
|
||||||
|
for row in &rows {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
codec.encode_values(row, &mut buf).unwrap();
|
||||||
|
encoded_values.push(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
let pk_array: ArrayRef = Arc::new(BinaryArray::from_iter_values(
|
||||||
|
encoded_values.iter().cloned(),
|
||||||
|
));
|
||||||
|
|
||||||
|
let args = ScalarFunctionArgs {
|
||||||
|
args: vec![
|
||||||
|
ColumnarValue::Array(pk_array),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("sparse".to_string()))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some(metadata_json))),
|
||||||
|
],
|
||||||
|
arg_fields: vec![
|
||||||
|
pk_field(),
|
||||||
|
Arc::new(Field::new("encoding", DataType::Utf8, false)),
|
||||||
|
Arc::new(Field::new("region_metadata", DataType::Utf8, false)),
|
||||||
|
],
|
||||||
|
number_rows: rows.len(),
|
||||||
|
return_field: Arc::new(Field::new(
|
||||||
|
"decoded",
|
||||||
|
DecodePrimaryKeyFunction::return_data_type(),
|
||||||
|
false,
|
||||||
|
)),
|
||||||
|
config_options: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let func = DecodePrimaryKeyFunction::default();
|
||||||
|
let result = func
|
||||||
|
.invoke_with_args(args)
|
||||||
|
.and_then(|v| v.to_array(rows.len()))
|
||||||
|
.unwrap();
|
||||||
|
let list = result.as_any().downcast_ref::<ListArray>().unwrap();
|
||||||
|
|
||||||
|
let expected = [
|
||||||
|
vec![
|
||||||
|
"k0 : a".to_string(),
|
||||||
|
"k1 : b".to_string(),
|
||||||
|
"__tsid : 100".to_string(),
|
||||||
|
"__table_id : 1".to_string(),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
"k0 : c".to_string(),
|
||||||
|
"k1 : d".to_string(),
|
||||||
|
"__tsid : 200".to_string(),
|
||||||
|
"__table_id : 1".to_string(),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (row_idx, expected_row) in expected.iter().enumerate() {
|
||||||
|
assert_eq!(*expected_row, list_row(list, row_idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,7 +44,8 @@ impl FunctionState {
|
|||||||
use session::context::QueryContextRef;
|
use session::context::QueryContextRef;
|
||||||
use store_api::storage::RegionId;
|
use store_api::storage::RegionId;
|
||||||
use table::requests::{
|
use table::requests::{
|
||||||
CompactTableRequest, DeleteRequest, FlushTableRequest, InsertRequest,
|
BuildIndexTableRequest, CompactTableRequest, DeleteRequest, FlushTableRequest,
|
||||||
|
InsertRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::handlers::{FlowServiceHandler, ProcedureServiceHandler, TableMutationHandler};
|
use crate::handlers::{FlowServiceHandler, ProcedureServiceHandler, TableMutationHandler};
|
||||||
@@ -120,6 +121,14 @@ impl FunctionState {
|
|||||||
Ok(ROWS)
|
Ok(ROWS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn build_index(
|
||||||
|
&self,
|
||||||
|
_request: BuildIndexTableRequest,
|
||||||
|
_ctx: QueryContextRef,
|
||||||
|
) -> Result<AffectedRows> {
|
||||||
|
Ok(ROWS)
|
||||||
|
}
|
||||||
|
|
||||||
async fn flush_region(
|
async fn flush_region(
|
||||||
&self,
|
&self,
|
||||||
_region_id: RegionId,
|
_region_id: RegionId,
|
||||||
|
|||||||
@@ -12,21 +12,19 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
mod version;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use common_catalog::consts::{
|
use common_catalog::consts::{
|
||||||
DEFAULT_PRIVATE_SCHEMA_NAME, INFORMATION_SCHEMA_NAME, PG_CATALOG_NAME,
|
DEFAULT_PRIVATE_SCHEMA_NAME, INFORMATION_SCHEMA_NAME, PG_CATALOG_NAME,
|
||||||
};
|
};
|
||||||
use datafusion::arrow::array::{ArrayRef, StringArray, as_boolean_array};
|
use datafusion::arrow::array::{ArrayRef, StringArray, StringBuilder, as_boolean_array};
|
||||||
use datafusion::catalog::TableFunction;
|
use datafusion::catalog::TableFunction;
|
||||||
use datafusion::common::ScalarValue;
|
use datafusion::common::ScalarValue;
|
||||||
use datafusion::common::utils::SingleRowListArrayBuilder;
|
use datafusion::common::utils::SingleRowListArrayBuilder;
|
||||||
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
|
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, TypeSignature, Volatility};
|
||||||
use datafusion_pg_catalog::pg_catalog::{self, PgCatalogStaticTables};
|
use datafusion_pg_catalog::pg_catalog::{self, PgCatalogStaticTables};
|
||||||
use datatypes::arrow::datatypes::{DataType, Field};
|
use datatypes::arrow::datatypes::{DataType, Field};
|
||||||
use version::PGVersionFunction;
|
use derive_more::derive::Display;
|
||||||
|
|
||||||
use crate::function::{Function, find_function_context};
|
use crate::function::{Function, find_function_context};
|
||||||
use crate::function_registry::FunctionRegistry;
|
use crate::function_registry::FunctionRegistry;
|
||||||
@@ -36,11 +34,15 @@ const CURRENT_SCHEMA_FUNCTION_NAME: &str = "current_schema";
|
|||||||
const CURRENT_SCHEMAS_FUNCTION_NAME: &str = "current_schemas";
|
const CURRENT_SCHEMAS_FUNCTION_NAME: &str = "current_schemas";
|
||||||
const SESSION_USER_FUNCTION_NAME: &str = "session_user";
|
const SESSION_USER_FUNCTION_NAME: &str = "session_user";
|
||||||
const CURRENT_DATABASE_FUNCTION_NAME: &str = "current_database";
|
const CURRENT_DATABASE_FUNCTION_NAME: &str = "current_database";
|
||||||
|
const OBJ_DESCRIPTION_FUNCTION_NAME: &str = "obj_description";
|
||||||
|
const COL_DESCRIPTION_FUNCTION_NAME: &str = "col_description";
|
||||||
|
const SHOBJ_DESCRIPTION_FUNCTION_NAME: &str = "shobj_description";
|
||||||
|
const PG_MY_TEMP_SCHEMA_FUNCTION_NAME: &str = "pg_my_temp_schema";
|
||||||
|
|
||||||
define_nullary_udf!(CurrentSchemaFunction);
|
define_nullary_udf!(CurrentSchemaFunction);
|
||||||
define_nullary_udf!(CurrentSchemasFunction);
|
|
||||||
define_nullary_udf!(SessionUserFunction);
|
define_nullary_udf!(SessionUserFunction);
|
||||||
define_nullary_udf!(CurrentDatabaseFunction);
|
define_nullary_udf!(CurrentDatabaseFunction);
|
||||||
|
define_nullary_udf!(PgMyTempSchemaFunction);
|
||||||
|
|
||||||
impl Function for CurrentDatabaseFunction {
|
impl Function for CurrentDatabaseFunction {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
@@ -118,6 +120,23 @@ impl Function for SessionUserFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Display, Debug)]
|
||||||
|
#[display("{}", self.name())]
|
||||||
|
pub(super) struct CurrentSchemasFunction {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CurrentSchemasFunction {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: Signature::new(
|
||||||
|
TypeSignature::Exact(vec![DataType::Boolean]),
|
||||||
|
Volatility::Stable,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Function for CurrentSchemasFunction {
|
impl Function for CurrentSchemasFunction {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
CURRENT_SCHEMAS_FUNCTION_NAME
|
CURRENT_SCHEMAS_FUNCTION_NAME
|
||||||
@@ -125,9 +144,9 @@ impl Function for CurrentSchemasFunction {
|
|||||||
|
|
||||||
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
Ok(DataType::List(Arc::new(Field::new(
|
Ok(DataType::List(Arc::new(Field::new(
|
||||||
"x",
|
"item",
|
||||||
DataType::Utf8View,
|
DataType::Utf8,
|
||||||
false,
|
true,
|
||||||
))))
|
))))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +178,175 @@ impl Function for CurrentSchemasFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// PostgreSQL obj_description - returns NULL for compatibility
|
||||||
|
#[derive(Display, Debug, Clone)]
|
||||||
|
#[display("{}", self.name())]
|
||||||
|
pub(super) struct ObjDescriptionFunction {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjDescriptionFunction {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: Signature::one_of(
|
||||||
|
vec![
|
||||||
|
TypeSignature::Exact(vec![DataType::Int64, DataType::Utf8]),
|
||||||
|
TypeSignature::Exact(vec![DataType::UInt32, DataType::Utf8]),
|
||||||
|
TypeSignature::Exact(vec![DataType::Int64]),
|
||||||
|
TypeSignature::Exact(vec![DataType::UInt32]),
|
||||||
|
],
|
||||||
|
Volatility::Stable,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Function for ObjDescriptionFunction {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
OBJ_DESCRIPTION_FUNCTION_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
Ok(DataType::Utf8)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
let num_rows = args.number_rows;
|
||||||
|
let mut builder = StringBuilder::with_capacity(num_rows, 0);
|
||||||
|
for _ in 0..num_rows {
|
||||||
|
builder.append_null();
|
||||||
|
}
|
||||||
|
Ok(ColumnarValue::Array(Arc::new(builder.finish())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PostgreSQL col_description - returns NULL for compatibility
|
||||||
|
#[derive(Display, Debug, Clone)]
|
||||||
|
#[display("{}", self.name())]
|
||||||
|
pub(super) struct ColDescriptionFunction {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ColDescriptionFunction {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: Signature::one_of(
|
||||||
|
vec![
|
||||||
|
TypeSignature::Exact(vec![DataType::Int64, DataType::Int32]),
|
||||||
|
TypeSignature::Exact(vec![DataType::UInt32, DataType::Int32]),
|
||||||
|
TypeSignature::Exact(vec![DataType::Int64, DataType::Int64]),
|
||||||
|
TypeSignature::Exact(vec![DataType::UInt32, DataType::Int64]),
|
||||||
|
],
|
||||||
|
Volatility::Stable,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Function for ColDescriptionFunction {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
COL_DESCRIPTION_FUNCTION_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
Ok(DataType::Utf8)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
let num_rows = args.number_rows;
|
||||||
|
let mut builder = StringBuilder::with_capacity(num_rows, 0);
|
||||||
|
for _ in 0..num_rows {
|
||||||
|
builder.append_null();
|
||||||
|
}
|
||||||
|
Ok(ColumnarValue::Array(Arc::new(builder.finish())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PostgreSQL shobj_description - returns NULL for compatibility
|
||||||
|
#[derive(Display, Debug, Clone)]
|
||||||
|
#[display("{}", self.name())]
|
||||||
|
pub(super) struct ShobjDescriptionFunction {
|
||||||
|
signature: Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShobjDescriptionFunction {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
signature: Signature::one_of(
|
||||||
|
vec![
|
||||||
|
TypeSignature::Exact(vec![DataType::Int64, DataType::Utf8]),
|
||||||
|
TypeSignature::Exact(vec![DataType::UInt64, DataType::Utf8]),
|
||||||
|
TypeSignature::Exact(vec![DataType::Int32, DataType::Utf8]),
|
||||||
|
TypeSignature::Exact(vec![DataType::UInt32, DataType::Utf8]),
|
||||||
|
],
|
||||||
|
Volatility::Stable,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Function for ShobjDescriptionFunction {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
SHOBJ_DESCRIPTION_FUNCTION_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
Ok(DataType::Utf8)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
let num_rows = args.number_rows;
|
||||||
|
let mut builder = StringBuilder::with_capacity(num_rows, 0);
|
||||||
|
for _ in 0..num_rows {
|
||||||
|
builder.append_null();
|
||||||
|
}
|
||||||
|
Ok(ColumnarValue::Array(Arc::new(builder.finish())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PostgreSQL pg_my_temp_schema - returns 0 (no temp schema) for compatibility
|
||||||
|
impl Function for PgMyTempSchemaFunction {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
PG_MY_TEMP_SCHEMA_FUNCTION_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
||||||
|
Ok(DataType::UInt32)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> &Signature {
|
||||||
|
&self.signature
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invoke_with_args(
|
||||||
|
&self,
|
||||||
|
_args: ScalarFunctionArgs,
|
||||||
|
) -> datafusion_common::Result<ColumnarValue> {
|
||||||
|
Ok(ColumnarValue::Scalar(ScalarValue::UInt32(Some(0))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) struct PGCatalogFunction;
|
pub(super) struct PGCatalogFunction;
|
||||||
|
|
||||||
impl PGCatalogFunction {
|
impl PGCatalogFunction {
|
||||||
@@ -166,9 +354,8 @@ impl PGCatalogFunction {
|
|||||||
let static_tables =
|
let static_tables =
|
||||||
Arc::new(PgCatalogStaticTables::try_new().expect("load postgres static tables"));
|
Arc::new(PgCatalogStaticTables::try_new().expect("load postgres static tables"));
|
||||||
|
|
||||||
registry.register_scalar(PGVersionFunction::default());
|
|
||||||
registry.register_scalar(CurrentSchemaFunction::default());
|
registry.register_scalar(CurrentSchemaFunction::default());
|
||||||
registry.register_scalar(CurrentSchemasFunction::default());
|
registry.register_scalar(CurrentSchemasFunction::new());
|
||||||
registry.register_scalar(SessionUserFunction::default());
|
registry.register_scalar(SessionUserFunction::default());
|
||||||
registry.register_scalar(CurrentDatabaseFunction::default());
|
registry.register_scalar(CurrentDatabaseFunction::default());
|
||||||
registry.register(pg_catalog::format_type::create_format_type_udf());
|
registry.register(pg_catalog::format_type::create_format_type_udf());
|
||||||
@@ -199,5 +386,98 @@ impl PGCatalogFunction {
|
|||||||
registry.register(pg_catalog::create_pg_total_relation_size_udf());
|
registry.register(pg_catalog::create_pg_total_relation_size_udf());
|
||||||
registry.register(pg_catalog::create_pg_stat_get_numscans());
|
registry.register(pg_catalog::create_pg_stat_get_numscans());
|
||||||
registry.register(pg_catalog::create_pg_get_constraintdef());
|
registry.register(pg_catalog::create_pg_get_constraintdef());
|
||||||
|
registry.register(pg_catalog::create_pg_get_partition_ancestors_udf());
|
||||||
|
registry.register_scalar(ObjDescriptionFunction::new());
|
||||||
|
registry.register_scalar(ColDescriptionFunction::new());
|
||||||
|
registry.register_scalar(ShobjDescriptionFunction::new());
|
||||||
|
registry.register_scalar(PgMyTempSchemaFunction::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arrow_schema::Field;
|
||||||
|
use datafusion::arrow::array::Array;
|
||||||
|
use datafusion_common::ScalarValue;
|
||||||
|
use datafusion_expr::ColumnarValue;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn create_test_args(args: Vec<ColumnarValue>, number_rows: usize) -> ScalarFunctionArgs {
|
||||||
|
ScalarFunctionArgs {
|
||||||
|
args,
|
||||||
|
arg_fields: vec![],
|
||||||
|
number_rows,
|
||||||
|
return_field: Arc::new(Field::new("result", DataType::Utf8, true)),
|
||||||
|
config_options: Arc::new(Default::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_obj_description_function() {
|
||||||
|
let func = ObjDescriptionFunction::new();
|
||||||
|
assert_eq!("obj_description", func.name());
|
||||||
|
assert_eq!(DataType::Utf8, func.return_type(&[]).unwrap());
|
||||||
|
|
||||||
|
let args = create_test_args(
|
||||||
|
vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Int64(Some(1234))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("pg_class".to_string()))),
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
let result = func.invoke_with_args(args).unwrap();
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
assert_eq!(1, arr.len());
|
||||||
|
assert!(arr.is_null(0));
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_col_description_function() {
|
||||||
|
let func = ColDescriptionFunction::new();
|
||||||
|
assert_eq!("col_description", func.name());
|
||||||
|
assert_eq!(DataType::Utf8, func.return_type(&[]).unwrap());
|
||||||
|
|
||||||
|
let args = create_test_args(
|
||||||
|
vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Int64(Some(1234))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Int64(Some(1))),
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
let result = func.invoke_with_args(args).unwrap();
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
assert_eq!(1, arr.len());
|
||||||
|
assert!(arr.is_null(0));
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_shobj_description_function() {
|
||||||
|
let func = ShobjDescriptionFunction::new();
|
||||||
|
assert_eq!("shobj_description", func.name());
|
||||||
|
assert_eq!(DataType::Utf8, func.return_type(&[]).unwrap());
|
||||||
|
|
||||||
|
let args = create_test_args(
|
||||||
|
vec![
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Int64(Some(1))),
|
||||||
|
ColumnarValue::Scalar(ScalarValue::Utf8(Some("pg_database".to_string()))),
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
let result = func.invoke_with_args(args).unwrap();
|
||||||
|
if let ColumnarValue::Array(arr) = result {
|
||||||
|
assert_eq!(1, arr.len());
|
||||||
|
assert!(arr.is_null(0));
|
||||||
|
} else {
|
||||||
|
panic!("Expected Array result");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
// Copyright 2023 Greptime Team
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use datafusion::arrow::datatypes::DataType;
|
|
||||||
use datafusion_common::ScalarValue;
|
|
||||||
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
|
|
||||||
|
|
||||||
use crate::function::Function;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub(crate) struct PGVersionFunction {
|
|
||||||
signature: Signature,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PGVersionFunction {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
signature: Signature::exact(vec![], Volatility::Immutable),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for PGVersionFunction {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "pg_catalog.VERSION")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Function for PGVersionFunction {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"pg_catalog.version"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
|
|
||||||
Ok(DataType::Utf8View)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn signature(&self) -> &Signature {
|
|
||||||
&self.signature
|
|
||||||
}
|
|
||||||
|
|
||||||
fn invoke_with_args(&self, _: ScalarFunctionArgs) -> datafusion_common::Result<ColumnarValue> {
|
|
||||||
Ok(ColumnarValue::Scalar(ScalarValue::Utf8View(Some(format!(
|
|
||||||
"PostgreSQL 16.3 GreptimeDB {}",
|
|
||||||
common_version::version()
|
|
||||||
)))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,7 +50,7 @@ impl Function for VersionFunction {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Channel::Postgres => {
|
Channel::Postgres => {
|
||||||
format!("16.3-greptimedb-{}", common_version::version())
|
format!("PostgreSQL 16.3 GreptimeDB {}", common_version::version())
|
||||||
}
|
}
|
||||||
_ => common_version::version().to_string(),
|
_ => common_version::version().to_string(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ datatypes.workspace = true
|
|||||||
flatbuffers = "25.2"
|
flatbuffers = "25.2"
|
||||||
hyper.workspace = true
|
hyper.workspace = true
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
|
notify.workspace = true
|
||||||
prost.workspace = true
|
prost.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
@@ -37,6 +38,7 @@ vec1 = "1.12"
|
|||||||
criterion = "0.4"
|
criterion = "0.4"
|
||||||
hyper-util = { workspace = true, features = ["tokio"] }
|
hyper-util = { workspace = true, features = ["tokio"] }
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
|
tempfile.workspace = true
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bench_main"
|
name = "bench_main"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -30,6 +31,7 @@ use tonic::transport::{
|
|||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
use crate::error::{CreateChannelSnafu, InvalidConfigFilePathSnafu, Result};
|
use crate::error::{CreateChannelSnafu, InvalidConfigFilePathSnafu, Result};
|
||||||
|
use crate::reloadable_tls::{ReloadableTlsConfig, TlsConfigLoader, maybe_watch_tls_config};
|
||||||
|
|
||||||
const RECYCLE_CHANNEL_INTERVAL_SECS: u64 = 60;
|
const RECYCLE_CHANNEL_INTERVAL_SECS: u64 = 60;
|
||||||
pub const DEFAULT_GRPC_REQUEST_TIMEOUT_SECS: u64 = 10;
|
pub const DEFAULT_GRPC_REQUEST_TIMEOUT_SECS: u64 = 10;
|
||||||
@@ -50,7 +52,7 @@ pub struct ChannelManager {
|
|||||||
struct Inner {
|
struct Inner {
|
||||||
id: u64,
|
id: u64,
|
||||||
config: ChannelConfig,
|
config: ChannelConfig,
|
||||||
client_tls_config: Option<ClientTlsConfig>,
|
reloadable_client_tls_config: Option<Arc<ReloadableClientTlsConfig>>,
|
||||||
pool: Arc<Pool>,
|
pool: Arc<Pool>,
|
||||||
channel_recycle_started: AtomicBool,
|
channel_recycle_started: AtomicBool,
|
||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
@@ -78,7 +80,7 @@ impl Inner {
|
|||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
config,
|
config,
|
||||||
client_tls_config: None,
|
reloadable_client_tls_config: None,
|
||||||
pool,
|
pool,
|
||||||
channel_recycle_started: AtomicBool::new(false),
|
channel_recycle_started: AtomicBool::new(false),
|
||||||
cancel,
|
cancel,
|
||||||
@@ -91,13 +93,17 @@ impl ChannelManager {
|
|||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// unified with config function that support tls config
|
/// Create a ChannelManager with configuration and optional TLS config
|
||||||
/// use [`load_tls_config`] to load tls config from file system
|
///
|
||||||
pub fn with_config(config: ChannelConfig, tls_config: Option<ClientTlsConfig>) -> Self {
|
/// Use [`load_client_tls_config`] to create TLS configuration from `ClientTlsOption`.
|
||||||
|
/// The TLS config supports both static (watch disabled) and dynamic reloading (watch enabled).
|
||||||
|
/// If you want to use dynamic reloading, please **manually** invoke [`maybe_watch_client_tls_config`] after this method.
|
||||||
|
pub fn with_config(
|
||||||
|
config: ChannelConfig,
|
||||||
|
reloadable_tls_config: Option<Arc<ReloadableClientTlsConfig>>,
|
||||||
|
) -> Self {
|
||||||
let mut inner = Inner::with_config(config.clone());
|
let mut inner = Inner::with_config(config.clone());
|
||||||
if let Some(tls_config) = tls_config {
|
inner.reloadable_client_tls_config = reloadable_tls_config;
|
||||||
inner.client_tls_config = Some(tls_config);
|
|
||||||
}
|
|
||||||
Self {
|
Self {
|
||||||
inner: Arc::new(inner),
|
inner: Arc::new(inner),
|
||||||
}
|
}
|
||||||
@@ -172,8 +178,21 @@ impl ChannelManager {
|
|||||||
self.pool().retain_channel(f);
|
self.pool().retain_channel(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clear all channels to force reconnection.
|
||||||
|
/// This should be called when TLS configuration changes to ensure new connections use updated certificates.
|
||||||
|
pub fn clear_all_channels(&self) {
|
||||||
|
self.pool().retain_channel(|_, _| false);
|
||||||
|
}
|
||||||
|
|
||||||
fn build_endpoint(&self, addr: &str) -> Result<Endpoint> {
|
fn build_endpoint(&self, addr: &str) -> Result<Endpoint> {
|
||||||
let http_prefix = if self.inner.client_tls_config.is_some() {
|
// Get the latest TLS config from reloadable config (which handles both static and dynamic cases)
|
||||||
|
let tls_config = self
|
||||||
|
.inner
|
||||||
|
.reloadable_client_tls_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|c| c.get_config());
|
||||||
|
|
||||||
|
let http_prefix = if tls_config.is_some() {
|
||||||
"https"
|
"https"
|
||||||
} else {
|
} else {
|
||||||
"http"
|
"http"
|
||||||
@@ -212,9 +231,9 @@ impl ChannelManager {
|
|||||||
if let Some(enabled) = self.config().http2_adaptive_window {
|
if let Some(enabled) = self.config().http2_adaptive_window {
|
||||||
endpoint = endpoint.http2_adaptive_window(enabled);
|
endpoint = endpoint.http2_adaptive_window(enabled);
|
||||||
}
|
}
|
||||||
if let Some(tls_config) = &self.inner.client_tls_config {
|
if let Some(tls_config) = tls_config {
|
||||||
endpoint = endpoint
|
endpoint = endpoint
|
||||||
.tls_config(tls_config.clone())
|
.tls_config(tls_config)
|
||||||
.context(CreateChannelSnafu { addr })?;
|
.context(CreateChannelSnafu { addr })?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +267,7 @@ impl ChannelManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_tls_config(tls_option: Option<&ClientTlsOption>) -> Result<Option<ClientTlsConfig>> {
|
fn load_tls_config(tls_option: Option<&ClientTlsOption>) -> Result<Option<ClientTlsConfig>> {
|
||||||
let path_config = match tls_option {
|
let path_config = match tls_option {
|
||||||
Some(path_config) if path_config.enabled => path_config,
|
Some(path_config) if path_config.enabled => path_config,
|
||||||
_ => return Ok(None),
|
_ => return Ok(None),
|
||||||
@@ -276,13 +295,69 @@ pub fn load_tls_config(tls_option: Option<&ClientTlsOption>) -> Result<Option<Cl
|
|||||||
Ok(Some(tls_config))
|
Ok(Some(tls_config))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
impl TlsConfigLoader<ClientTlsConfig> for ClientTlsOption {
|
||||||
|
type Error = crate::error::Error;
|
||||||
|
|
||||||
|
fn load(&self) -> Result<Option<ClientTlsConfig>> {
|
||||||
|
load_tls_config(Some(self))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn watch_paths(&self) -> Vec<&Path> {
|
||||||
|
let mut paths = Vec::new();
|
||||||
|
if let Some(cert_path) = &self.client_cert_path {
|
||||||
|
paths.push(Path::new(cert_path.as_str()));
|
||||||
|
}
|
||||||
|
if let Some(key_path) = &self.client_key_path {
|
||||||
|
paths.push(Path::new(key_path.as_str()));
|
||||||
|
}
|
||||||
|
if let Some(ca_path) = &self.server_ca_cert_path {
|
||||||
|
paths.push(Path::new(ca_path.as_str()));
|
||||||
|
}
|
||||||
|
paths
|
||||||
|
}
|
||||||
|
|
||||||
|
fn watch_enabled(&self) -> bool {
|
||||||
|
self.enabled && self.watch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type alias for client-side reloadable TLS config
|
||||||
|
pub type ReloadableClientTlsConfig = ReloadableTlsConfig<ClientTlsConfig, ClientTlsOption>;
|
||||||
|
|
||||||
|
/// Load client TLS configuration from `ClientTlsOption` and return a `ReloadableClientTlsConfig`.
|
||||||
|
/// This is the primary way to create TLS configuration for the ChannelManager.
|
||||||
|
pub fn load_client_tls_config(
|
||||||
|
tls_option: Option<ClientTlsOption>,
|
||||||
|
) -> Result<Option<Arc<ReloadableClientTlsConfig>>> {
|
||||||
|
match tls_option {
|
||||||
|
Some(option) if option.enabled => {
|
||||||
|
let reloadable = ReloadableClientTlsConfig::try_new(option)?;
|
||||||
|
Ok(Some(Arc::new(reloadable)))
|
||||||
|
}
|
||||||
|
_ => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn maybe_watch_client_tls_config(
|
||||||
|
client_tls_config: Arc<ReloadableClientTlsConfig>,
|
||||||
|
channel_manager: ChannelManager,
|
||||||
|
) -> Result<()> {
|
||||||
|
maybe_watch_tls_config(client_tls_config, move || {
|
||||||
|
// Clear all existing channels to force reconnection with new certificates
|
||||||
|
channel_manager.clear_all_channels();
|
||||||
|
info!("Cleared all existing channels to use new TLS certificates.");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
pub struct ClientTlsOption {
|
pub struct ClientTlsOption {
|
||||||
/// Whether to enable TLS for client.
|
/// Whether to enable TLS for client.
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub server_ca_cert_path: Option<String>,
|
pub server_ca_cert_path: Option<String>,
|
||||||
pub client_cert_path: Option<String>,
|
pub client_cert_path: Option<String>,
|
||||||
pub client_key_path: Option<String>,
|
pub client_key_path: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub watch: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
@@ -602,6 +677,7 @@ mod tests {
|
|||||||
server_ca_cert_path: Some("some_server_path".to_string()),
|
server_ca_cert_path: Some("some_server_path".to_string()),
|
||||||
client_cert_path: Some("some_cert_path".to_string()),
|
client_cert_path: Some("some_cert_path".to_string()),
|
||||||
client_key_path: Some("some_key_path".to_string()),
|
client_key_path: Some("some_key_path".to_string()),
|
||||||
|
watch: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -623,6 +699,7 @@ mod tests {
|
|||||||
server_ca_cert_path: Some("some_server_path".to_string()),
|
server_ca_cert_path: Some("some_server_path".to_string()),
|
||||||
client_cert_path: Some("some_cert_path".to_string()),
|
client_cert_path: Some("some_cert_path".to_string()),
|
||||||
client_key_path: Some("some_key_path".to_string()),
|
client_key_path: Some("some_key_path".to_string()),
|
||||||
|
watch: false,
|
||||||
}),
|
}),
|
||||||
max_recv_message_size: DEFAULT_MAX_GRPC_RECV_MESSAGE_SIZE,
|
max_recv_message_size: DEFAULT_MAX_GRPC_RECV_MESSAGE_SIZE,
|
||||||
max_send_message_size: DEFAULT_MAX_GRPC_SEND_MESSAGE_SIZE,
|
max_send_message_size: DEFAULT_MAX_GRPC_SEND_MESSAGE_SIZE,
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ pub enum Error {
|
|||||||
location: Location,
|
location: Location,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#[snafu(display("Failed to watch config file path: {}", path))]
|
||||||
|
FileWatch {
|
||||||
|
path: String,
|
||||||
|
#[snafu(source)]
|
||||||
|
error: notify::Error,
|
||||||
|
#[snafu(implicit)]
|
||||||
|
location: Location,
|
||||||
|
},
|
||||||
|
|
||||||
#[snafu(display(
|
#[snafu(display(
|
||||||
"Write type mismatch, column name: {}, expected: {}, actual: {}",
|
"Write type mismatch, column name: {}, expected: {}, actual: {}",
|
||||||
column_name,
|
column_name,
|
||||||
@@ -108,6 +117,7 @@ impl ErrorExt for Error {
|
|||||||
match self {
|
match self {
|
||||||
Error::InvalidTlsConfig { .. }
|
Error::InvalidTlsConfig { .. }
|
||||||
| Error::InvalidConfigFilePath { .. }
|
| Error::InvalidConfigFilePath { .. }
|
||||||
|
| Error::FileWatch { .. }
|
||||||
| Error::TypeMismatch { .. }
|
| Error::TypeMismatch { .. }
|
||||||
| Error::InvalidFlightData { .. }
|
| Error::InvalidFlightData { .. }
|
||||||
| Error::NotSupported { .. } => StatusCode::InvalidArguments,
|
| Error::NotSupported { .. } => StatusCode::InvalidArguments,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub mod channel_manager;
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod flight;
|
pub mod flight;
|
||||||
pub mod precision;
|
pub mod precision;
|
||||||
|
pub mod reloadable_tls;
|
||||||
pub mod select;
|
pub mod select;
|
||||||
|
|
||||||
pub use arrow_flight::FlightData;
|
pub use arrow_flight::FlightData;
|
||||||
|
|||||||
163
src/common/grpc/src/reloadable_tls.rs
Normal file
163
src/common/grpc/src/reloadable_tls.rs
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
// Copyright 2023 Greptime Team
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
use std::result::Result as StdResult;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
use common_telemetry::{error, info};
|
||||||
|
use notify::{EventKind, RecursiveMode, Watcher};
|
||||||
|
use snafu::ResultExt;
|
||||||
|
|
||||||
|
use crate::error::{FileWatchSnafu, Result};
|
||||||
|
|
||||||
|
/// A trait for loading TLS configuration from an option type
|
||||||
|
pub trait TlsConfigLoader<T> {
|
||||||
|
type Error;
|
||||||
|
|
||||||
|
/// Load the TLS configuration
|
||||||
|
fn load(&self) -> StdResult<Option<T>, Self::Error>;
|
||||||
|
|
||||||
|
/// Get paths to certificate files for watching
|
||||||
|
fn watch_paths(&self) -> Vec<&Path>;
|
||||||
|
|
||||||
|
/// Check if watching is enabled
|
||||||
|
fn watch_enabled(&self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A mutable container for TLS config
|
||||||
|
///
|
||||||
|
/// This struct allows dynamic reloading of certificates and keys.
|
||||||
|
/// It's generic over the config type (e.g., ServerConfig, ClientTlsConfig)
|
||||||
|
/// and the option type (e.g., TlsOption, ClientTlsOption).
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ReloadableTlsConfig<T, O>
|
||||||
|
where
|
||||||
|
O: TlsConfigLoader<T>,
|
||||||
|
{
|
||||||
|
tls_option: O,
|
||||||
|
config: RwLock<Option<T>>,
|
||||||
|
version: AtomicUsize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, O> ReloadableTlsConfig<T, O>
|
||||||
|
where
|
||||||
|
O: TlsConfigLoader<T>,
|
||||||
|
{
|
||||||
|
/// Create config by loading configuration from the option type
|
||||||
|
pub fn try_new(tls_option: O) -> StdResult<Self, O::Error> {
|
||||||
|
let config = tls_option.load()?;
|
||||||
|
Ok(Self {
|
||||||
|
tls_option,
|
||||||
|
config: RwLock::new(config),
|
||||||
|
version: AtomicUsize::new(0),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reread certificates and keys from file system.
|
||||||
|
pub fn reload(&self) -> StdResult<(), O::Error> {
|
||||||
|
let config = self.tls_option.load()?;
|
||||||
|
*self.config.write().unwrap() = config;
|
||||||
|
self.version.fetch_add(1, Ordering::Relaxed);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the config held by this container
|
||||||
|
pub fn get_config(&self) -> Option<T>
|
||||||
|
where
|
||||||
|
T: Clone,
|
||||||
|
{
|
||||||
|
self.config.read().unwrap().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get associated option
|
||||||
|
pub fn get_tls_option(&self) -> &O {
|
||||||
|
&self.tls_option
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get version of current config
|
||||||
|
///
|
||||||
|
/// this version will auto increase when config get reloaded.
|
||||||
|
pub fn get_version(&self) -> usize {
|
||||||
|
self.version.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Watch TLS configuration files for changes and reload automatically
|
||||||
|
///
|
||||||
|
/// This is a generic function that works with any ReloadableTlsConfig.
|
||||||
|
/// When changes are detected, it calls the provided callback after reloading.
|
||||||
|
///
|
||||||
|
/// T: the original TLS config
|
||||||
|
/// O: the compiled TLS option
|
||||||
|
/// F: the hook function to be called after reloading
|
||||||
|
/// E: the error type for the loading operation
|
||||||
|
pub fn maybe_watch_tls_config<T, O, F, E>(
|
||||||
|
tls_config: Arc<ReloadableTlsConfig<T, O>>,
|
||||||
|
on_reload: F,
|
||||||
|
) -> Result<()>
|
||||||
|
where
|
||||||
|
T: Send + Sync + 'static,
|
||||||
|
O: TlsConfigLoader<T, Error = E> + Send + Sync + 'static,
|
||||||
|
E: std::error::Error + Send + Sync + 'static,
|
||||||
|
F: Fn() + Send + 'static,
|
||||||
|
{
|
||||||
|
if !tls_config.get_tls_option().watch_enabled() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let tls_config_for_watcher = tls_config.clone();
|
||||||
|
|
||||||
|
let (tx, rx) = channel::<notify::Result<notify::Event>>();
|
||||||
|
let mut watcher = notify::recommended_watcher(tx).context(FileWatchSnafu { path: "<none>" })?;
|
||||||
|
|
||||||
|
// Watch all paths returned by the TlsConfigLoader
|
||||||
|
for path in tls_config.get_tls_option().watch_paths() {
|
||||||
|
watcher
|
||||||
|
.watch(path, RecursiveMode::NonRecursive)
|
||||||
|
.with_context(|_| FileWatchSnafu {
|
||||||
|
path: path.display().to_string(),
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Spawning background task for watching TLS cert/key file changes");
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let _watcher = watcher;
|
||||||
|
loop {
|
||||||
|
match rx.recv() {
|
||||||
|
Ok(Ok(event)) => {
|
||||||
|
if let EventKind::Modify(_) | EventKind::Create(_) = event.kind {
|
||||||
|
info!("Detected TLS cert/key file change: {:?}", event);
|
||||||
|
if let Err(err) = tls_config_for_watcher.reload() {
|
||||||
|
error!("Failed to reload TLS config: {}", err);
|
||||||
|
} else {
|
||||||
|
info!("Reloaded TLS cert/key file successfully.");
|
||||||
|
on_reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Err(err)) => {
|
||||||
|
error!("Failed to watch TLS cert/key file: {}", err);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("TLS cert/key file watcher channel closed: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -13,14 +13,15 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use common_grpc::channel_manager::{
|
use common_grpc::channel_manager::{
|
||||||
ChannelConfig, ChannelManager, ClientTlsOption, load_tls_config,
|
ChannelConfig, ChannelManager, ClientTlsOption, load_client_tls_config,
|
||||||
|
maybe_watch_client_tls_config,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_mtls_config() {
|
async fn test_mtls_config() {
|
||||||
// test no config
|
// test no config
|
||||||
let config = ChannelConfig::new();
|
let config = ChannelConfig::new();
|
||||||
let re = load_tls_config(config.client_tls.as_ref());
|
let re = load_client_tls_config(config.client_tls.clone());
|
||||||
assert!(re.is_ok());
|
assert!(re.is_ok());
|
||||||
assert!(re.unwrap().is_none());
|
assert!(re.unwrap().is_none());
|
||||||
|
|
||||||
@@ -30,9 +31,10 @@ async fn test_mtls_config() {
|
|||||||
server_ca_cert_path: Some("tests/tls/wrong_ca.pem".to_string()),
|
server_ca_cert_path: Some("tests/tls/wrong_ca.pem".to_string()),
|
||||||
client_cert_path: Some("tests/tls/wrong_client.pem".to_string()),
|
client_cert_path: Some("tests/tls/wrong_client.pem".to_string()),
|
||||||
client_key_path: Some("tests/tls/wrong_client.key".to_string()),
|
client_key_path: Some("tests/tls/wrong_client.key".to_string()),
|
||||||
|
watch: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let re = load_tls_config(config.client_tls.as_ref());
|
let re = load_client_tls_config(config.client_tls.clone());
|
||||||
assert!(re.is_err());
|
assert!(re.is_err());
|
||||||
|
|
||||||
// test corrupted file content
|
// test corrupted file content
|
||||||
@@ -41,9 +43,10 @@ async fn test_mtls_config() {
|
|||||||
server_ca_cert_path: Some("tests/tls/ca.pem".to_string()),
|
server_ca_cert_path: Some("tests/tls/ca.pem".to_string()),
|
||||||
client_cert_path: Some("tests/tls/client.pem".to_string()),
|
client_cert_path: Some("tests/tls/client.pem".to_string()),
|
||||||
client_key_path: Some("tests/tls/corrupted".to_string()),
|
client_key_path: Some("tests/tls/corrupted".to_string()),
|
||||||
|
watch: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let tls_config = load_tls_config(config.client_tls.as_ref()).unwrap();
|
let tls_config = load_client_tls_config(config.client_tls.clone()).unwrap();
|
||||||
let re = ChannelManager::with_config(config, tls_config);
|
let re = ChannelManager::with_config(config, tls_config);
|
||||||
|
|
||||||
let re = re.get("127.0.0.1:0");
|
let re = re.get("127.0.0.1:0");
|
||||||
@@ -55,10 +58,112 @@ async fn test_mtls_config() {
|
|||||||
server_ca_cert_path: Some("tests/tls/ca.pem".to_string()),
|
server_ca_cert_path: Some("tests/tls/ca.pem".to_string()),
|
||||||
client_cert_path: Some("tests/tls/client.pem".to_string()),
|
client_cert_path: Some("tests/tls/client.pem".to_string()),
|
||||||
client_key_path: Some("tests/tls/client.key".to_string()),
|
client_key_path: Some("tests/tls/client.key".to_string()),
|
||||||
|
watch: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let tls_config = load_tls_config(config.client_tls.as_ref()).unwrap();
|
let tls_config = load_client_tls_config(config.client_tls.clone()).unwrap();
|
||||||
let re = ChannelManager::with_config(config, tls_config);
|
let re = ChannelManager::with_config(config, tls_config);
|
||||||
let re = re.get("127.0.0.1:0");
|
let re = re.get("127.0.0.1:0");
|
||||||
let _ = re.unwrap();
|
let _ = re.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_reloadable_client_tls_config() {
|
||||||
|
common_telemetry::init_default_ut_logging();
|
||||||
|
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let cert_path = dir.path().join("client.pem");
|
||||||
|
let key_path = dir.path().join("client.key");
|
||||||
|
|
||||||
|
std::fs::copy("tests/tls/client.pem", &cert_path).expect("failed to copy cert to tmpdir");
|
||||||
|
std::fs::copy("tests/tls/client.key", &key_path).expect("failed to copy key to tmpdir");
|
||||||
|
|
||||||
|
assert!(std::fs::exists(&cert_path).unwrap());
|
||||||
|
assert!(std::fs::exists(&key_path).unwrap());
|
||||||
|
|
||||||
|
let client_tls_option = ClientTlsOption {
|
||||||
|
enabled: true,
|
||||||
|
server_ca_cert_path: Some("tests/tls/ca.pem".to_string()),
|
||||||
|
client_cert_path: Some(
|
||||||
|
cert_path
|
||||||
|
.clone()
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.expect("failed to convert path to string"),
|
||||||
|
),
|
||||||
|
client_key_path: Some(
|
||||||
|
key_path
|
||||||
|
.clone()
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.expect("failed to convert path to string"),
|
||||||
|
),
|
||||||
|
watch: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let reloadable_config = load_client_tls_config(Some(client_tls_option))
|
||||||
|
.expect("failed to load tls config")
|
||||||
|
.expect("tls config should be present");
|
||||||
|
|
||||||
|
let config = ChannelConfig::new();
|
||||||
|
let manager = ChannelManager::with_config(config, Some(reloadable_config.clone()));
|
||||||
|
|
||||||
|
maybe_watch_client_tls_config(reloadable_config.clone(), manager.clone())
|
||||||
|
.expect("failed to watch client config");
|
||||||
|
|
||||||
|
assert_eq!(0, reloadable_config.get_version());
|
||||||
|
assert!(reloadable_config.get_config().is_some());
|
||||||
|
|
||||||
|
// Create a channel to verify it gets cleared on reload
|
||||||
|
let _ = manager.get("127.0.0.1:0").expect("failed to get channel");
|
||||||
|
|
||||||
|
// Simulate file change by copying a different key file
|
||||||
|
let tmp_file = key_path.with_extension("tmp");
|
||||||
|
std::fs::copy("tests/tls/server.key", &tmp_file).expect("Failed to copy temp key file");
|
||||||
|
std::fs::rename(&tmp_file, &key_path).expect("Failed to rename temp key file");
|
||||||
|
|
||||||
|
const MAX_RETRIES: usize = 30;
|
||||||
|
let mut retries = 0;
|
||||||
|
let mut version_updated = false;
|
||||||
|
|
||||||
|
while retries < MAX_RETRIES {
|
||||||
|
if reloadable_config.get_version() > 0 {
|
||||||
|
version_updated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
retries += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(version_updated, "TLS config did not reload in time");
|
||||||
|
assert!(reloadable_config.get_version() > 0);
|
||||||
|
assert!(reloadable_config.get_config().is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_channel_manager_with_reloadable_tls() {
|
||||||
|
common_telemetry::init_default_ut_logging();
|
||||||
|
|
||||||
|
let client_tls_option = ClientTlsOption {
|
||||||
|
enabled: true,
|
||||||
|
server_ca_cert_path: Some("tests/tls/ca.pem".to_string()),
|
||||||
|
client_cert_path: Some("tests/tls/client.pem".to_string()),
|
||||||
|
client_key_path: Some("tests/tls/client.key".to_string()),
|
||||||
|
watch: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let reloadable_config = load_client_tls_config(Some(client_tls_option))
|
||||||
|
.expect("failed to load tls config")
|
||||||
|
.expect("tls config should be present");
|
||||||
|
|
||||||
|
let config = ChannelConfig::new();
|
||||||
|
let manager = ChannelManager::with_config(config, Some(reloadable_config.clone()));
|
||||||
|
|
||||||
|
// Test that we can get a channel
|
||||||
|
let channel = manager.get("127.0.0.1:0");
|
||||||
|
assert!(channel.is_ok());
|
||||||
|
|
||||||
|
// Test that config is properly set
|
||||||
|
assert_eq!(0, reloadable_config.get_version());
|
||||||
|
assert!(reloadable_config.get_config().is_some());
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,8 +12,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use greptime_proto::v1::ColumnDataTypeExtension;
|
||||||
use greptime_proto::v1::column_data_type_extension::TypeExt;
|
use greptime_proto::v1::column_data_type_extension::TypeExt;
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
use syn::{DeriveInput, Result};
|
use syn::{DeriveInput, Result};
|
||||||
@@ -69,57 +70,7 @@ fn impl_schema_method(fields: &[ParsedField<'_>]) -> Result<TokenStream2> {
|
|||||||
let semantic_type_val = convert_semantic_type_to_proto_semantic_type(column_attribute.semantic_type) as i32;
|
let semantic_type_val = convert_semantic_type_to_proto_semantic_type(column_attribute.semantic_type) as i32;
|
||||||
let semantic_type = syn::LitInt::new(&semantic_type_val.to_string(), ident.span());
|
let semantic_type = syn::LitInt::new(&semantic_type_val.to_string(), ident.span());
|
||||||
let extension = match extension {
|
let extension = match extension {
|
||||||
Some(ext) => {
|
Some(ext) => column_data_type_extension_to_tokens(&ext, ident.span()),
|
||||||
match ext.type_ext {
|
|
||||||
Some(TypeExt::DecimalType(ext)) => {
|
|
||||||
let precision = syn::LitInt::new(&ext.precision.to_string(), ident.span());
|
|
||||||
let scale = syn::LitInt::new(&ext.scale.to_string(), ident.span());
|
|
||||||
quote! {
|
|
||||||
Some(ColumnDataTypeExtension { type_ext: Some(TypeExt::DecimalType(DecimalTypeExtension { precision: #precision, scale: #scale })) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(TypeExt::JsonType(ext)) => {
|
|
||||||
let json_type = syn::LitInt::new(&ext.to_string(), ident.span());
|
|
||||||
quote! {
|
|
||||||
Some(ColumnDataTypeExtension { type_ext: Some(TypeExt::JsonType(#json_type)) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(TypeExt::VectorType(ext)) => {
|
|
||||||
let dim = syn::LitInt::new(&ext.dim.to_string(), ident.span());
|
|
||||||
quote! {
|
|
||||||
Some(ColumnDataTypeExtension { type_ext: Some(TypeExt::VectorType(VectorTypeExtension { dim: #dim })) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO(sunng87): revisit all these implementations
|
|
||||||
Some(TypeExt::ListType(ext)) => {
|
|
||||||
let item_type = syn::Ident::new(&ext.datatype.to_string(), ident.span());
|
|
||||||
quote! {
|
|
||||||
Some(ColumnDataTypeExtension { type_ext: Some(TypeExt::ListType(ListTypeExtension { item_type: #item_type })) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(TypeExt::StructType(ext)) => {
|
|
||||||
let fields = ext.fields.iter().map(|field| {
|
|
||||||
let field_name = syn::Ident::new(&field.name.clone(), ident.span());
|
|
||||||
let field_type = syn::Ident::new(&field.datatype.to_string(), ident.span());
|
|
||||||
quote! {
|
|
||||||
StructField { name: #field_name, type_: #field_type }
|
|
||||||
}
|
|
||||||
}).collect::<Vec<_>>();
|
|
||||||
quote! {
|
|
||||||
Some(ColumnDataTypeExtension { type_ext: Some(TypeExt::StructType(StructTypeExtension { fields: [#(#fields),*] })) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(TypeExt::JsonNativeType(ext)) => {
|
|
||||||
let inner = syn::Ident::new(&ext.datatype.to_string(), ident.span());
|
|
||||||
quote! {
|
|
||||||
Some(ColumnDataTypeExtension { type_ext: Some(TypeExt::JsonNativeType(JsonNativeTypeExtension { datatype: #inner })) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
quote! { None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => quote! { None },
|
None => quote! { None },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -141,3 +92,125 @@ fn impl_schema_method(fields: &[ParsedField<'_>]) -> Result<TokenStream2> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn column_data_type_extension_to_tokens(
|
||||||
|
extension: &ColumnDataTypeExtension,
|
||||||
|
span: Span,
|
||||||
|
) -> TokenStream2 {
|
||||||
|
match extension.type_ext.as_ref() {
|
||||||
|
Some(TypeExt::DecimalType(ext)) => {
|
||||||
|
let precision = syn::LitInt::new(&ext.precision.to_string(), span);
|
||||||
|
let scale = syn::LitInt::new(&ext.scale.to_string(), span);
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::DecimalType(DecimalTypeExtension {
|
||||||
|
precision: #precision,
|
||||||
|
scale: #scale,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(TypeExt::JsonType(ext)) => {
|
||||||
|
let json_type = syn::LitInt::new(&ext.to_string(), span);
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::JsonType(#json_type)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(TypeExt::VectorType(ext)) => {
|
||||||
|
let dim = syn::LitInt::new(&ext.dim.to_string(), span);
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::VectorType(VectorTypeExtension { dim: #dim })),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(TypeExt::ListType(ext)) => {
|
||||||
|
let datatype = syn::LitInt::new(&ext.datatype.to_string(), span);
|
||||||
|
let datatype_extension = ext
|
||||||
|
.datatype_extension
|
||||||
|
.as_deref()
|
||||||
|
.map(|ext| column_data_type_extension_to_tokens(ext, span))
|
||||||
|
.unwrap_or_else(|| quote! { None });
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::ListType(Box::new(ListTypeExtension {
|
||||||
|
datatype: #datatype,
|
||||||
|
datatype_extension: #datatype_extension,
|
||||||
|
}))),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(TypeExt::StructType(ext)) => {
|
||||||
|
let fields = ext.fields.iter().map(|field| {
|
||||||
|
let field_name = &field.name;
|
||||||
|
let datatype = syn::LitInt::new(&field.datatype.to_string(), span);
|
||||||
|
let datatype_extension = field
|
||||||
|
.datatype_extension
|
||||||
|
.as_ref()
|
||||||
|
.map(|ext| column_data_type_extension_to_tokens(ext, span))
|
||||||
|
.unwrap_or_else(|| quote! { None });
|
||||||
|
quote! {
|
||||||
|
greptime_proto::v1::StructField {
|
||||||
|
name: #field_name.to_string(),
|
||||||
|
datatype: #datatype,
|
||||||
|
datatype_extension: #datatype_extension,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::StructType(StructTypeExtension {
|
||||||
|
fields: vec![#(#fields),*],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(TypeExt::JsonNativeType(ext)) => {
|
||||||
|
let inner = syn::LitInt::new(&ext.datatype.to_string(), span);
|
||||||
|
let datatype_extension = ext
|
||||||
|
.datatype_extension
|
||||||
|
.as_deref()
|
||||||
|
.map(|ext| column_data_type_extension_to_tokens(ext, span))
|
||||||
|
.unwrap_or_else(|| quote! { None });
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::JsonNativeType(Box::new(
|
||||||
|
JsonNativeTypeExtension {
|
||||||
|
datatype: #inner,
|
||||||
|
datatype_extension: #datatype_extension,
|
||||||
|
},
|
||||||
|
))),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(TypeExt::DictionaryType(ext)) => {
|
||||||
|
let key_datatype = syn::LitInt::new(&ext.key_datatype.to_string(), span);
|
||||||
|
let value_datatype = syn::LitInt::new(&ext.value_datatype.to_string(), span);
|
||||||
|
let key_datatype_extension = ext
|
||||||
|
.key_datatype_extension
|
||||||
|
.as_deref()
|
||||||
|
.map(|ext| column_data_type_extension_to_tokens(ext, span))
|
||||||
|
.unwrap_or_else(|| quote! { None });
|
||||||
|
let value_datatype_extension = ext
|
||||||
|
.value_datatype_extension
|
||||||
|
.as_deref()
|
||||||
|
.map(|ext| column_data_type_extension_to_tokens(ext, span))
|
||||||
|
.unwrap_or_else(|| quote! { None });
|
||||||
|
quote! {
|
||||||
|
Some(ColumnDataTypeExtension {
|
||||||
|
type_ext: Some(TypeExt::DictionaryType(Box::new(
|
||||||
|
DictionaryTypeExtension {
|
||||||
|
key_datatype: #key_datatype,
|
||||||
|
key_datatype_extension: #key_datatype_extension,
|
||||||
|
value_datatype: #value_datatype,
|
||||||
|
value_datatype_extension: #value_datatype_extension,
|
||||||
|
},
|
||||||
|
))),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => quote! { None },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -309,5 +309,8 @@ pub(crate) fn convert_column_data_type_to_value_data_ident(
|
|||||||
ColumnDataType::Vector => format_ident!("VectorValue"),
|
ColumnDataType::Vector => format_ident!("VectorValue"),
|
||||||
ColumnDataType::List => format_ident!("ListValue"),
|
ColumnDataType::List => format_ident!("ListValue"),
|
||||||
ColumnDataType::Struct => format_ident!("StructValue"),
|
ColumnDataType::Struct => format_ident!("StructValue"),
|
||||||
|
ColumnDataType::Dictionary => {
|
||||||
|
panic!("Dictionary data type is not supported in row macros yet")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ pub enum RegionManifestInfo {
|
|||||||
Mito {
|
Mito {
|
||||||
manifest_version: u64,
|
manifest_version: u64,
|
||||||
flushed_entry_id: u64,
|
flushed_entry_id: u64,
|
||||||
|
/// Number of files removed in the manifest's `removed_files` field.
|
||||||
|
file_removed_cnt: u64,
|
||||||
},
|
},
|
||||||
Metric {
|
Metric {
|
||||||
data_manifest_version: u64,
|
data_manifest_version: u64,
|
||||||
@@ -271,9 +273,11 @@ impl From<store_api::region_engine::RegionManifestInfo> for RegionManifestInfo {
|
|||||||
store_api::region_engine::RegionManifestInfo::Mito {
|
store_api::region_engine::RegionManifestInfo::Mito {
|
||||||
manifest_version,
|
manifest_version,
|
||||||
flushed_entry_id,
|
flushed_entry_id,
|
||||||
|
file_removed_cnt,
|
||||||
} => RegionManifestInfo::Mito {
|
} => RegionManifestInfo::Mito {
|
||||||
manifest_version,
|
manifest_version,
|
||||||
flushed_entry_id,
|
flushed_entry_id,
|
||||||
|
file_removed_cnt,
|
||||||
},
|
},
|
||||||
store_api::region_engine::RegionManifestInfo::Metric {
|
store_api::region_engine::RegionManifestInfo::Metric {
|
||||||
data_manifest_version,
|
data_manifest_version,
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ fn build_new_schema_value(
|
|||||||
SetDatabaseOption::Ttl(ttl) => {
|
SetDatabaseOption::Ttl(ttl) => {
|
||||||
value.ttl = Some(*ttl);
|
value.ttl = Some(*ttl);
|
||||||
}
|
}
|
||||||
|
SetDatabaseOption::Other(key, val) => {
|
||||||
|
value.extra_options.insert(key.clone(), val.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +57,9 @@ fn build_new_schema_value(
|
|||||||
for key in keys.0.iter() {
|
for key in keys.0.iter() {
|
||||||
match key {
|
match key {
|
||||||
UnsetDatabaseOption::Ttl => value.ttl = None,
|
UnsetDatabaseOption::Ttl => value.ttl = None,
|
||||||
|
UnsetDatabaseOption::Other(key) => {
|
||||||
|
value.extra_options.remove(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,4 +240,41 @@ mod tests {
|
|||||||
build_new_schema_value(current_schema_value, &unset_ttl_alter_kind).unwrap();
|
build_new_schema_value(current_schema_value, &unset_ttl_alter_kind).unwrap();
|
||||||
assert_eq!(new_schema_value.ttl, None);
|
assert_eq!(new_schema_value.ttl, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_build_new_schema_value_with_compaction_options() {
|
||||||
|
let set_compaction = AlterDatabaseKind::SetDatabaseOptions(SetDatabaseOptions(vec![
|
||||||
|
SetDatabaseOption::Other("compaction.type".to_string(), "twcs".to_string()),
|
||||||
|
SetDatabaseOption::Other("compaction.twcs.time_window".to_string(), "1d".to_string()),
|
||||||
|
]));
|
||||||
|
|
||||||
|
let current_schema_value = SchemaNameValue::default();
|
||||||
|
let new_schema_value =
|
||||||
|
build_new_schema_value(current_schema_value.clone(), &set_compaction).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
new_schema_value.extra_options.get("compaction.type"),
|
||||||
|
Some(&"twcs".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
new_schema_value
|
||||||
|
.extra_options
|
||||||
|
.get("compaction.twcs.time_window"),
|
||||||
|
Some(&"1d".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
let unset_compaction = AlterDatabaseKind::UnsetDatabaseOptions(UnsetDatabaseOptions(vec![
|
||||||
|
UnsetDatabaseOption::Other("compaction.type".to_string()),
|
||||||
|
]));
|
||||||
|
|
||||||
|
let new_schema_value = build_new_schema_value(new_schema_value, &unset_compaction).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(new_schema_value.extra_options.get("compaction.type"), None);
|
||||||
|
assert_eq!(
|
||||||
|
new_schema_value
|
||||||
|
.extra_options
|
||||||
|
.get("compaction.twcs.time_window"),
|
||||||
|
Some(&"1d".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ fn alter_request_handler(_peer: Peer, request: RegionRequest) -> Result<RegionRe
|
|||||||
let region_id = RegionId::from(req.region_id);
|
let region_id = RegionId::from(req.region_id);
|
||||||
response.extensions.insert(
|
response.extensions.insert(
|
||||||
MANIFEST_INFO_EXTENSION_KEY.to_string(),
|
MANIFEST_INFO_EXTENSION_KEY.to_string(),
|
||||||
RegionManifestInfo::encode_list(&[(region_id, RegionManifestInfo::mito(1, 1))])
|
RegionManifestInfo::encode_list(&[(region_id, RegionManifestInfo::mito(1, 1, 0))])
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
response.extensions.insert(
|
response.extensions.insert(
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use common_error::ext::BoxedError;
|
||||||
use common_procedure::{
|
use common_procedure::{
|
||||||
BoxedProcedureLoader, Output, ProcedureId, ProcedureManagerRef, ProcedureWithId, watcher,
|
BoxedProcedureLoader, Output, ProcedureId, ProcedureManagerRef, ProcedureWithId, watcher,
|
||||||
};
|
};
|
||||||
@@ -66,6 +67,19 @@ use crate::rpc::ddl::{
|
|||||||
};
|
};
|
||||||
use crate::rpc::router::RegionRoute;
|
use crate::rpc::router::RegionRoute;
|
||||||
|
|
||||||
|
/// A configurator that customizes or enhances a [`DdlManager`].
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait DdlManagerConfigurator<C>: Send + Sync {
|
||||||
|
/// Configures the given [`DdlManager`] using the provided [`DdlManagerConfigureContext`].
|
||||||
|
async fn configure(
|
||||||
|
&self,
|
||||||
|
ddl_manager: DdlManager,
|
||||||
|
ctx: C,
|
||||||
|
) -> std::result::Result<DdlManager, BoxedError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DdlManagerConfiguratorRef<C> = Arc<dyn DdlManagerConfigurator<C>>;
|
||||||
|
|
||||||
pub type DdlManagerRef = Arc<DdlManager>;
|
pub type DdlManagerRef = Arc<DdlManager>;
|
||||||
|
|
||||||
pub type BoxedProcedureLoaderFactory = dyn Fn(DdlContext) -> BoxedProcedureLoader;
|
pub type BoxedProcedureLoaderFactory = dyn Fn(DdlContext) -> BoxedProcedureLoader;
|
||||||
@@ -148,11 +162,8 @@ impl DdlManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "enterprise")]
|
#[cfg(feature = "enterprise")]
|
||||||
pub fn with_trigger_ddl_manager(
|
pub fn with_trigger_ddl_manager(mut self, trigger_ddl_manager: TriggerDdlManagerRef) -> Self {
|
||||||
mut self,
|
self.trigger_ddl_manager = Some(trigger_ddl_manager);
|
||||||
trigger_ddl_manager: Option<TriggerDdlManagerRef>,
|
|
||||||
) -> Self {
|
|
||||||
self.trigger_ddl_manager = trigger_ddl_manager;
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -339,6 +339,16 @@ pub struct FlushRegions {
|
|||||||
pub error_strategy: FlushErrorStrategy,
|
pub error_strategy: FlushErrorStrategy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for FlushRegions {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"FlushRegions(region_ids={:?}, strategy={:?}, error_strategy={:?})",
|
||||||
|
self.region_ids, self.strategy, self.error_strategy
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FlushRegions {
|
impl FlushRegions {
|
||||||
/// Create synchronous single-region flush
|
/// Create synchronous single-region flush
|
||||||
pub fn sync_single(region_id: RegionId) -> Self {
|
pub fn sync_single(region_id: RegionId) -> Self {
|
||||||
@@ -420,20 +430,25 @@ where
|
|||||||
/// Instruction to get file references for specified regions.
|
/// Instruction to get file references for specified regions.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct GetFileRefs {
|
pub struct GetFileRefs {
|
||||||
/// List of region IDs to get file references for.
|
/// List of region IDs to get file references from active FileHandles (in-memory).
|
||||||
pub region_ids: Vec<RegionId>,
|
pub query_regions: Vec<RegionId>,
|
||||||
|
/// Mapping from the source region ID (where to read the manifest) to
|
||||||
|
/// the target region IDs (whose file references to look for).
|
||||||
|
/// Key: The region ID of the manifest.
|
||||||
|
/// Value: The list of region IDs to find references for in that manifest.
|
||||||
|
pub related_regions: HashMap<RegionId, Vec<RegionId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for GetFileRefs {
|
impl Display for GetFileRefs {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "GetFileRefs(region_ids={:?})", self.region_ids)
|
write!(f, "GetFileRefs(region_ids={:?})", self.query_regions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instruction to trigger garbage collection for a region.
|
/// Instruction to trigger garbage collection for a region.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct GcRegions {
|
pub struct GcRegions {
|
||||||
/// The region ID to perform GC on.
|
/// The region ID to perform GC on, only regions that are currently on the given datanode can be garbage collected, regions not on the datanode will report errors.
|
||||||
pub regions: Vec<RegionId>,
|
pub regions: Vec<RegionId>,
|
||||||
/// The file references manifest containing temporary file references.
|
/// The file references manifest containing temporary file references.
|
||||||
pub file_refs_manifest: FileRefsManifest,
|
pub file_refs_manifest: FileRefsManifest,
|
||||||
|
|||||||
@@ -164,6 +164,25 @@ impl DatanodeTableManager {
|
|||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn batch_get(
|
||||||
|
&self,
|
||||||
|
keys: &[DatanodeTableKey],
|
||||||
|
) -> Result<HashMap<DatanodeTableKey, DatanodeTableValue>> {
|
||||||
|
let req = BatchGetRequest::default().with_keys(keys.iter().map(|k| k.to_bytes()).collect());
|
||||||
|
let resp = self.kv_backend.batch_get(req).await?;
|
||||||
|
let values = resp
|
||||||
|
.kvs
|
||||||
|
.into_iter()
|
||||||
|
.map(|kv| {
|
||||||
|
Ok((
|
||||||
|
DatanodeTableKey::from_bytes(&kv.key)?,
|
||||||
|
DatanodeTableValue::try_from_raw_value(&kv.value)?,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect::<Result<HashMap<_, _>>>()?;
|
||||||
|
Ok(values)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn tables(
|
pub fn tables(
|
||||||
&self,
|
&self,
|
||||||
datanode_id: DatanodeId,
|
datanode_id: DatanodeId,
|
||||||
|
|||||||
@@ -661,13 +661,32 @@ impl TableRouteStorage {
|
|||||||
|
|
||||||
/// Returns batch of [`TableRouteValue`] that respects the order of `table_ids`.
|
/// Returns batch of [`TableRouteValue`] that respects the order of `table_ids`.
|
||||||
pub async fn batch_get(&self, table_ids: &[TableId]) -> Result<Vec<Option<TableRouteValue>>> {
|
pub async fn batch_get(&self, table_ids: &[TableId]) -> Result<Vec<Option<TableRouteValue>>> {
|
||||||
let mut table_routes = self.batch_get_inner(table_ids).await?;
|
let raw_table_routes = self.batch_get_inner(table_ids).await?;
|
||||||
self.remap_routes_addresses(&mut table_routes).await?;
|
|
||||||
|
|
||||||
Ok(table_routes)
|
Ok(raw_table_routes
|
||||||
|
.into_iter()
|
||||||
|
.map(|v| v.map(|x| x.inner))
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn batch_get_inner(&self, table_ids: &[TableId]) -> Result<Vec<Option<TableRouteValue>>> {
|
/// Returns batch of [`TableRouteValue`] wrapped with [`DeserializedValueWithBytes`].
|
||||||
|
///
|
||||||
|
/// The return value is a vector of [`Option<DeserializedValueWithBytes<TableRouteValue>>`].
|
||||||
|
/// Note: This method remaps the addresses of the table routes, but does not update their raw byte representations.
|
||||||
|
pub async fn batch_get_with_raw_bytes(
|
||||||
|
&self,
|
||||||
|
table_ids: &[TableId],
|
||||||
|
) -> Result<Vec<Option<DeserializedValueWithBytes<TableRouteValue>>>> {
|
||||||
|
let mut raw_table_routes = self.batch_get_inner(table_ids).await?;
|
||||||
|
self.remap_routes_addresses(&mut raw_table_routes).await?;
|
||||||
|
|
||||||
|
Ok(raw_table_routes)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn batch_get_inner(
|
||||||
|
&self,
|
||||||
|
table_ids: &[TableId],
|
||||||
|
) -> Result<Vec<Option<DeserializedValueWithBytes<TableRouteValue>>>> {
|
||||||
let keys = table_ids
|
let keys = table_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|id| TableRouteKey::new(*id).to_bytes())
|
.map(|id| TableRouteKey::new(*id).to_bytes())
|
||||||
@@ -685,7 +704,7 @@ impl TableRouteStorage {
|
|||||||
keys.into_iter()
|
keys.into_iter()
|
||||||
.map(|key| {
|
.map(|key| {
|
||||||
if let Some(value) = kvs.get(&key) {
|
if let Some(value) = kvs.get(&key) {
|
||||||
Ok(Some(TableRouteValue::try_from_raw_value(value)?))
|
Ok(Some(DeserializedValueWithBytes::from_inner_slice(value)?))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@@ -695,14 +714,14 @@ impl TableRouteStorage {
|
|||||||
|
|
||||||
async fn remap_routes_addresses(
|
async fn remap_routes_addresses(
|
||||||
&self,
|
&self,
|
||||||
table_routes: &mut [Option<TableRouteValue>],
|
table_routes: &mut [Option<DeserializedValueWithBytes<TableRouteValue>>],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let keys = table_routes
|
let keys = table_routes
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|table_route| {
|
.flat_map(|table_route| {
|
||||||
table_route
|
table_route
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(extract_address_keys)
|
.map(|x| extract_address_keys(&x.inner))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
})
|
})
|
||||||
.collect::<HashSet<_>>()
|
.collect::<HashSet<_>>()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use crate::rpc::store::{
|
|||||||
|
|
||||||
// The TopicRegionKey is a key for the topic-region mapping in the kvbackend.
|
// The TopicRegionKey is a key for the topic-region mapping in the kvbackend.
|
||||||
// The layout of the key is `__topic_region/{topic_name}/{region_id}`.
|
// The layout of the key is `__topic_region/{topic_name}/{region_id}`.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct TopicRegionKey<'a> {
|
pub struct TopicRegionKey<'a> {
|
||||||
pub region_id: RegionId,
|
pub region_id: RegionId,
|
||||||
pub topic: &'a str,
|
pub topic: &'a str,
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ pub mod memory;
|
|||||||
#[cfg(any(feature = "mysql_kvbackend", feature = "pg_kvbackend"))]
|
#[cfg(any(feature = "mysql_kvbackend", feature = "pg_kvbackend"))]
|
||||||
pub mod rds;
|
pub mod rds;
|
||||||
pub mod test;
|
pub mod test;
|
||||||
|
#[cfg(any(test, feature = "testing"))]
|
||||||
|
pub mod test_util;
|
||||||
pub mod txn;
|
pub mod txn;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
pub type KvBackendRef<E = Error> = Arc<dyn KvBackend<Error = E> + Send + Sync>;
|
pub type KvBackendRef<E = Error> = Arc<dyn KvBackend<Error = E> + Send + Sync>;
|
||||||
|
|||||||
125
src/common/meta/src/kv_backend/test_util.rs
Normal file
125
src/common/meta/src/kv_backend/test_util.rs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
// Copyright 2023 Greptime Team
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use derive_builder::Builder;
|
||||||
|
|
||||||
|
use crate::error::Result;
|
||||||
|
use crate::kv_backend::txn::{Txn, TxnResponse};
|
||||||
|
use crate::kv_backend::{
|
||||||
|
BatchDeleteRequest, BatchDeleteResponse, BatchGetRequest, BatchGetResponse, BatchPutRequest,
|
||||||
|
BatchPutResponse, DeleteRangeRequest, DeleteRangeResponse, KvBackend, PutRequest, PutResponse,
|
||||||
|
RangeRequest, RangeResponse, TxnService,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub type MockFn<Req, Resp> = Arc<dyn Fn(Req) -> Result<Resp> + Send + Sync>;
|
||||||
|
|
||||||
|
/// A mock kv backend for testing.
|
||||||
|
#[derive(Builder)]
|
||||||
|
pub struct MockKvBackend {
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub range_fn: Option<MockFn<RangeRequest, RangeResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub put_fn: Option<MockFn<PutRequest, PutResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub batch_put_fn: Option<MockFn<BatchPutRequest, BatchPutResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub batch_get_fn: Option<MockFn<BatchGetRequest, BatchGetResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub delete_range_fn: Option<MockFn<DeleteRangeRequest, DeleteRangeResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub batch_delete_fn: Option<MockFn<BatchDeleteRequest, BatchDeleteResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub txn: Option<MockFn<Txn, TxnResponse>>,
|
||||||
|
#[builder(setter(strip_option), default)]
|
||||||
|
pub max_txn_ops: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl TxnService for MockKvBackend {
|
||||||
|
type Error = crate::error::Error;
|
||||||
|
|
||||||
|
async fn txn(&self, txn: Txn) -> Result<TxnResponse> {
|
||||||
|
if let Some(f) = &self.txn {
|
||||||
|
f(txn)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn max_txn_ops(&self) -> usize {
|
||||||
|
self.max_txn_ops.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl KvBackend for MockKvBackend {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"mock_kv_backend"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn range(&self, req: RangeRequest) -> Result<RangeResponse> {
|
||||||
|
if let Some(f) = &self.range_fn {
|
||||||
|
f(req)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn put(&self, req: PutRequest) -> Result<PutResponse> {
|
||||||
|
if let Some(f) = &self.put_fn {
|
||||||
|
f(req)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn batch_put(&self, req: BatchPutRequest) -> Result<BatchPutResponse> {
|
||||||
|
if let Some(f) = &self.batch_put_fn {
|
||||||
|
f(req)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn batch_get(&self, req: BatchGetRequest) -> Result<BatchGetResponse> {
|
||||||
|
if let Some(f) = &self.batch_get_fn {
|
||||||
|
f(req)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_range(&self, req: DeleteRangeRequest) -> Result<DeleteRangeResponse> {
|
||||||
|
if let Some(f) = &self.delete_range_fn {
|
||||||
|
f(req)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn batch_delete(&self, req: BatchDeleteRequest) -> Result<BatchDeleteResponse> {
|
||||||
|
if let Some(f) = &self.batch_delete_fn {
|
||||||
|
f(req)
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ impl LeaderRegionManifestInfo {
|
|||||||
RegionManifestInfo::Mito {
|
RegionManifestInfo::Mito {
|
||||||
manifest_version,
|
manifest_version,
|
||||||
flushed_entry_id,
|
flushed_entry_id,
|
||||||
|
file_removed_cnt: _,
|
||||||
} => LeaderRegionManifestInfo::Mito {
|
} => LeaderRegionManifestInfo::Mito {
|
||||||
manifest_version,
|
manifest_version,
|
||||||
flushed_entry_id,
|
flushed_entry_id,
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ use serde_with::{DefaultOnNull, serde_as};
|
|||||||
use session::context::{QueryContextBuilder, QueryContextRef};
|
use session::context::{QueryContextBuilder, QueryContextRef};
|
||||||
use snafu::{OptionExt, ResultExt};
|
use snafu::{OptionExt, ResultExt};
|
||||||
use table::metadata::{RawTableInfo, TableId};
|
use table::metadata::{RawTableInfo, TableId};
|
||||||
|
use table::requests::validate_database_option;
|
||||||
use table::table_name::TableName;
|
use table::table_name::TableName;
|
||||||
use table::table_reference::TableReference;
|
use table::table_reference::TableReference;
|
||||||
|
|
||||||
@@ -1059,14 +1060,21 @@ impl TryFrom<PbOption> for SetDatabaseOption {
|
|||||||
type Error = error::Error;
|
type Error = error::Error;
|
||||||
|
|
||||||
fn try_from(PbOption { key, value }: PbOption) -> Result<Self> {
|
fn try_from(PbOption { key, value }: PbOption) -> Result<Self> {
|
||||||
match key.to_ascii_lowercase().as_str() {
|
let key_lower = key.to_ascii_lowercase();
|
||||||
|
match key_lower.as_str() {
|
||||||
TTL_KEY => {
|
TTL_KEY => {
|
||||||
let ttl = DatabaseTimeToLive::from_humantime_or_str(&value)
|
let ttl = DatabaseTimeToLive::from_humantime_or_str(&value)
|
||||||
.map_err(|_| InvalidSetDatabaseOptionSnafu { key, value }.build())?;
|
.map_err(|_| InvalidSetDatabaseOptionSnafu { key, value }.build())?;
|
||||||
|
|
||||||
Ok(SetDatabaseOption::Ttl(ttl))
|
Ok(SetDatabaseOption::Ttl(ttl))
|
||||||
}
|
}
|
||||||
_ => InvalidSetDatabaseOptionSnafu { key, value }.fail(),
|
_ => {
|
||||||
|
if validate_database_option(&key_lower) {
|
||||||
|
Ok(SetDatabaseOption::Other(key_lower, value))
|
||||||
|
} else {
|
||||||
|
InvalidSetDatabaseOptionSnafu { key, value }.fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1074,20 +1082,29 @@ impl TryFrom<PbOption> for SetDatabaseOption {
|
|||||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||||
pub enum SetDatabaseOption {
|
pub enum SetDatabaseOption {
|
||||||
Ttl(DatabaseTimeToLive),
|
Ttl(DatabaseTimeToLive),
|
||||||
|
Other(String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||||
pub enum UnsetDatabaseOption {
|
pub enum UnsetDatabaseOption {
|
||||||
Ttl,
|
Ttl,
|
||||||
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&str> for UnsetDatabaseOption {
|
impl TryFrom<&str> for UnsetDatabaseOption {
|
||||||
type Error = error::Error;
|
type Error = error::Error;
|
||||||
|
|
||||||
fn try_from(key: &str) -> Result<Self> {
|
fn try_from(key: &str) -> Result<Self> {
|
||||||
match key.to_ascii_lowercase().as_str() {
|
let key_lower = key.to_ascii_lowercase();
|
||||||
|
match key_lower.as_str() {
|
||||||
TTL_KEY => Ok(UnsetDatabaseOption::Ttl),
|
TTL_KEY => Ok(UnsetDatabaseOption::Ttl),
|
||||||
_ => InvalidUnsetDatabaseOptionSnafu { key }.fail(),
|
_ => {
|
||||||
|
if validate_database_option(&key_lower) {
|
||||||
|
Ok(UnsetDatabaseOption::Other(key_lower))
|
||||||
|
} else {
|
||||||
|
InvalidUnsetDatabaseOptionSnafu { key }.fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,25 +92,96 @@ impl Event for ProcedureEvent {
|
|||||||
schema
|
schema
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extra_row(&self) -> Result<Row> {
|
fn extra_rows(&self) -> Result<Vec<Row>> {
|
||||||
let error_str = match &self.state {
|
let mut internal_event_extra_rows = self.internal_event.extra_rows()?;
|
||||||
ProcedureState::Failed { error } => format!("{:?}", error),
|
let mut rows = Vec::with_capacity(internal_event_extra_rows.len());
|
||||||
ProcedureState::PrepareRollback { error } => format!("{:?}", error),
|
for internal_event_extra_row in internal_event_extra_rows.iter_mut() {
|
||||||
ProcedureState::RollingBack { error } => format!("{:?}", error),
|
let error_str = match &self.state {
|
||||||
ProcedureState::Retrying { error } => format!("{:?}", error),
|
ProcedureState::Failed { error } => format!("{:?}", error),
|
||||||
ProcedureState::Poisoned { error, .. } => format!("{:?}", error),
|
ProcedureState::PrepareRollback { error } => format!("{:?}", error),
|
||||||
_ => "".to_string(),
|
ProcedureState::RollingBack { error } => format!("{:?}", error),
|
||||||
};
|
ProcedureState::Retrying { error } => format!("{:?}", error),
|
||||||
let mut row = vec![
|
ProcedureState::Poisoned { error, .. } => format!("{:?}", error),
|
||||||
ValueData::StringValue(self.procedure_id.to_string()).into(),
|
_ => "".to_string(),
|
||||||
ValueData::StringValue(self.state.as_str_name().to_string()).into(),
|
};
|
||||||
ValueData::StringValue(error_str).into(),
|
let mut values = Vec::with_capacity(3 + internal_event_extra_row.values.len());
|
||||||
];
|
values.extend([
|
||||||
row.append(&mut self.internal_event.extra_row()?.values);
|
ValueData::StringValue(self.procedure_id.to_string()).into(),
|
||||||
Ok(Row { values: row })
|
ValueData::StringValue(self.state.as_str_name().to_string()).into(),
|
||||||
|
ValueData::StringValue(error_str).into(),
|
||||||
|
]);
|
||||||
|
values.append(&mut internal_event_extra_row.values);
|
||||||
|
rows.push(Row { values });
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
fn as_any(&self) -> &dyn Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use api::v1::value::ValueData;
|
||||||
|
use api::v1::{ColumnDataType, ColumnSchema, Row, SemanticType};
|
||||||
|
use common_event_recorder::Event;
|
||||||
|
|
||||||
|
use crate::{ProcedureEvent, ProcedureId, ProcedureState};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct TestEvent;
|
||||||
|
|
||||||
|
impl Event for TestEvent {
|
||||||
|
fn event_type(&self) -> &str {
|
||||||
|
"test_event"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extra_schema(&self) -> Vec<ColumnSchema> {
|
||||||
|
vec![ColumnSchema {
|
||||||
|
column_name: "test_event_column".to_string(),
|
||||||
|
datatype: ColumnDataType::String.into(),
|
||||||
|
semantic_type: SemanticType::Field.into(),
|
||||||
|
..Default::default()
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extra_rows(&self) -> common_event_recorder::error::Result<Vec<Row>> {
|
||||||
|
Ok(vec![
|
||||||
|
Row {
|
||||||
|
values: vec![ValueData::StringValue("test_event1".to_string()).into()],
|
||||||
|
},
|
||||||
|
Row {
|
||||||
|
values: vec![ValueData::StringValue("test_event2".to_string()).into()],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_procedure_event_extra_rows() {
|
||||||
|
let procedure_event = ProcedureEvent::new(
|
||||||
|
ProcedureId::random(),
|
||||||
|
Box::new(TestEvent {}),
|
||||||
|
ProcedureState::Running,
|
||||||
|
);
|
||||||
|
|
||||||
|
let procedure_event_extra_rows = procedure_event.extra_rows().unwrap();
|
||||||
|
assert_eq!(procedure_event_extra_rows.len(), 2);
|
||||||
|
assert_eq!(procedure_event_extra_rows[0].values.len(), 4);
|
||||||
|
assert_eq!(
|
||||||
|
procedure_event_extra_rows[0].values[3],
|
||||||
|
ValueData::StringValue("test_event1".to_string()).into()
|
||||||
|
);
|
||||||
|
assert_eq!(procedure_event_extra_rows[1].values.len(), 4);
|
||||||
|
assert_eq!(
|
||||||
|
procedure_event_extra_rows[1].values[3],
|
||||||
|
ValueData::StringValue("test_event2".to_string()).into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ pub enum Error {
|
|||||||
data_type: ArrowDatatype,
|
data_type: ArrowDatatype,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[snafu(display("Failed to downcast vector: {}", err_msg))]
|
|
||||||
DowncastVector { err_msg: String },
|
|
||||||
|
|
||||||
#[snafu(display("Invalid input type: {}", err_msg))]
|
#[snafu(display("Invalid input type: {}", err_msg))]
|
||||||
InvalidInputType {
|
InvalidInputType {
|
||||||
#[snafu(implicit)]
|
#[snafu(implicit)]
|
||||||
@@ -209,8 +206,7 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
impl ErrorExt for Error {
|
impl ErrorExt for Error {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match self {
|
match self {
|
||||||
Error::DowncastVector { .. }
|
Error::InvalidInputState { .. }
|
||||||
| Error::InvalidInputState { .. }
|
|
||||||
| Error::ToScalarValue { .. }
|
| Error::ToScalarValue { .. }
|
||||||
| Error::GetScalarVector { .. }
|
| Error::GetScalarVector { .. }
|
||||||
| Error::ArrowCompute { .. }
|
| Error::ArrowCompute { .. }
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user