Skip to content

Commit a477a5a

Browse files
committed
Merge branch 'multiple-catalogs/show-tables' of github.com:ClSlaid/databend into multiple-catalogs/show-tables
2 parents e37ff60 + 5afe6d9 commit a477a5a

File tree

43 files changed

+358
-127
lines changed

Some content is hidden

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

43 files changed

+358
-127
lines changed

.github/actions/artifact_upload/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ runs:
3939
name: ${{ inputs.profile }}-${{ inputs.sha }}-${{ inputs.target }}-${{ inputs.category }}
4040
path: ./target/${{ inputs.target }}/${{ inputs.profile }}/databend-*
4141

42+
- name: Upload open-sharing to github
43+
if: steps.info.outputs.src == 'github'
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: ${{ inputs.profile }}-${{ inputs.sha }}-${{ inputs.target }}-${{ inputs.category }}
47+
path: ./target/${{ inputs.target }}/${{ inputs.profile }}/open-sharing
48+
4249
- name: Upload artifacts to s3
4350
if: steps.info.outputs.src == 's3'
4451
shell: bash

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/doc/14-sql-commands/10-dml/dml-copy-into-table.md

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,34 +160,78 @@ formatTypeOptions ::=
160160
RECORD_DELIMITER = '<character>'
161161
FIELD_DELIMITER = '<character>'
162162
SKIP_HEADER = <integer>
163+
QUOTE = '<character>'
164+
ESCAPE = '<character>'
165+
NAN_DISPLAY = '<string>'
166+
ROW_TAG = '<string>'
163167
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | XZ | NONE
164168
```
165169

166-
#### `RECORD_DELIMITER = '<character>'`
170+
#### `TYPE = 'CSV'`
167171

168-
Description: One character that separate records in an input file.
172+
Comma Separated Values format ([RFC](https://www.rfc-editor.org/rfc/rfc4180)).
169173

170-
Default: `'\n'`
174+
some notice:
171175

172-
#### `FIELD_DELIMITER = '<character>'`
176+
1. a string field contains `Quote`|`Escape`|`RECORD_DELIMITER`|`RECORD_DELIMITER` must be quoted.
177+
2. no character is escaped except `Quote` in quoted string.
178+
3. no space between `FIELD_DELIMITER` and `Quote`.
179+
4. no trailing `FIELD_DELIMITER` for a record.
180+
5. Array/Struct field is serialized to a string as in SQL, and then the resulting string is output to CSV in quotes.
181+
6. if you are generating CSV via programing, we highly recommend you to use the CSV lib of the programing language.
182+
7. for text file unloaded from [MySQL](https://dev.mysql.com/doc/refman/8.0/en/load-data.html), the default format is
183+
TSV in databend. it is valid CSV only if `ESCAPED BY` is empty and `ENCLOSED BY` is not empty.
173184

174-
Description: One character that separate fields in an input file.
185+
##### `RECORD_DELIMITER = '<character>'`
175186

176-
Default: `','` (comma)
187+
**Description**: One character that separate records in an input file.
188+
**Supported Values**: `\r\n` or One character including escaped char: `\b`, `\f`, `\r`, `\n`, `\t`, `\0`, `\xHH`
189+
**Default**: `\n`
177190

178-
#### `SKIP_HEADER = '<integer>'`
191+
##### `FIELD_DELIMITER = '<character>'`
179192

180-
Description: Number of lines at the start of the file to skip.
193+
**Description**: One character that separate fields in an input file.
194+
**Supported Values**: One character only, including escaped char: `\b`, `\f`, `\r`, `\n`, `\t`, `\0`, `\xHH`
195+
**Default**: `,` (comma)
181196

182-
Default: `0`
197+
##### `Quote = '<character>'`
183198

184-
#### `COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | XZ | NONE`
199+
**Description**: One character to quote strings in CSV file.
185200

186-
Description: String that represents the compression algorithm.
201+
for data loading, quote is not necessary unless a string contains `Quote`|`Escape`|`RECORD_DELIMITER`|`RECORD_DELIMITER`
187202

188-
Default: `NONE`
203+
**Supported Values**: `\'` or `\"`.
189204

