Skip to content

Commit

Permalink
[feature](mtmv)(2)Implementing mtmv using antlr (apache#26102)
Browse files Browse the repository at this point in the history
Implementing mtmv using antlr,

No specific business logic was implemented, therefore an exception was thrown during execution
```
throw new AnalysisException("current not support.");
```
  • Loading branch information
zddr authored Nov 3, 2023
1 parent 509723c commit 61edb9e
Show file tree
Hide file tree
Showing 23 changed files with 1,481 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ LOCATION: 'LOCATION';
LOCK: 'LOCK';
LOGICAL: 'LOGICAL';
LOW_PRIORITY: 'LOW_PRIORITY';
MANUAL: 'MANUAL';
MAP: 'MAP';
MATCH: 'MATCH';
MATCH_ALL: 'MATCH_ALL';
Expand Down Expand Up @@ -447,6 +448,7 @@ ROW: 'ROW';
ROWS: 'ROWS';
S3: 'S3';
SAMPLE: 'SAMPLE';
SCHEDULE: 'SCHEDULE';
SCHEDULER: 'SCHEDULER';
SCHEMA: 'SCHEMA';
SCHEMAS: 'SCHEMAS';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ statement
TO filePath=STRING_LITERAL
(propertyClause)?
(withRemoteStorageSystem)? #export
| CREATE MATERIALIZED VIEW (IF NOT EXISTS)? mvName=multipartIdentifier
(LEFT_PAREN cols=simpleColumnDefs RIGHT_PAREN)? buildMode?
(REFRESH refreshMethod? refreshTrigger?)?
(KEY keys=identifierList)?
(COMMENT STRING_LITERAL)?
(DISTRIBUTED BY (HASH hashKeys=identifierList | RANDOM) (BUCKETS (INTEGER_VALUE | AUTO))?)?
propertyClause?
AS query #createMTMV
| REFRESH MATERIALIZED VIEW mvName=multipartIdentifier #refreshMTMV
| ALTER MATERIALIZED VIEW mvName=multipartIdentifier ((RENAME newName=identifier)
| (REFRESH (refreshMethod | refreshTrigger | refreshMethod refreshTrigger))
| (SET LEFT_PAREN fileProperties=propertyItemList RIGHT_PAREN)) #alterMTMV
| DROP MATERIALIZED VIEW (IF EXISTS)? mvName=multipartIdentifier #dropMTMV
;

dataDesc
Expand Down Expand Up @@ -110,6 +123,26 @@ dataDesc
;

// -----------------Command accessories-----------------
buildMode
: BUILD (IMMEDIATE | DEFERRED)
;

refreshTrigger
: ON MANUAL
| ON SCHEDULE refreshSchedule
;

refreshSchedule
: EVERY INTEGER_VALUE mvRefreshUnit (STARTS STRING_LITERAL)?
;

mvRefreshUnit
: SECOND | MINUTE | HOUR | DAY | WEEK
;

refreshMethod
: COMPLETE
;

identifierOrText
: errorCapturingIdentifier
Expand Down Expand Up @@ -413,7 +446,14 @@ multipartIdentifier
;

// ----------------Create Table Fields----------

simpleColumnDefs
: cols+=simpleColumnDef (COMMA cols+=simpleColumnDef)*
;

simpleColumnDef
: colName=identifier (COMMENT comment=STRING_LITERAL)?
;

columnDefs
: cols+=columnDef (COMMA cols+=columnDef)*
;
Expand Down Expand Up @@ -958,6 +998,7 @@ nonReserved
| LOCATION
| LOCK
| LOGICAL
| MANUAL
| MAP
| MATERIALIZED
| MAX
Expand Down Expand Up @@ -1033,6 +1074,7 @@ nonReserved
| ROUTINE
| S3
| SAMPLE
| SCHEDULE
| SCHEDULER
| SCHEMA
| SECOND
Expand Down
43 changes: 43 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.mtmv;

import com.google.gson.annotations.SerializedName;

/**
* EnvInfo
*/
public class EnvInfo {
@SerializedName("cn")
private String ctlName;
@SerializedName("dn")
private String dbName;

public EnvInfo(String ctlName, String dbName) {
this.ctlName = ctlName;
this.dbName = dbName;
}

public String getCtlName() {
return ctlName;
}

public String getDbName() {
return dbName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.mtmv;

/**
* refresh enum
*/
public class MTMVRefreshEnum {

/**
* RefreshMethod
*/
public enum RefreshMethod {
COMPLETE //complete
}

/**
* BuildMode
*/
public enum BuildMode {
IMMEDIATE, //right now
DEFERRED // deferred
}

/**
* RefreshTrigger
*/
public enum RefreshTrigger {
MANUAL, //manual
SCHEDULE // schedule
}

/**
* MTMVState
*/
public enum MTMVState {
INIT,
NORMAL,
SCHEMA_CHANGE
}

/**
* MTMVRefreshState
*/
public enum MTMVRefreshState {
INIT,
REFRESHING,
FAIL,
SUCCESS
}
}
109 changes: 109 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// 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.mtmv;

import org.apache.doris.mtmv.MTMVRefreshEnum.BuildMode;
import org.apache.doris.mtmv.MTMVRefreshEnum.RefreshMethod;

import com.google.gson.annotations.SerializedName;

import java.util.Objects;

/**
* refresh info
*/
public class MTMVRefreshInfo {
@SerializedName("bm")
private BuildMode buildMode;
@SerializedName("rm")
private RefreshMethod refreshMethod;
@SerializedName("rti")
private MTMVRefreshTriggerInfo refreshTriggerInfo;

public MTMVRefreshInfo() {
}

public MTMVRefreshInfo(BuildMode buildMode,
RefreshMethod refreshMethod,
MTMVRefreshTriggerInfo refreshTriggerInfo) {
this.buildMode = Objects.requireNonNull(buildMode, "require buildMode object");
this.refreshMethod = Objects.requireNonNull(refreshMethod, "require refreshMethod object");
this.refreshTriggerInfo = Objects.requireNonNull(refreshTriggerInfo, "require refreshTriggerInfo object");
}

public void validate() {
if (refreshTriggerInfo != null) {
refreshTriggerInfo.validate();
}
}

public BuildMode getBuildMode() {
return buildMode;
}

public RefreshMethod getRefreshMethod() {
return refreshMethod;
}

public MTMVRefreshTriggerInfo getRefreshTriggerInfo() {
return refreshTriggerInfo;
}

public void setBuildMode(BuildMode buildMode) {
this.buildMode = buildMode;
}

public void setRefreshMethod(RefreshMethod refreshMethod) {
this.refreshMethod = refreshMethod;
}

public void setRefreshTriggerInfo(
MTMVRefreshTriggerInfo refreshTriggerInfo) {
this.refreshTriggerInfo = refreshTriggerInfo;
}

/**
* update refreshInfo
*/
public MTMVRefreshInfo updateNotNull(MTMVRefreshInfo newRefreshInfo) {
Objects.requireNonNull(newRefreshInfo);
if (newRefreshInfo.buildMode != null) {
this.buildMode = newRefreshInfo.buildMode;
}
if (newRefreshInfo.refreshMethod != null) {
this.refreshMethod = newRefreshInfo.refreshMethod;
}
if (newRefreshInfo.refreshTriggerInfo != null) {
this.refreshTriggerInfo = newRefreshInfo.refreshTriggerInfo;
}
return this;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("BUILD ");
builder.append(buildMode);
builder.append(" REFRESH ");
builder.append(refreshMethod);
builder.append(" ");
builder.append(refreshTriggerInfo);
return builder.toString();
}

}
Loading

0 comments on commit 61edb9e

Please sign in to comment.