Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ AS: 'AS';
ASC: 'ASC';
AT: 'AT';
AUTHORS: 'AUTHORS';
AUTHENTICATION: 'AUTHENTICATION';
AUTO: 'AUTO';
AUTO_INCREMENT: 'AUTO_INCREMENT';
ALWAYS: 'ALWAYS';
Expand Down Expand Up @@ -294,6 +295,7 @@ IGNORE: 'IGNORE';
IMMEDIATE: 'IMMEDIATE';
IN: 'IN';
INCREMENTAL: 'INCREMENTAL';
INTEGRATION: 'INTEGRATION';
INDEX: 'INDEX';
INDEXES: 'INDEXES';
INFILE: 'INFILE';
Expand Down
15 changes: 15 additions & 0 deletions fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ supportedCreateStatement
LIKE existedTable=multipartIdentifier
(WITH ROLLUP (rollupNames=identifierList)?)? #createTableLike
| CREATE ROLE (IF NOT EXISTS)? name=identifierOrText (COMMENT STRING_LITERAL)? #createRole
| CREATE AUTHENTICATION INTEGRATION (IF NOT EXISTS)? integrationName=identifier
properties=propertyClause commentSpec? #createAuthenticationIntegration
| CREATE WORKLOAD GROUP (IF NOT EXISTS)?
name=identifierOrText (FOR computeGroup=identifierOrText)? properties=propertyClause? #createWorkloadGroup
| CREATE CATALOG (IF NOT EXISTS)? catalogName=identifier
Expand Down Expand Up @@ -292,6 +294,12 @@ supportedAlterStatement
properties=propertyClause? #alterComputeGroup
| ALTER CATALOG name=identifier SET PROPERTIES
LEFT_PAREN propertyItemList RIGHT_PAREN #alterCatalogProperties
| ALTER AUTHENTICATION INTEGRATION integrationName=identifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to delete an existing property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALTER AUTHENTICATION INTEGRATION <integration_name>
UNSET PROPERTIES ('k1', 'k2', ...);

SET properties=propertyClause #alterAuthenticationIntegrationProperties
| ALTER AUTHENTICATION INTEGRATION integrationName=identifier
UNSET properties=propertyKeyClause #alterAuthenticationIntegrationUnsetProperties
| ALTER AUTHENTICATION INTEGRATION integrationName=identifier
SET COMMENT comment=STRING_LITERAL #alterAuthenticationIntegrationComment
| ALTER WORKLOAD POLICY name=identifierOrText
properties=propertyClause? #alterWorkloadPolicy
| ALTER SQL_BLOCK_RULE name=identifier properties=propertyClause? #alterSqlBlockRule
Expand Down Expand Up @@ -335,6 +343,7 @@ supportedDropStatement
| DROP STORAGE POLICY (IF EXISTS)? name=identifier #dropStoragePolicy
| DROP WORKLOAD GROUP (IF EXISTS)? name=identifierOrText (FOR computeGroup=identifierOrText)? #dropWorkloadGroup
| DROP CATALOG (IF EXISTS)? name=identifier #dropCatalog
| DROP AUTHENTICATION INTEGRATION (IF EXISTS)? name=identifier #dropAuthenticationIntegration
| DROP FILE name=STRING_LITERAL
((FROM | IN) database=identifier)? properties=propertyClause #dropFile
| DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText #dropWorkloadPolicy
Expand Down Expand Up @@ -1454,6 +1463,10 @@ propertyClause
: PROPERTIES LEFT_PAREN fileProperties=propertyItemList RIGHT_PAREN
;

propertyKeyClause
: PROPERTIES LEFT_PAREN keys+=propertyKey (COMMA keys+=propertyKey)* RIGHT_PAREN
;

propertyItemList
: properties+=propertyItem (COMMA properties+=propertyItem)*
;
Expand Down Expand Up @@ -1955,6 +1968,7 @@ nonReserved
| ARRAY
| AT
| AUTHORS
| AUTHENTICATION
| AUTO_INCREMENT
| BACKENDS
| BACKUP
Expand Down Expand Up @@ -2106,6 +2120,7 @@ nonReserved
| IGNORE
| IMMEDIATE
| INCREMENTAL
| INTEGRATION
| INDEXES
| INSERT
| INVERTED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.authentication;

import org.apache.doris.common.DdlException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.persist.gson.GsonUtils;

