Skip to main content
VeloDB Cloud 26.x is based on Apache Doris 4.x. See Version Mapping.

Replace Data with Temporary Partitions

A temporary partition is a category of partition in a VeloDB Cloud partitioned table that is independent of formal partitions. It is not hit by regular queries and must be accessed explicitly through dedicated syntax. It is mainly used to perform atomic data switching and partition structure adjustments while keeping the formal partitions available until the switch. Coordinate concurrent loads before replacement so they do not write to partitions being retired.

Choose a temporary partition workflow​

ScenarioDescriptionKey Capability
Atomic overwriteRewrite the data of a partition without producing a "delete old data, then load new data" gap windowAtomic replacement via REPLACE PARTITION
Change bucket countThe current bucket count of an existing partition is suboptimal and needs to be adjustedSpecify a new bucket count on the temporary partition and then replace
Merge / split partitionsAdjust partition granularity by merging multiple partitions into one or splitting one large partition into manyRedistribute data with INSERT INTO and then replace

Tip:

For atomic overwrite of a non-partitioned table, refer to the Replace Table documentation.

Check temporary partition constraints​

A temporary partition shares the same table schema as a formal partition, but has the following independence:

  • The partition columns of a temporary partition are the same as those of formal partitions and cannot be modified.
  • The partition ranges of all temporary partitions must not overlap with each other.
  • The ranges of a temporary partition and a formal partition may overlap.
  • The name of a temporary partition cannot be the same as any formal partition or other temporary partition.

Follow the replacement workflow​

A typical workflow consists of the following four steps:

  1. Add a temporary partition (specify range / enumerated values / bucket count)
  2. Load data into the temporary partition (INSERT INTO / Stream Load / Broker Load / Routine Load)
  3. Replace the formal partition (REPLACE PARTITION, an atomic operation)
  4. (Optional) Drop any unused temporary partitions

Add a temporary partition​

Use the ALTER TABLE ADD TEMPORARY PARTITION statement to create a temporary partition. Both Range and List partitions are supported. You can specify a different bucket count. VeloDB Cloud manages storage redundancy, so do not configure replica counts in these examples. The following alternatives assume tables with the corresponding partition columns and types.

-- Range partition: LESS THAN form
ALTER TABLE tbl1 ADD TEMPORARY PARTITION tp1 VALUES LESS THAN("2020-02-01");

-- Range partition: fixed-interval form
ALTER TABLE tbl2 ADD TEMPORARY PARTITION tp1 VALUES [("2020-01-01"), ("2020-02-01"));

-- Range partition: custom bucketing
ALTER TABLE tbl1 ADD TEMPORARY PARTITION tp1 VALUES LESS THAN("2020-02-01")
DISTRIBUTED BY HASH(k1) BUCKETS 5;

-- List partition: single-column enumeration
ALTER TABLE tbl3 ADD TEMPORARY PARTITION tp1 VALUES IN ("Beijing", "Shanghai");

-- List partition: multi-column enumeration
ALTER TABLE tbl4 ADD TEMPORARY PARTITION tp1 VALUES IN ((1, "Beijing"), (1, "Shanghai"));

-- List partition: custom bucketing
ALTER TABLE tbl3 ADD TEMPORARY PARTITION tp1 VALUES IN ("Beijing", "Shanghai")
DISTRIBUTED BY HASH(k1) BUCKETS 5;

Load data into a temporary partition​

For Stream Load, <endpoint> is the HTTPS HTTP endpoint, including its port, from warehouse connection settings. curl prompts for the SQL password. Configure source access and authentication as described in each loading guide. The following syntax sketches show where each load method specifies temporary partitions. Replace table, partition, source, and mapping placeholders with those of your load job:

-- INSERT INTO
INSERT INTO tbl TEMPORARY PARTITION(tp1, tp2, ...) SELECT ...;
# Stream Load
curl --location-trusted -u '<sql-user>' \
-H "label:123" \
-H "temporary_partitions: tp1,tp2" \
-T testData \
'<endpoint>/api/testDb/testTbl/_stream_load'
-- Broker Load
LOAD LABEL example_db.label1
(
DATA INFILE("hdfs://<hdfs-host>:<hdfs-port>/data/input/file")
INTO TABLE my_table
TEMPORARY PARTITION (tp1, tp2, ...)
...
)
WITH HDFS ("fs.defaultFS"="hdfs://<hdfs-host>:<hdfs-port>", "hadoop.username"="<hdfs-user>");

-- Routine Load
CREATE ROUTINE LOAD example_db.test1 ON example_tbl
COLUMNS(k1, k2, k3, v1, v2, v3 = k1 * 100),
TEMPORARY PARTITIONS(tp1, tp2, ...),
WHERE k1 > 100
PROPERTIES (...)
FROM KAFKA (...);

