Skip to content

Commit 54d6041

Browse files
authored
Merge branch 'main' into weekly-72
2 parents 611b04d + 6f5006e commit 54d6041

File tree

32 files changed

+384
-144
lines changed

32 files changed

+384
-144
lines changed

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/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/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ pub struct StorageMokaConfig {
451451
}
452452

453453
impl Default for StorageMokaConfig {
454+
#[no_sanitize(address)]
454455
fn default() -> Self {
455456
Self {
456457
// Use 1G as default.

src/common/storage/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
//! - Table snapshots, segments cache must be stored accessed via cache operator.
2929
//! - Intermediate data generated by query could be stored by temporary operator.
3030
31+
#![feature(no_sanitize)]
32+
3133
mod config;
3234
pub use config::CacheConfig;
3335
pub use config::ShareTableConfig;

src/query/ast/src/ast/statements/table.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::ast::UriLocation;
3030

3131
#[derive(Debug, Clone, PartialEq)] // Tables
3232
pub struct ShowTablesStmt<'a> {
33+
pub catalog: Option<Identifier<'a>>,
3334
pub database: Option<Identifier<'a>>,
3435
pub full: bool,
3536
pub limit: Option<ShowLimit<'a>>,
@@ -47,7 +48,11 @@ impl Display for ShowTablesStmt<'_> {
4748
write!(f, " HISTORY")?;
4849
}
4950
if let Some(database) = &self.database {
50-
write!(f, " FROM {database}")?;
51+
write!(f, " FROM ")?;
52+
if let Some(catalog) = &self.catalog {
53+
write!(f, "{catalog}.",)?;
54+
}
55+
write!(f, "{database}")?;
5156
}
5257
if let Some(limit) = &self.limit {
5358
write!(f, " {limit}")?;

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,17 @@ pub fn statement(i: Input) -> IResult<StatementMsg> {
332332
);
333333
let show_tables = map(
334334
rule! {
335-
SHOW ~ FULL? ~ TABLES ~ HISTORY? ~ ( ( FROM | IN ) ~ ^#ident )? ~ #show_limit?
335+
SHOW ~ FULL? ~ TABLES ~ HISTORY? ~ ( ( FROM | IN ) ~ #peroid_separated_idents_1_to_2 )? ~ #show_limit?
336336
},
337-
|(_, opt_full, _, opt_history, opt_database, limit)| {
337+
|(_, opt_full, _, opt_history, ctl_db, limit)| {
338+
let (catalog, database) = match ctl_db {
339+
Some((_, (Some(c), d))) => (Some(c), Some(d)),
340+
Some((_, (None, d))) => (None, Some(d)),
341+
_ => (None, None),
342+
};
338343
Statement::ShowTables(ShowTablesStmt {
339-
database: opt_database.map(|(_, database)| database),
344+
catalog,
345+
database,
340346
full: opt_full.is_some(),
341347
limit,
342348
with_history: opt_history.is_some(),

src/query/ast/tests/it/parser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ fn test_statement() {
6767
r#"show databases format TabSeparatedWithNamesAndTypes;"#,
6868
r#"show tables"#,
6969
r#"show tables format TabSeparatedWithNamesAndTypes;"#,
70+
r#"show full tables"#,
71+
r#"show full tables from db"#,
72+
r#"show full tables from ctl.db"#,
7073
r#"show processlist;"#,
7174
r#"show create table a.b;"#,
7275
r#"show create table a.b format TabSeparatedWithNamesAndTypes;"#,

src/query/ast/tests/it/testdata/statement.txt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SHOW TABLES
3737
---------- AST ------------
3838
ShowTables(
3939
ShowTablesStmt {
40+
catalog: None,
4041
database: None,
4142
full: false,
4243
limit: None,
@@ -52,6 +53,7 @@ SHOW TABLES
5253
---------- AST ------------
5354
ShowTables(
5455
ShowTablesStmt {
56+
catalog: None,
5557
database: None,
5658
full: false,
5759
limit: None,
@@ -64,6 +66,72 @@ ShowTables(
6466
Some(
6567
"TabSeparatedWithNamesAndTypes",
6668
)
69+
---------- Input ----------
70+
show full tables
71+
---------- Output ---------
72+
SHOW FULL TABLES
73+
---------- AST ------------
74+
ShowTables(
75+
ShowTablesStmt {
76+
catalog: None,
77+
database: None,
78+
full: true,
79+
limit: None,
80+
with_history: false,
81+
},
82+
)
83+
84+
85+
---------- Input ----------
86+
show full tables from db
87+
---------- Output ---------
88+
SHOW FULL TABLES FROM db
89+
---------- AST ------------
90+
ShowTables(
91+
ShowTablesStmt {
92+
catalog: None,
93+
database: Some(
94+
Identifier {
95+
name: "db",
96+
quote: None,
97+
span: Ident(22..24),
98+
},
99+
),
100+
full: true,
101+
limit: None,
102+
with_history: false,
103+
},
104+
)
105+
106+
107+
---------- Input ----------
108+
show full tables from ctl.db
109+
---------- Output ---------
110+
SHOW FULL TABLES FROM ctl.db
111+
---------- AST ------------
112+
ShowTables(
113+
ShowTablesStmt {
114+
catalog: Some(
115+
Identifier {
116+
name: "ctl",
117+
quote: None,
118+
span: Ident(22..25),
119+
},
120+
),
121+
database: Some(
122+
Identifier {
123+
name: "db",
124+
quote: None,
125+
span: Ident(26..28),
126+
},
127+
),
128+
full: true,
129+
limit: None,
130+
with_history: false,
131+
},
132+
)
133+
134+
67135
---------- Input ----------
68136
show processlist;
69137
---------- Output ---------

src/query/config/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![feature(no_sanitize)]
16+
1517
/// Config mods provide config support.
1618
///
1719
/// We are providing two config types:

src/query/config/src/outer_v0.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl Config {
136136
/// with_args is to control whether we need to load from args or not.
137137
/// We should set this to false during tests because we don't want
138138
/// our test binary to parse cargo's args.
139+
#[no_sanitize(address)]
139140
pub fn load(with_args: bool) -> Result<Self> {
140141
let mut arg_conf = Self::default();
141142

0 commit comments

Comments
 (0)