import com.google.gson.annotations.SerializedName;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
* Persistent metadata for AUTHENTICATION INTEGRATION.
*/
public class AuthenticationIntegrationMeta implements Writable {
public static final String TYPE_PROPERTY = "type";

@SerializedName(value = "n")
private String name;
@SerializedName(value = "t")
private String type;
@SerializedName(value = "p")
private Map<String, String> properties;
@SerializedName(value = "c")
private String comment;

private AuthenticationIntegrationMeta() {
this.name = "";
this.type = "";
this.properties = Collections.emptyMap();
this.comment = null;
}

public AuthenticationIntegrationMeta(String name, String type, Map<String, String> properties, String comment) {
this.name = Objects.requireNonNull(name, "name can not be null");
this.type = Objects.requireNonNull(type, "type can not be null");
this.properties = Collections.unmodifiableMap(
new LinkedHashMap<>(Objects.requireNonNull(properties, "properties can not be null")));
this.comment = comment;
}

/**
* Build metadata from CREATE SQL arguments.
*/
public static AuthenticationIntegrationMeta fromCreateSql(
String integrationName, Map<String, String> properties, String comment) throws DdlException {
if (properties == null || properties.isEmpty()) {
throw new DdlException("Property 'type' is required in CREATE AUTHENTICATION INTEGRATION");
}
String type = null;
Map<String, String> copiedProperties = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = Objects.requireNonNull(entry.getKey(), "property key can not be null");
if (TYPE_PROPERTY.equalsIgnoreCase(key)) {
if (type != null) {
throw new DdlException("Property 'type' is duplicated in CREATE AUTHENTICATION INTEGRATION");
}
type = entry.getValue();
continue;
}
copiedProperties.put(key, entry.getValue());
}
if (type == null || type.isEmpty()) {
throw new DdlException("Property 'type' is required in CREATE AUTHENTICATION INTEGRATION");
}
return new AuthenticationIntegrationMeta(integrationName, type, copiedProperties, comment);
}

/**
* Build a new metadata object after ALTER ... SET PROPERTIES.
*/
public AuthenticationIntegrationMeta withAlterProperties(Map<String, String> propertiesDelta) throws DdlException {
if (propertiesDelta == null || propertiesDelta.isEmpty()) {
throw new DdlException("ALTER AUTHENTICATION INTEGRATION should contain at least one property");
}
for (String key : propertiesDelta.keySet()) {
if (TYPE_PROPERTY.equalsIgnoreCase(key)) {
throw new DdlException("ALTER AUTHENTICATION INTEGRATION does not allow modifying property 'type'");
}
}
Map<String, String> mergedProperties = new LinkedHashMap<>(properties);
mergedProperties.putAll(propertiesDelta);
return new AuthenticationIntegrationMeta(name, type, mergedProperties, comment);
}

/**
* Build a new metadata object after ALTER ... UNSET PROPERTIES.
*/
public AuthenticationIntegrationMeta withUnsetProperties(Set<String> propertiesToUnset) throws DdlException {
if (propertiesToUnset == null || propertiesToUnset.isEmpty()) {
throw new DdlException("ALTER AUTHENTICATION INTEGRATION should contain at least one property");
}
Map<String, String> reducedProperties = new LinkedHashMap<>(properties);
for (String key : propertiesToUnset) {
if (TYPE_PROPERTY.equalsIgnoreCase(key)) {
throw new DdlException("ALTER AUTHENTICATION INTEGRATION does not allow modifying property 'type'");
}
reducedProperties.remove(key);
}
return new AuthenticationIntegrationMeta(name, type, reducedProperties, comment);
}

public AuthenticationIntegrationMeta withComment(String newComment) {
return new AuthenticationIntegrationMeta(name, type, properties, newComment);
}

public String getName() {
return name;
}

public String getType() {
return type;
}

public Map<String, String> getProperties() {
return properties;
}

public String getComment() {
return comment;
}

public Map<String, String> toSqlPropertiesView() {
Map<String, String> allProperties = new LinkedHashMap<>();
allProperties.put(TYPE_PROPERTY, type);
allProperties.putAll(properties);
return allProperties;
}

@Override
public void write(DataOutput out) throws IOException {
Text.writeString(out, GsonUtils.GSON.toJson(this));
}

public static AuthenticationIntegrationMeta read(DataInput in) throws IOException {
return GsonUtils.GSON.fromJson(Text.readString(in), AuthenticationIntegrationMeta.class);
}
}
Loading
Loading