Query a temporary partition​

Temporary partitions cannot be reached by regular SQL. You must declare them explicitly with the TEMPORARY PARTITION keyword:

SELECT ... FROM
tbl1 TEMPORARY PARTITION(tp1, tp2, ...)
JOIN
tbl2 TEMPORARY PARTITION(tp1, tp2, ...)
ON ...
WHERE ...;

Replace a formal partition​

Use ALTER TABLE REPLACE PARTITION to atomically replace formal partitions with temporary partitions.

-- Equal-count replacement
ALTER TABLE tbl1 REPLACE PARTITION (p1) WITH TEMPORARY PARTITION (tp1);

-- Many-to-many replacement
ALTER TABLE tbl1 REPLACE PARTITION (p1, p2) WITH TEMPORARY PARTITION (tp1, tp2, tp3);

-- Replace with explicit parameters
ALTER TABLE tbl1 REPLACE PARTITION (p1, p2) WITH TEMPORARY PARTITION (tp1, tp2)
PROPERTIES (
"strict_range" = "false",
"use_temp_partition_name" = "true"
);

Set replacement parameters​

ParameterDefaultDescription
strict_rangetrueControls how strictly partition ranges / enumerated values must match before and after replacement (see below)
use_temp_partition_namefalseControls how formal partitions are named after replacement

Control partition matching with strict_range​

  • Range partition:
    • true: The union of ranges of the formal partitions being replaced must be exactly the same as the union of ranges of the temporary partitions used for replacement.
    • false: The incoming partitions must not conflict with any formal partition that remains after replacement. Temporary partitions must also remain mutually non-overlapping.
  • List partition: With true, the unions of enumerated values must match. With false, the incoming values must not conflict with the remaining formal partitions.

Replace partitions with equal range unions​

Replace partitions with equal range unions
-- Ranges (=> union) of partitions p1, p2, p3 to be replaced:
[10, 20), [20, 30), [40, 50) => [10, 30), [40, 50)

-- Ranges (=> union) of replacement partitions tp1, tp2, tp3:
[10, 30), [40, 45), [45, 50) => [10, 30), [40, 50)

-- The unions are equal, so tp1, tp2, and tp3 can replace p1, p2, and p3.

Replace partitions with different range unions​

Replace partitions with different range unions
-- Range (=> union) of partition p1 to be replaced:
[10, 50) => [10, 50)

-- Ranges (=> union) of replacement partitions tp1, tp2:
[10, 30), [40, 50) => [10, 30), [40, 50)

-- strict_range = true: replacement is rejected.
-- strict_range = false: if the resulting [10, 30) and [40, 50) do not overlap with other formal partitions, the replacement is allowed.

Match single-column list values​

Match single-column list values
-- Enumerated values (=> union) of partitions p1, p2 to be replaced:
(1, 2, 3), (4, 5, 6) => (1, 2, 3, 4, 5, 6)

-- Enumerated values (=> union) of replacement partitions tp1, tp2, tp3:
(1, 2, 3), (4), (5, 6) => (1, 2, 3, 4, 5, 6)

-- The unions are equal, so tp1, tp2, and tp3 can replace p1 and p2.

Match multiple-column list values​

Match multiple-column list values
-- Enumerated values (=> union) of partitions p1, p2, p3 to be replaced:
(("1","beijing"), ("1", "shanghai")),
(("2","beijing"), ("2", "shanghai")),
(("3","beijing"), ("3", "shanghai"))
=> (("1","beijing"), ("1", "shanghai"), ("2","beijing"), ("2", "shanghai"), ("3","beijing"), ("3", "shanghai"))

-- Enumerated values (=> union) of replacement partitions tp1, tp2:
(("1","beijing"), ("1", "shanghai")),
(("2","beijing"), ("2", "shanghai"), ("3","beijing"), ("3", "shanghai"))
=> (("1","beijing"), ("1", "shanghai"), ("2","beijing"), ("2", "shanghai"), ("3","beijing"), ("3", "shanghai"))

-- The unions are equal, so tp1 and tp2 can replace p1, p2, and p3.

Choose names with use_temp_partition_name​

Controls the naming behavior of formal partitions after replacement:

Scenariouse_temp_partition_name = false (default)use_temp_partition_name = true
Number of partitions to be replaced = number of replacement partitionsKeep the original formal partition name (only data and properties are replaced)Use the temporary partition name as the new formal partition name
Number of partitions to be replaced != number of replacement partitionsThe parameter has no effect; the temporary partition name is forcedUse the temporary partition name

Keep names with equal partition counts​

