Skip to content

Commit 4f6e4cf

Browse files
committed
resolve conflict: Merge remote-tracking branch 'origin/main' into fix-thread-leakings
2 parents 9efcbff + f35912a commit 4f6e4cf

File tree

73 files changed

+3064
-962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3064
-962
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
---
22
title: Arithmetic Operators
3-
title_includes: plus, minus, multiply, div, divide, mod, caret, modulo, negate, +, -, /, %, *, ^
3+
title_includes: plus, minus, multiply, div, divide, mod, caret, modulo, negate, +, -, /, %, *, ^, |/, ||/, @, &, |, #, ~, <<, >>
44
---
55

6-
| Operator | Description | Example | Result |
7-
|---------------|-------------------------------------------------------|-----------|--------|
8-
| **+ (unary)** | Returns `a` | **+5** | 5 |
9-
| **+** | Adds two numeric expressions | **4 + 1** | 5 |
10-
| **- (unary)** | Negates the numeric expression | **-5** | -5 |
11-
| **-** | Subtract two numeric expressions | **4 - 1** | 3 |
12-
| __*__ | Multiplies two numeric expressions | **4 * 1** | 4 |
13-
| **/** | Divides one numeric expression (`a`) by another (`b`) | **4 / 2** | 2 |
14-
| **%** | Computes the modulo of numeric expression | **4 % 2** | 0 |
15-
| **^** | Computes the exponentiation of numeric expression | **4 ^ 2** | 16 |
6+
| Operator | Description | Example | Result |
7+
|-----------------------|--------------------------------------------------------|----------------------------|--------|
8+
| **+ (unary)** | Returns `a` | **+5** | 5 |
9+
| **+** | Adds two numeric expressions | **4 + 1** | 5 |
10+
| **- (unary)** | Negates the numeric expression | **-5** | -5 |
11+
| **-** | Subtract two numeric expressions | **4 - 1** | 3 |
12+
| __*__ | Multiplies two numeric expressions | **4 * 1** | 4 |
13+
| **/** | Divides one numeric expression (`a`) by another (`b`) | **4 / 2** | 2 |
14+
| **%** | Computes the modulo of numeric expression | **4 % 2** | 0 |
15+
| **^** | Computes the exponentiation of numeric expression | **4 ^ 2** | 16 |
16+
| **&verbar;/** | Computes the square root of numeric expression | **&verbar;/ 25.0** | 5 |
17+
| **&verbar;&verbar;/** | Computes the cube root of numeric expression | **&verbar;&verbar;/ 27.0** | 3 |
18+
| **@** | Computes the abs of numeric expression | **@ -5.0** | 5 |
19+
| **&** | Computes the bitwise and of numeric expression | **91 & 15** | 11 |
20+
| **&verbar;** | Computes the bitwise or of numeric expression | **32 &verbar; 3** | 35 |
21+
| **#** | Computes the bitwise xor of numeric expression | **17 # 5** | 20 |
22+
| **~** | Computes the bitwise not of numeric expression | **~ 1** | ~2 |
23+
| **<<** | Computes the bitwise shift left of numeric expression | **1 << 4** | 16 |
24+
| **>>** | Computes the bitwise shift right of numeric expression | **8 >> 2** | 2 |

docs/doc/15-sql-functions/20-numeric-functions/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ The table below shows the available numeric functions.
3535
| **SIGN(x)** | Returns the sign of the argument as -1, 0, or 1, depending on whether x is negative, zero, or positive or NULL if the argument was NULL. | **SIGN(0)** | 0 |
3636
| **SIN(x)** | Returns the sine of x, where x is given in radians. | **SIN(90)** | 0.8939966636005579 |
3737
| **SQRT(x)** | Returns the square root of a nonnegative number x. Return Nan for negative input. | **SQRT(4)** | 2.0 |
38+
| **CBRT(x)** | Returns the cube root of a nonnegative number x. | **CURT(27)** | 3.0 |
3839
| **TAN(x)** | Returns the tangent of x, where x is given in radians. | **TAN(90)** | -1.995200412208242 |
39-
| **TRUNCATE(x, d)** | Returns the number x, truncated to d decimal places. If d is 0, the result has no decimal point or fractional part. d can be negative to cause d digits left of the decimal point of the value X to become zero. The maximum absolute value for d is 30; any digits in excess of 30 (or -30) are truncated. | **TRUNCATE(1.223, 1)** | 1.2 |
40+
| **TRUNCATE(x, d)** | Returns the number x, truncated to d decimal places. If d is 0, the result has no decimal point or fractional part. d can be negative to cause d digits left of the decimal point of the value X to become zero. The maximum absolute value for d is 30; any digits in excess of 30 (or -30) are truncated. | **TRUNCATE(1.223, 1)** | 1.2 |
41+
| **FACTORIAL(x)** | Returns the factorial logarithm of x. If x is less than or equal to 0, the function returns 0. | **FACTORIAL(5)** | 120 |
Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,105 @@
11
---
2-
title: Getting and Building Databend From Source
3-
sidebar_label: Building From Source
2+
title: Building Databend
3+
sidebar_label: Building Databend
44
description:
55
Getting and building Databend from Source
66
---
77

8-
:::note
9-
10-
Note that at least 16GB of RAM is required to build from source and run tests.
8+
As an open-source platform, Databend provides the flexibility for users to modify, distribute and enhance the software according to their specific needs. Additionally, users have the freedom to build Databend from the source code, allowing them to fully understand how the software works and potentially contribute to its development.
119

10+
:::tip
11+
Databend offers a Docker image that includes all the necessary tools for development, but it's currently only available for the amd64 architecture. To use it, ensure that Docker is installed and running, and then run `INTERACTIVE=true scripts/setup/run_build_tool.sh`. This will launch an environment for building and testing, and the `INTERACTIVE=true` flag enables interactive mode.
1212
:::
1313

14-
### Install prerequisites
14+
## Prerequisites
15+
16+
Before you build Databend, make sure the following requirements have been met:
17+
18+
- At least 16 GB of RAM will be required to build Databend from the source code.
19+
- You have installed the following required tools:
20+
- Git
21+
- cmake
22+
- [rustup](https://rustup.rs/)
23+
24+
## Building Databend
1525

16-
Databend is written in Rust, to build Databend from scratch you will need to install the following tools:
17-
* **Git, cmake**
18-
* **Rust** Install with [rustup](https://rustup.rs/)
26+
Follow the steps below to build Databend:
27+
28+
1. Download the source code.
29+
30+
```shell
31+
git clone https://github.com/datafuselabs/databend.git
32+
```
1933

20-
### Get the Databend code
34+
2. Install dependencies and compile the source code.
2135

2236
```shell
23-
git clone https://github.com/datafuselabs/databend
2437
cd databend
38+
make setup -d
39+
export PATH=$PATH:~/.cargo/bin
2540
```
26-
### Run make
41+
42+
3. Build Databend.
43+
44+
- To build Databend with debug information for debugging purposes, run `make build`. The resulting files will be located in the "target/debug/" directory.
45+
46+
```shell
47+
make build
48+
```
49+
- To build Databend for production, optimized for your local CPU, run `make build-release`. The resulting files will be located in the "target/release/" directory.
2750

2851
```shell
2952
make build-release
3053
```
3154

32-
`databend-query` and `databend-meta` will be placed in the `target/release` directory.
55+
## Start Databend for Debugging
56+
57+
```shell
58+
# 1. Start databend-meta first:
59+
nohup target/debug/databend-meta --single --log-level=ERROR &
60+
61+
# 2. Start databend-query and connect it to databend-meta:
62+
nohup target/debug/databend-query -c scripts/ci/deploy/config/databend-query-node-1.toml &
63+
```
64+
:::tip
65+
To stop databend-meta and databend-query, run the following commands:
66+
67+
```shell
68+
killall -9 databend-meta
69+
killall -9 databend-query
70+
```
71+
:::
72+
73+
## Common Errors
74+
75+
1. protoc failed: Unknown flag: --experimental_allow_proto3_optional\n
76+
77+
```bash
78+
--- stderr
79+
Error: Custom { kind: Other, error: "protoc failed: Unknown flag: --experimental_allow_proto3_optional\n" }
80+
warning: build failed, waiting for other jobs to finish...
81+
All done...
82+
# Reduce binary size by compressing binaries.
83+
objcopy --compress-debug-sections=zlib-gnu /home/aucker/mldb/databend/target/release/databend-query
84+
objcopy: '/home/aucker/mldb/databend/target/release/databend-query': No such file
85+
make: *** [Makefile:51: build-release] Error 1
86+
```
3387
88+
The error message indicates that there is an issue with building Databend due to an unknown flag (--experimental_allow_proto3_optional) being used with protoc, which is a protocol buffer compiler. This flag is only available in protoc version 3.12 or higher, and the current version being used does not support it.
89+
90+
The recommended solution is to upgrade to a version of protoc that supports that flag. You can do this by downloading the latest version of protoc from the official release page (https://github.com/protocolbuffers/protobuf/releases) and installing it on your system.
91+
92+
```bash
93+
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
94+
curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
95+
unzip protoc-3.15.8-linux-x86_64.zip
96+
$sudo cp bin/protoc /usr/bin/
97+
$protoc --version
98+
libprotoc 3.15.6
99+
```
34100
35-
### Build With Docker Image
101+
2. Coundn't connect to databend-meta in a forked Databend project.
36102
37-
We provide a docker image with full development requirements, currently only on amd64.
103+
This issue is likely caused by a version check implemented in Databend-meta that is not being met by the forked project.
38104
39-
Making sure docker is installed and running, just run `INTERACTIVE=true scripts/setup/run_build_tool.sh` to get into the build/test environment.
105+
One possible solution is to fetch the latest tags from the official Databend repository using the command `git fetch https://github.com/datafuselabs/databend.git --tags`. This should ensure that the project is using the latest version of Databend-meta and will pass the version check.

src/binaries/query/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub async fn query_local(conf: &InnerConfig) -> Result<()> {
4444
.await?;
4545
let ctx = session.create_query_context().await?;
4646
let mut planner = Planner::new(ctx.clone());
47-
let (plan, _, _) = planner.plan_sql(&sql).await?;
47+
let (plan, _) = planner.plan_sql(&sql).await?;
4848
let interpreter = InterpreterFactory::get(ctx.clone(), &plan).await?;
4949
let stream = interpreter.execute(ctx.clone()).await?;
5050
let blocks = stream.map(|v| v).collect::<Vec<_>>().await;

src/query/ast/benches/bench.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern crate criterion;
1818
use common_ast::parser::parse_expr;
1919
use common_ast::parser::parse_sql;
2020
use common_ast::parser::tokenize_sql;
21-
use common_ast::Backtrace;
2221
use common_ast::Dialect;
2322
use criterion::black_box;
2423
use criterion::Criterion;
@@ -31,35 +30,31 @@ fn bench(c: &mut Criterion) {
3130
b.iter(|| {
3231
let case = r#"explain SELECT SUM(count) FROM (SELECT ((((((((((((true)and(true)))or((('614')like('998831')))))or(false)))and((true IN (true, true, (-1014651046 NOT BETWEEN -1098711288 AND -1158262473))))))or((('780820706')=('')))) IS NOT NULL AND ((((((((((true)AND(true)))or((('614')like('998831')))))or(false)))and((true IN (true, true, (-1014651046 NOT BETWEEN -1098711288 AND -1158262473))))))OR((('780820706')=(''))))) ::INT64)as count FROM t0) as res;"#;
3332
let tokens = tokenize_sql(case).unwrap();
34-
let backtrace = Backtrace::new();
35-
let (stmt, _) = parse_sql(&tokens, Dialect::PostgreSQL, &backtrace).unwrap();
33+
let (stmt, _) = parse_sql(&tokens, Dialect::PostgreSQL).unwrap();
3634
black_box(stmt);
3735
})
3836
});
3937
group.bench_function("large_query", |b| {
4038
b.iter(|| {
4139
let case = r#"SELECT SUM(count) FROM (SELECT ((((((((((((true)and(true)))or((('614')like('998831')))))or(false)))and((true IN (true, true, (-1014651046 NOT BETWEEN -1098711288 AND -1158262473))))))or((('780820706')=('')))) IS NOT NULL AND ((((((((((true)AND(true)))or((('614')like('998831')))))or(false)))and((true IN (true, true, (-1014651046 NOT BETWEEN -1098711288 AND -1158262473))))))OR((('780820706')=(''))))) ::INT64)as count FROM t0) as res;"#;
4240
let tokens = tokenize_sql(case).unwrap();
43-
let backtrace = Backtrace::new();
44-
let (stmt, _) = parse_sql(&tokens, Dialect::PostgreSQL, &backtrace).unwrap();
41+
let (stmt, _) = parse_sql(&tokens, Dialect::PostgreSQL).unwrap();
4542
black_box(stmt);
4643
})
4744
});
4845
group.bench_function("wide_expr", |b| {
4946
b.iter(|| {
5047
let case = r#"a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a AND a"#;
5148
let tokens = tokenize_sql(case).unwrap();
52-
let backtrace = Backtrace::new();
53-
let expr = parse_expr(&tokens, Dialect::PostgreSQL, &backtrace).unwrap();
49+
let expr = parse_expr(&tokens, Dialect::PostgreSQL).unwrap();
5450
black_box(expr);
5551
})
5652
});
5753
group.bench_function("deep_expr", |b| {
5854
b.iter(|| {
5955
let case = r#"((((((((((((((((((((((((((((((1))))))))))))))))))))))))))))))"#;
6056
let tokens = tokenize_sql(case).unwrap();
61-
let backtrace = Backtrace::new();
62-
let expr = parse_expr(&tokens, Dialect::PostgreSQL, &backtrace).unwrap();
57+
let expr = parse_expr(&tokens, Dialect::PostgreSQL).unwrap();
6358
black_box(expr);
6459
})
6560
});

0 commit comments

Comments
 (0)