Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Data Lake Insight/ Spark SQL Syntax Reference/ Tables/ Partition-related Syntax/ Deleting Partitions by Specifying Filter Criteria (Only Supported on OBS Tables)

Deleting Partitions by Specifying Filter Criteria (Only Supported on OBS Tables)

Updated on 2024-07-04 GMT+08:00

Function

This statement is used to delete one or more partitions based on specified conditions.

Precautions

  • This statement is only used for OBS tables.
  • The table in which partitions are to be deleted must exist. Otherwise, an error is reported.
  • The partition to be deleted must exist. Otherwise, an error is reported. To avoid this error, add IF EXISTS to this statement.

Syntax

1
2
3
ALTER TABLE [db_name.]table_name
  DROP [IF EXISTS]
  PARTITIONS partition_filtercondition;

Keywords

  • DROP: deletes specified partitions.
  • IF EXISTS: Partitions to be deleted must exist. Otherwise, an error is reported.
  • PARTITIONS: specifies partitions meeting the conditions

Parameters

Table 1 Parameters

Parameter

Description

db_name

Database name that contains letters, digits, and underscores (_). It cannot contain only digits or start with an underscore (_).

table_name

Table name of a database that contains letters, digits, and underscores (_). It cannot contain only digits or start with an underscore (_). The matching rule is ^(?!_)(?![0-9]+$)[A-Za-z0-9_$]*$. If special characters are required, use single quotation marks ('') to enclose them.

This statement is used for OBS table operations.

partition_filtercondition

Condition used to search partitions to be deleted. The format is as follows:

Partition column name Operator Value to compare

Example: start_date < '201911'

  • Example 1: <partition_filtercondition1> AND|OR <partition_filtercondition2>

    Example: start_date < '201911' OR start_date >= '202006'

  • Example 2: (<partition_filtercondition1>)[,partitions (<partition_filtercondition2>), ...]

    Example: (start_date <> '202007'), partitions(start_date < '201912')

Example

To help you understand how to use this statement, this section provides an example of deleting a partition from the source data.

  1. Use the DataSource syntax to create an OBS partitioned table.

    An OBS partitioned table named student is created, which contains the student ID (id), student name (name), student faculty number (facultyNo), and student class number (classNo) and uses facultyNo and classNo for partitioning.

    1
    2
    3
    4
    5
    6
    7
    8
    create table if not exists student (
    id int,
    name STRING,
    facultyNo int,
    classNo INT)
    using csv
    options (path 'path 'obs://bucketName/filePath'')
    partitioned by (faculytNo, classNo);
    

  2. Insert partition data into the table.

    You can insert the following data:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    INSERT into student
    partition (facultyNo = 10, classNo = 101)
    values (1010101, "student01"), (1010102, "student02");
    
    INSERT into student
    partition (facultyNo = 10, classNo = 102)
    values (1010203, "student03"), (1010204, "student04");
    
    INSERT into student
    partition (facultyNo = 20, classNo = 101)
    values (2010105, "student05"), (2010106, "student06");
    
    INSERT into student
    partition (facultyNo = 20, classNo = 102)
    values (2010207, "student07"), (2010208, "student08");
    
    INSERT into student
    partition (facultyNo = 20, classNo = 103)
    values (2010309, "student09"), (2010310, "student10");
    
    INSERT into student
    partition (facultyNo = 30, classNo = 101)
    values (3010111, "student11"), (3010112, "student12");
    
    INSERT into student
    partition (facultyNo = 30, classNo = 102)
    values (3010213, "student13"), (3010214, "student14");
    

  3. View the partitions.

    You can view all partitions in the table.

    The example code is as follows:

    SHOW partitions student;
    Table 2 Example table data

    facultyNo

    classNo

    facultyNo=10

    classNo=101

    facultyNo=10

    classNo=102

    facultyNo=20

    classNo=101

    facultyNo=20

    classNo=102

    facultyNo=20

    classNo=103

    facultyNo=30

    classNo=101

    facultyNo=30

    classNo=102

  4. Delete a partition.

    NOTE:

    This step describes how to delete a partition by specifying filter criteria. If you want to delete a partition without specifying filter criteria, see Deleting a Partition.

    This example cannot be used together with that in Deleting a Partition. Distinguish the keyword partitions in this example from the keyword partition in the example in Deleting a Partition.

    • Example 1: deleting partitions by specifying filter criteria (only supported on OBS tables), and using the AND statement to delete partitions
      Table 3 Data before execution

      facultyNo

      classNo

      facultyNo=10

      classNo=101

      facultyNo=10

      classNo=102

      facultyNo=20

      classNo=101

      facultyNo=20

      classNo=102

      Run the following statements to delete the partitions whose facultyNo is 20 and classNo is 102:

      ALTER TABLE student
      DROP IF EXISTS
      PARTITIONS (facultyNo = 20 AND classNo = 102);

      You can see that the statement deletes the partitions that meet both the criteria.

      Table 4 Data after execution

      facultyNo

      classNo

      facultyNo=10

      classNo=101

      facultyNo=10

      classNo=102

      facultyNo=20

      classNo=101

    • Example 2: deleting partitions by specifying filter criteria (only supported on OBS tables), and using the OR statement to delete partitions
      Table 5 Data before execution

      facultyNo

      classNo

      facultyNo=10

      classNo=101

      facultyNo=10

      classNo=102

      facultyNo=20

      classNo=101

      facultyNo=20

      classNo=102

      Run the following statements to delete the partitions whose facultyNo is 10 or classNo is 101:

      ALTER TABLE student 
      DROP IF EXISTS
      PARTITIONS (facultyNo = 10),
      PARTITIONS (classNo = 101);

      Execution result:

      Table 6 Data after execution

      facultyNo

      classNo

      facultyNo=20

      classNo=102

      Under the selected deletion criteria, the first record in the partition meets both facultyNo and classNo, the second record meets facultyNo, and the third record meets classNo.

      As a result, only one partition row remains after executing the partition deletion statement.

      According to method 1, the foregoing execution statement may also be written as:

      ALTER TABLE student
      DROP IF EXISTS
      PARTITIONS (facultyNo = 10 OR classNo = 101);
    • Example 3: deleting partitions by specifying filter criteria (only supported on OBS tables), and using relational operator statements to delete specified partitions
      Table 7 Data before execution

      facultyNo

      classNo

      facultyNo=10

      classNo=101

      facultyNo=10

      classNo=102

      facultyNo=20

      classNo=101

      facultyNo=20

      classNo=102

      facultyNo=20

      classNo=103

      Run the following statements to delete partitions whose classNo is greater than 100 and less than 102:

      ALTER TABLE student
      DROP IF EXISTS
      PARTITIONS (classNo BETWEEN 100 AND 102);

      Execution result:

      Table 8 Data before execution

      facultyNo

      classNo

      facultyNo=20

      classNo=103

Sitemizi ve deneyiminizi iyileştirmek için çerezleri kullanırız. Sitemizde tarama yapmaya devam ederek çerez politikamızı kabul etmiş olursunuz. Daha fazla bilgi edinin

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback