Skip to content
Merged
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 @@ -473,6 +473,8 @@ public enum SQLVisitorRule {

ALTER_RESOURCE_GROUP("AlterResourceGroup", SQLStatementType.DAL),

ALTER_RESOURCE("AlterResource", SQLStatementType.DAL),

DELIMITER("Delimiter", SQLStatementType.DAL),

CALL("Call", SQLStatementType.DML),
Expand Down
5 changes: 5 additions & 0 deletions parser/sql/engine/dialect/doris/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
<artifactId>shardingsphere-parser-sql-statement-mysql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-parser-sql-statement-doris</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,30 @@ alterResourceGroup
(ENABLE | DISABLE FORCE?)?
;

alterResource
: ALTER RESOURCE resourceName PROPERTIES LP_ propertyAssignments RP_
;

resourceName
: identifier | string_
;

propertyAssignments
: propertyAssignment (COMMA_ propertyAssignment)*
;

propertyAssignment
: propertyKey EQ_ propertyValue
;

propertyKey
: identifier | string_
;

propertyValue
: literals | identifier
;

vcpuSpec
: NUMBER_ | NUMBER_ MINUS_ NUMBER_
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ execute
| createTrigger
| dropTrigger
| alterResourceGroup
| alterResource
| createResourceGroup
| dropResourceGroup
| prepare
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UninstallComponentContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UninstallPluginContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UseContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AlterResourceContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyAssignmentContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ResourceNameContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyKeyContext;
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyValueContext;
import org.apache.shardingsphere.sql.parser.engine.doris.visitor.statement.DorisStatementVisitor;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CacheTableIndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneActionSegment;
Expand Down Expand Up @@ -153,6 +158,13 @@
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.LiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.BooleanLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.DateTimeLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NullLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.OtherLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.TemporalLiteralValue;
import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement;
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement;
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateLoadableFunctionStatement;
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement;
Expand Down Expand Up @@ -233,6 +245,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -902,6 +915,68 @@ public ASTNode visitAlterResourceGroup(final AlterResourceGroupContext ctx) {
return new MySQLAlterResourceGroupStatement(getDatabaseType(), ((IdentifierValue) visit(ctx.groupName())).getValue());
}

@Override
public ASTNode visitAlterResource(final AlterResourceContext ctx) {
String resourceName = getResourceName(ctx.resourceName());
Properties properties = new Properties();
for (PropertyAssignmentContext each : ctx.propertyAssignments().propertyAssignment()) {
String key = getPropertyKey(each.propertyKey());
String value = getPropertyValue(each.propertyValue());
properties.setProperty(key, value);
}
return new DorisAlterResourceStatement(getDatabaseType(), resourceName, properties);
}

private String getResourceName(final ResourceNameContext ctx) {
if (null != ctx.identifier()) {
return ((IdentifierValue) visit(ctx.identifier())).getValue();
}
return ((StringLiteralValue) visit(ctx.string_())).getValue();
}

private String getPropertyKey(final PropertyKeyContext ctx) {
if (null != ctx.identifier()) {
return ((IdentifierValue) visit(ctx.identifier())).getValue();
}
return ((StringLiteralValue) visit(ctx.string_())).getValue();
}

private String getPropertyValue(final PropertyValueContext ctx) {
if (null != ctx.identifier()) {
return ((IdentifierValue) visit(ctx.identifier())).getValue();
}
ASTNode result = visit(ctx.literals());
if (result instanceof LiteralValue) {
return getLiteralValueAsString((LiteralValue<?>) result);
}
return result.toString();
}

private String getLiteralValueAsString(final LiteralValue<?> literalValue) {
if (literalValue instanceof StringLiteralValue) {
return ((StringLiteralValue) literalValue).getValue();
}
if (literalValue instanceof NumberLiteralValue) {
return ((NumberLiteralValue) literalValue).getValue().toString();
}
if (literalValue instanceof BooleanLiteralValue) {
return String.valueOf(((BooleanLiteralValue) literalValue).getValue());
}
if (literalValue instanceof NullLiteralValue) {
return "NULL";
}
if (literalValue instanceof DateTimeLiteralValue) {
return ((DateTimeLiteralValue) literalValue).getValue();
}
if (literalValue instanceof TemporalLiteralValue) {
return ((TemporalLiteralValue) literalValue).getValue();
}
if (literalValue instanceof OtherLiteralValue) {
return String.valueOf(((OtherLiteralValue) literalValue).getValue());
}
return String.valueOf(literalValue.getValue());
}

@Override
public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) {
return new MySQLChangeMasterStatement(getDatabaseType());
Expand Down
36 changes: 36 additions & 0 deletions parser/sql/statement/dialect/doris/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-parser-sql-statement-dialect</artifactId>
<version>5.5.3-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-parser-sql-statement-doris</artifactId>
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-parser-sql-statement-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.shardingsphere.sql.parser.statement.doris.dal;

import lombok.Getter;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;

import java.util.Properties;

/**
* Alter resource statement for Doris.
*/
@Getter
public final class DorisAlterResourceStatement extends DALStatement {

private final String resourceName;

private final Properties properties;

public DorisAlterResourceStatement(final DatabaseType databaseType, final String resourceName, final Properties properties) {
super(databaseType);
this.resourceName = resourceName;
this.properties = properties;
}
}
1 change: 1 addition & 0 deletions parser/sql/statement/dialect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
<module>sqlserver</module>
<module>oracle</module>
<module>hive</module>
<module>doris</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.mysql.MySQLDALStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.oracle.OracleDALStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.postgresql.PostgreSQLDALStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.DorisDALStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.standard.StandardDALStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;

Expand All @@ -45,5 +46,6 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final DALS
MySQLDALStatementAssert.assertIs(assertContext, actual, expected);
PostgreSQLDALStatementAssert.assertIs(assertContext, actual, expected);
OracleDALStatementAssert.assertIs(assertContext, actual, expected);
DorisDALStatementAssert.assertIs(assertContext, actual, expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type.DorisAlterResourceStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterResourceStatementTestCase;

/**
* DAL statement assert for Doris.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DorisDALStatementAssert {

/**
* Assert DAL statement is correct with expected parser result.
*
* @param assertContext assert context
* @param actual actual DAL statement
* @param expected expected DAL statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final DALStatement actual, final SQLParserTestCase expected) {
if (actual instanceof DorisAlterResourceStatement) {
DorisAlterResourceStatementAssert.assertIs(assertContext, (DorisAlterResourceStatement) actual, (DorisAlterResourceStatementTestCase) expected);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterResourceStatementTestCase;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Alter resource statement assert for Doris.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DorisAlterResourceStatementAssert {

/**
* Assert alter resource statement is correct with expected parser result.
*
* @param assertContext assert context
* @param actual actual alter resource statement
* @param expected expected alter resource statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final DorisAlterResourceStatement actual, final DorisAlterResourceStatementTestCase expected) {
if (null != expected.getResourceName()) {
assertThat(assertContext.getText("resource name does not match: "), actual.getResourceName(), is(expected.getResourceName()));
}
assertNotNull(actual.getProperties(), assertContext.getText("properties should not be null"));
if (!expected.getProperties().isEmpty()) {
assertThat(assertContext.getText("properties size does not match: "), actual.getProperties().size(), is(expected.getProperties().size()));
expected.getProperties().forEach(property -> {
String actualValue = actual.getProperties().getProperty(property.getKey());
assertNotNull(actualValue, assertContext.getText("property key '" + property.getKey() + "' should exist"));
assertThat(assertContext.getText("property value for key '" + property.getKey() + "' does not match: "), actualValue, is(property.getValue()));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.table.MySQLChecksumTableStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.table.MySQLOptimizeTableStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.table.MySQLRepairTableStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterResourceStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.oracle.OracleSpoolStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.postgresql.PostgreSQLResetParameterStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.standard.EmptyStatementTestCase;
Expand Down Expand Up @@ -649,6 +650,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "alter-resource-group")
private final List<MySQLAlterResourceGroupStatementTestCase> alterResourceGroupTestCases = new LinkedList<>();

@XmlElement(name = "alter-resource")
private final List<DorisAlterResourceStatementTestCase> alterResourceTestCases = new LinkedList<>();

@XmlElement(name = "create-resource-group")
private final List<MySQLCreateResourceGroupStatementTestCase> createResourceGroupTestCases = new LinkedList<>();

Expand Down
Loading