190-
Values:
205+
**Default**: `\"`
206+
207+
##### `ESCAPE = '<character>'`
208+
209+
**Description**: One character to escape quote in quoted strings.
210+
211+
**Supported Values**: `\'` or `\"` or `\\`.
212+
213+
**Default**: `\"`
214+
215+
##### `SKIP_HEADER = '<integer>'`
216+
217+
**Use**: Data loading only.
218+
219+
**Description**: Number of lines at the start of the file to skip.
220+
221+
**Default**: `0`
222+
223+
##### `NAN_DISPLAY = '<string>'`
224+
225+
**Supported Values**: must be literal `'nan'` or `'null'` (case-insensitive)
226+
**Default**: `'NaN'`
227+
228+
##### `COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | XZ | NONE`
229+
230+
**Description**: String that represents the compression algorithm.
231+
232+
**Default**: `NONE`
233+
234+
**Supported Values**:
191235

192236
| Values | Notes |
193237
| ------------- | --------------------------------------------------------------- |
@@ -201,6 +245,55 @@ Values:
201245
| `XZ` | |
202246
| `NONE` | Indicates that the files have not been compressed. |
203247

248+
#### `TYPE = 'TSV'`
249+
250+
1. these characters are escaped: `\b`, `\f`, `\r`, `\n`, `\t`, `\0`, `\\`, `\'`, `RECORD_DELIMITER`,`FIELD_DELIMITER`.
251+
2. quoting/enclosing is not support now.
252+
3. Array/Struct field is serialized to a string as in SQL, and then the resulting string is output to CSV in quotes.
253+
4. Null is serialized as `\N`
254+
255+
##### `RECORD_DELIMITER = '<character>'`
256+
257+
**Description**: One character that separate records in an input file.
258+
259+
**Supported Values**: `\r\n` or One character including escaped char: `\b`, `\f`, `\r`, `\n`, `\t`, `\0`, `\xHH`
260+
261+
**Default**: `\n`
262+
263+
##### `FIELD_DELIMITER = '<character>'`
264+
265+
**Description**: One character that separate fields in an input file.
266+
267+
**Supported Values**: One character only, including escaped char: `\b`, `\f`, `\r`, `\n`, `\t`, `\0`, `\xHH`
268+
269+
**Default**: `\t` (TAB)
270+
271+
##### `COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | XZ | NONE`
272+
273+
same as `COMPRESSION` in `TYPE = 'CSV'`
274+
275+
#### `TYPE = 'NDJSON'`
276+
277+
##### `COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | XZ | NONE`
278+
279+
same as `COMPRESSION` in `TYPE = 'CSV'`
280+
281+
#### `TYPE = 'XML'`
282+
283+
##### `COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | XZ | NONE`
284+
285+
same as `COMPRESSION` in `TYPE = 'CSV'`
286+
287+
##### `ROW_TAG` = `<string>`
288+
289+
**Description**: used to select XML elements to be decoded as a record.
290+
291+
**Default**: `'row'`
292+
293+
#### `TYPE = 'Parquet'`
294+
295+
No options available now.
296+
204297
### copyOptions
205298

