Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Support parsing Oracle CREATE MATERIALIZED sql #27994

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ execute
| alterRollbackSegment
| alterDiskgroup
| alterIndexType
| createMaterializedView
| createMaterializedViewLog
| alterMaterializedView
| alterMaterializedViewLog
| alterFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateSynonymContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTableContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTablespaceContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewLogContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DisassociateStatisticsContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropClusterContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropColumnSpecificationContext;
Expand Down Expand Up @@ -242,6 +244,8 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateSynonymStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTablespaceStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewLogStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateVarrayTypeStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDisassociateStatisticsStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropClusterStatement;
Expand Down Expand Up @@ -1199,6 +1203,16 @@ public ASTNode visitCreateTablespace(final CreateTablespaceContext ctx) {
return new OracleCreateTablespaceStatement();
}

@Override
public ASTNode visitCreateMaterializedView(final CreateMaterializedViewContext ctx) {
return new OracleCreateMaterializedViewStatement();
}

@Override
public ASTNode visitCreateMaterializedViewLog(final CreateMaterializedViewLogContext ctx) {
return new OracleCreateMaterializedViewLogStatement();
}

@Override
public ASTNode visitCreateCluster(final CreateClusterContext ctx) {
return new OracleCreateClusterStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ public enum SQLVisitorRule {

CREATE_MATERIALIZED_VIEW("CreateMaterializedView", SQLStatementType.DDL),

CREATE_MATERIALIZED_VIEW_LOG("CreateMaterializedViewLog", SQLStatementType.DDL),

CREATE_OPERATOR("CreateOperator", SQLStatementType.DDL),

CREATE_POLICY("CreatePolicy", SQLStatementType.DDL),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.sql.dialect.statement.oracle.ddl;

import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;

/**
* Oracle create materialized view log statement.
*/
public class OracleCreateMaterializedViewLogStatement extends AbstractSQLStatement implements OracleStatement {
zhangfengcdt marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.sql.dialect.statement.oracle.ddl;

import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateMaterializedViewStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;

/**
* OracleSQL create materialized view statement.
*/
public class OracleCreateMaterializedViewStatement extends CreateMaterializedViewStatement implements OracleStatement {
zhangfengcdt marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateInmemoryJoinGroupStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLanguageStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLockdownProfileStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateMaterializedViewLogStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateMaterializedViewStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateOperatorStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreatePFileStatementTestCase;
Expand Down Expand Up @@ -1666,6 +1667,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "create-materialized-view")
private final List<CreateMaterializedViewStatementTestCase> createMaterializedViewStatementTestCases = new LinkedList<>();

@XmlElement(name = "create-materialized-view-log")
private final List<CreateMaterializedViewLogStatementTestCase> createMaterializedViewLogStatementTestCases = new LinkedList<>();

@XmlElement(name = "create-operator")
private final List<CreateOperatorStatementTestCase> createOperatorStatementTestCases = new LinkedList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.cases.parser.jaxb.statement.ddl;

import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;

/**
* Create materialized view statement test case.
*/
public final class CreateMaterializedViewLogStatementTestCase extends SQLParserTestCase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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.
-->

<sql-parser-test-cases>
<create-materialized-view-log sql-case-id="create_materialized_view_log_with" />
<create-materialized-view-log sql-case-id="create_materialized_view_log_with_including_new" />
<create-materialized-view-log sql-case-id="create_materialized_view_log_with_tablespace" />
<create-materialized-view-log sql-case-id="create_materialized_view_log_with_table_schema" />
<create-materialized-view-log sql-case-id="create_materialized_view_log_with_object_id" />
<create-materialized-view-log sql-case-id="create_materialized_view_log_with_row_id" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
<create-materialized-view sql-case-id="create_materialized_view_with_using" />
<create-materialized-view sql-case-id="create_materialized_view_with_no_data" />
<create-materialized-view sql-case-id="create_materialized_view_with_data" />
<create-materialized-view sql-case-id="create_materialized_view_with_refresh_fast" />
<create-materialized-view sql-case-id="create_materialized_view_with_refresh_fast_query_rewrite" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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.
-->

<sql-cases>
<sql-case id="create_materialized_view_log_with" value="CREATE MATERIALIZED VIEW LOG ON inventories WITH (quantity_on_hand);" db-types="Oracle" />
<sql-case id="create_materialized_view_log_with_including_new" value="CREATE MATERIALIZED VIEW
LOG ON employees WITH PRIMARY KEY INCLUDING NEW VALUES;" db-types="Oracle" />
<sql-case id="create_materialized_view_log_with_tablespace" value="CREATE MATERIALIZED VIEW
LOG ON emp_data PCTFREE 5 PCTUSED 60 TABLESPACE example STORAGE (INITIAL 50K)
REFRESH FAST NEXT sysdate + 7 AS SELECT * FROM employees;" db-types="Oracle" />
<sql-case id="create_materialized_view_log_with_table_schema" value="CREATE MATERIALIZED VIEW
LOG ON &quot;SH&quot;.&quot;CUSTOMERS&quot; WITH ROWID, SEQUENCE(&quot;CUST_ID&quot;)
INCLUDING NEW VALUES;" db-types="Oracle" />
<sql-case id="create_materialized_view_log_with_object_id" value="CREATE MATERIALIZED VIEW LOG ON oe.categories_tab_sys WITH OBJECT ID;" db-types="Oracle" />
<sql-case id="create_materialized_view_log_with_row_id" value="CREATE MATERIALIZED VIEW LOG ON sales WITH ROWID;" db-types="Oracle" />
</sql-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@
<sql-case id="create_materialized_view_with_using" value="CREATE MATERIALIZED VIEW mat_view_heap_psql USING heap_psql AS SELECT f1 from tbl_heap_psql;" db-types="PostgreSQL" />
<sql-case id="create_materialized_view_with_no_data" value="CREATE MATERIALIZED VIEW matview_schema.mv_nodata1 (a) AS SELECT generate_series(1, 10) WITH NO DATA;" db-types="PostgreSQL" />
<sql-case id="create_materialized_view_with_data" value="CREATE MATERIALIZED VIEW matview_schema.mv_withdata1 (a) AS SELECT generate_series(1, 10) WITH DATA;" db-types="PostgreSQL" />
<sql-case id="create_materialized_view_with_refresh_fast" value="CREATE MATERIALIZED VIEW warranty_orders REFRESH FAST AS
SELECT order_id, line_item_id, product_id FROM order_items WHERE EXISTS
(SELECT * FROM inventories i WHERE o.product_id = i.product_id AND i.quantity_on_hand IS NOT NULL)
UNION
SELECT order_id, line_item_id, product_id FROM order_items WHERE quantity > 5;" db-types="Oracle" />
<sql-case id="create_materialized_view_with_refresh_fast_query_rewrite" value="CREATE MATERIALIZED VIEW SH.CUST_MV$SUB1
REFRESH FAST WITH ROWID ON COMMIT ENABLE QUERY REWRITE
AS SELECT SH.SALES.PROD_ID C1, SH.CUSTOMERS.CUST_ID C2,
SUM(SH.SALES.AMOUNT_SOLD) M1, COUNT(SH.SALES.AMOUNT_SOLD) M2, COUNT(*) M3 FROM SH.SALES, SH.CUSTOMERS
WHERE SH.CUSTOMERS.CUST_ID = SH.SALES.CUST_ID AND (SH.SALES.CUST_ID IN (1012, 1010, 1005))
GROUP BY SH.SALES.PROD_ID, SH.CUSTOMERS.CUST_ID;" db-types="Oracle" />
</sql-cases>