You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/src/test/scala/org/apache/spark/sql/PartitionTableSuite.scala
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,18 @@ class PartitionTableSuite extends BasePlanTest {
33
33
super.afterAll()
34
34
}
35
35
36
+
test("reading from range column partition") {
37
+
tidbStmt.execute("drop table if exists range_column_test")
38
+
tidbStmt.execute(
39
+
"create table range_column_test (id varchar(10)) partition by RANGE COLUMNS(`id`) (PARTITION `p1` VALUES LESS THAN ('''CN001'''),PARTITION `p2` VALUES LESS THAN ('CN002'))")
40
+
tidbStmt.execute("insert into `range_column_test` values('CN001')")
41
+
tidbStmt.execute("insert into `range_column_test` values('''CN001''')")
42
+
43
+
judge("select * from range_column_test where id = 'CN001'")
44
+
judge("select * from range_column_test where id = '\\'CN001\\''")
45
+
judge("select * from range_column_test where id = 'CN002'")
TiSpark supports reads the range, hash and list partition table from TiDB.
6
+
7
+
TiSpark doesn't support a MySQL/TiDB partition table syntax `select col_name from table_name partition(partition_name)`, but you can still use `where` condition to filter the partitions.
8
+
9
+
## Partition pruning in Reading
10
+
11
+
TiSpark decides whether to apply partition pruning according to the partition type and the partition expression associated with the table. If partition pruning is not applied, TiSpark's reading is equivalent to doing a table scan over all partitions.
12
+
13
+
TiSpark only supports partition pruning with the following partition expression in **range** partition:
14
+
15
+
+ column expression
16
+
+`YEAR(col)` and its type is datetime/string/date literal that can be parsed as datetime.
17
+
+`TO_DAYS(col)` and its type is datetime/string/date literal that can be parsed as datetime.
18
+
19
+
### Limitations
20
+
21
+
- TiSpark does not support partition pruning in hash and list partition.
22
+
- TiSpark can not apply partition pruning for some special characters in partition definition. For example, Partition definition with `""` can not be pruned. such as `partition p0 values less than ('"string"')`.
23
+
24
+
## Write into partition table
25
+
26
+
Currently, TiSpark only supports writing into the range and hash partition table under the following conditions:
27
+
+ the partition expression is column expression
28
+
+ the partition expression is `YEAR($argument)` where the argument is a column and its type is datetime or string literal
29
+
that can be parsed as datetime.
30
+
31
+
There are two ways to write into partition table:
32
+
1. Use datasource API to write into partition table which supports replace and append semantics.
33
+
2. Use delete statement with Spark SQL.
34
+
35
+
> [!NOTE]
36
+
> Because different character sets and collations have different sort orders, the character sets and
37
+
> collations in use may affect which partition of a table partitioned by RANGE COLUMNS a given row
38
+
> is stored in when using string columns as partitioning columns.
39
+
> For supported character sets and collations, see [Limitations](../README.md#limitations)
0 commit comments