206299
```

src/common/base/src/base/singleton_instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl SingletonType {
5656
let guard = LOCAL.wait().read();
5757
let v: &T = guard
5858
.get(&thread_name)
59-
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated"))
59+
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated, don't worry if we are in dropping"))
6060
.get();
6161
v.clone()
6262
}
@@ -75,7 +75,7 @@ impl SingletonType {
7575
let guard = LOCAL.wait().read();
7676
guard
7777
.get(&thread_name)
78-
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated"))
78+
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated, don't worry if we are in dropping"))
7979
.set(value)
8080
}
8181
}

src/common/base/src/mem_allocator/mmap_allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ pub mod linux {
5151
#[inline(always)]
5252
fn mmap_alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
5353
debug_assert!(layout.align() <= page_size());
54+
ThreadTracker::alloc(layout.size() as i64);
5455
const PROT: i32 = libc::PROT_READ | libc::PROT_WRITE;
5556
const FLAGS: i32 = libc::MAP_PRIVATE | libc::MAP_ANONYMOUS | libc::MAP_POPULATE;
5657
let addr = unsafe { libc::mmap(null_mut(), layout.size(), PROT, FLAGS, -1, 0) };
5758
if addr == libc::MAP_FAILED {
5859
return Err(AllocError);
5960
}
6061
let addr = NonNull::new(addr as *mut ()).ok_or(AllocError)?;
61-
ThreadTracker::alloc(layout.size() as i64);
6262
Ok(NonNull::<[u8]>::from_raw_parts(addr, layout.size()))
6363
}
6464

src/common/storage/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ pub use operator::init_operator;
5555
pub use operator::CacheOperator;
5656
pub use operator::DataOperator;
5757

58-
mod location;
59-
pub use location::parse_uri_location;
60-
pub use location::UriLocation;
61-
6258
mod metrics;
6359
pub use metrics::StorageMetrics;
6460
pub use metrics::StorageMetricsLayer;

src/query/ast/src/ast/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use std::fmt::Formatter;
1818
use crate::ast::write_comma_separated_list;
1919
use crate::ast::write_period_separated_list;
2020
use crate::ast::Expr;
21+
use crate::ast::FileLocation;
2122
use crate::ast::Identifier;
22-
use crate::ast::StageLocation;
2323
use crate::parser::token::Token;
2424

2525
/// Root node of a query tree
@@ -178,7 +178,7 @@ pub enum TableReference<'a> {
178178
},
179179
Stage {
180180
span: &'a [Token<'a>],
181-
location: StageLocation,
181+
location: FileLocation,
182182
files: Vec<String>,
183183
alias: Option<TableAlias<'a>>,
184184
},

src/query/ast/src/ast/statements/copy.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,25 @@ impl Display for StageLocation {
213213
}
214214
}
215215

216+
#[derive(Debug, Clone, PartialEq, Eq)]
217+
pub enum FileLocation {
218+
Stage(StageLocation),
219+
Uri(UriLocation),
220+
}
221+
222+
impl Display for FileLocation {
223+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
224+
match self {
225+
FileLocation::Uri(loc) => {
226+
write!(f, "{}", loc)
227+
}
228+
FileLocation::Stage(loc) => {
229+
write!(f, "{}", loc)
230+
}
231+
}
232+
}
233+
}
234+
216235
pub enum CopyOption {
217236
Files(Vec<String>),
218237
Pattern(String),

src/query/ast/src/parser/query.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use pratt::PrattParser;
2222
use pratt::Precedence;
2323

2424
use super::stage::stage_location;
25+
use super::stage::uri_location;
2526
use crate::ast::*;
2627
use crate::input::Input;
2728
use crate::input::WithSpan;
@@ -259,7 +260,7 @@ pub enum TableReferenceElement<'a> {
259260
JoinCondition(JoinCondition<'a>),
260261
Group(TableReference<'a>),
261262
Stage {
262-
location: StageLocation,
263+
location: FileLocation,
263264
files: Vec<String>,
264265
alias: Option<TableAlias<'a>>,
265266
},
@@ -325,9 +326,27 @@ pub fn table_reference_element(i: Input) -> IResult<WithSpan<TableReferenceEleme
325326
|(_, table_ref, _)| TableReferenceElement::Group(table_ref),
326327
);
327328

329+
let stage_location = |i| {
330+
map_res(
331+
rule! {
332+
#stage_location
333+
},
334+
|v| Ok(FileLocation::Stage(v)),
335+
)(i)
336+
};
337+
338+
let uri_location = |i| {
339+
map_res(
340+
rule! {
341+
#uri_location
342+
},
343+
|v| Ok(FileLocation::Uri(v)),
344+
)(i)
345+
};
346+
328347
let aliased_stage = map(
329348
rule! {
330-
#stage_location ~ ( FILES ~ "=" ~ "(" ~ #comma_separated_list0(literal_string) ~ ")")? ~ #table_alias?
349+
(#stage_location | #uri_location) ~ ( FILES ~ "=" ~ "(" ~ #comma_separated_list0(literal_string) ~ ")")? ~ #table_alias?
331350
},
332351
|(location, files, alias)| TableReferenceElement::Stage {
333352
location,

src/query/service/src/api/rpc/exchange/exchange_manager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,9 @@ impl QueryCoordinator {
552552
}
553553
}
554554

555-
let executor_settings = ExecutorSettings::try_create(&info.query_ctx.get_settings())?;
555+
let query_id = info.query_ctx.get_id();
556+
let executor_settings =
557+
ExecutorSettings::try_create(&info.query_ctx.get_settings(), query_id)?;
556558

557559
let executor = PipelineCompleteExecutor::from_pipelines(pipelines, executor_settings)?;
558560

0 commit comments

Comments
 (0)