Keep names with equal partition counts
ALTER TABLE tbl1 REPLACE PARTITION (p1) WITH TEMPORARY PARTITION (tp1);
  • use_temp_partition_name = false (default): After replacement, the partition is still named p1, but its data and properties come from tp1.
  • use_temp_partition_name = true: After replacement, the partition is renamed to tp1, and p1 no longer exists.

Assign names with unequal partition counts​

Assign names with unequal partition counts
ALTER TABLE tbl1 REPLACE PARTITION (p1, p2) WITH TEMPORARY PARTITION (tp1);
  • Because the number of partitions to be replaced (2) is not equal to the number of replacement partitions (1), use_temp_partition_name has no effect.
  • After replacement, the partition is named tp1, and the original p1 and p2 no longer exist.

Tip:

Validate replacement data

Always validate the temporary data before replacement. Old formal partitions are recycled unless FORCE is used. Recovery depends on retention, schema compatibility, and resolving conflicting active partitions. See Recover retained partitions. Do not treat replacement as an automatic rollback mechanism.

Drop a temporary partition​

Use ALTER TABLE DROP TEMPORARY PARTITION to drop temporary partitions that are no longer needed:

ALTER TABLE tbl1 DROP TEMPORARY PARTITION tp1;

Note:

After a temporary partition is dropped, it cannot be recovered with the RECOVER command.


Coordinate other operations​

Check the effect of DROP​

OperationEffect on Temporary PartitionsRecoverable
DROP DATABASE / DROP TABLETemporary partitions in the database or table are dropped togetherThe database or table may be recovered within retention unless FORCE was used. Inspect temporary partitions after recovery before relying on them
ALTER ... DROP PARTITION (formal partition)Has no effect on temporary partitionsThe formal partition can be recovered with RECOVER within the retention window
ALTER ... DROP TEMPORARY PARTITIONDrops the specified temporary partitionNot recoverable

Check the effect of TRUNCATE​

OperationEffect
TRUNCATE TABLEClears formal and temporary partition data. Non-FORCE operations retain old partition metadata subject to recovery constraints
TRUNCATE TABLE ... PARTITION (truncate a formal partition)Does not affect temporary partitions
Running TRUNCATE on a temporary partitionNot supported

Check the effect of ALTER​

  • While a table has temporary partitions, schema changes, rollups, and similar alteration operations cannot be executed.
  • While a table is undergoing an alteration operation, temporary partitions cannot be added.

Resolve common questions​

Access temporary partitions explicitly

No. A temporary partition can only be accessed explicitly through a TEMPORARY PARTITION(...) clause. Regular queries, reports, and views do not read data from temporary partitions.

Choose a different bucket count

Specify a different BUCKETS value for the new partition, load the data, and switch with REPLACE PARTITION. Storage redundancy is managed by VeloDB Cloud.

Switch partition data after validation

Follow this order:

  1. Run ALTER TABLE ... ADD TEMPORARY PARTITION to create the temporary partition.
  2. Use INSERT INTO or a load job to write the new data into the temporary partition.
  3. Verify that the data in the temporary partition is correct.
  4. Run ALTER TABLE ... REPLACE PARTITION ... WITH TEMPORARY PARTITION ... to perform the atomic replacement.

Throughout the process, the formal partition remains readable from outside.

Handle replacement failures or invalid data

Before replacement, the data is still in the temporary partition and the formal partition is unaffected. If you find a data issue, run ALTER TABLE ... DROP TEMPORARY PARTITION to drop the temporary partition and reload. After replacement, recovery of the original formal partition depends on retention, FORCE, and partition conflicts. Keep a reloadable source for predictable rollback.

Add multiple temporary partitions

Yes. As long as the temporary partitions do not overlap in range or enumerated values and their names are unique, you can add multiple temporary partitions within the service-managed partition limits.

Resolve common errors​

Error / SymptomPossible CauseResolution
Adding a temporary partition fails: partition already existsThe name conflicts with an existing formal or temporary partitionChange the temporary partition name
Adding a temporary partition fails: range overlapThe range or enumerated values overlap with an existing temporary partitionAdjust the range or drop the conflicting temporary partition first
Replacement fails: strict_range check failsThe range unions of the Range partitions are not equalMake sure the unions match, or set strict_range = false explicitly
Replacement fails: List partition enumerated values do not matchThe value unions differ with strict_range=trueMatch the value unions, or use strict_range=false only when the new values do not conflict with remaining formal partitions
Schema change cannot be executedThe table contains temporary partitionsDrop or replace all temporary partitions first
Temporary partition was dropped by mistakeRECOVER does not support recovering temporary partitionsRecreate the partition and reload the data