snuyanzin commented on code in PR #27843: URL: https://github.com/apache/flink/pull/27843#discussion_r3001359718
########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/materializedtable/SqlStartMode.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.flink.sql.parser.ddl; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.sql.parser.SqlParseUtils; + +import org.apache.calcite.sql.SqlIntervalLiteral; +import org.apache.calcite.sql.SqlLiteral; +import org.apache.calcite.sql.SqlTimestampLiteral; +import org.apache.calcite.sql.SqlUnknownLiteral; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.sql.type.SqlTypeName; + +import javax.annotation.Nullable; + +/** Start mode configuration for materialized tables. */ +@Internal +public class SqlStartMode { + private final SqlStartModeKind kind; + private final @Nullable SqlTimestampLiteral timestampLiteral; + private final @Nullable SqlIntervalLiteral intervalLiteral; + + public SqlStartModeKind getKind() { + return kind; + } + + @Nullable + public SqlTimestampLiteral getTimestampLiteral() { + return timestampLiteral; + } + + @Nullable + public SqlIntervalLiteral getIntervalLiteral() { + return intervalLiteral; + } + + public enum SqlStartModeKind { + FROM_BEGINNING, + FROM_NOW, + FROM_TIMESTAMP, + RESUME_OR_FROM_BEGINNING, + RESUME_OR_FROM_NOW, + RESUME_OR_FROM_TIMESTAMP; + + /** + * Creates a parse-tree node representing an occurrence of this keyword at a particular + * position in the parsed text. + */ + public SqlLiteral symbol(SqlParserPos pos) { + return SqlLiteral.createSymbol(this, pos); + } + + public boolean isFromNow() { + return this == FROM_NOW || this == RESUME_OR_FROM_NOW; + } + + public boolean isFromTimestamp() { + return this == FROM_TIMESTAMP || this == RESUME_OR_FROM_TIMESTAMP; + } + + public boolean isCreateOrAlterOption() { + return this == RESUME_OR_FROM_BEGINNING + || this == RESUME_OR_FROM_NOW + || this == RESUME_OR_FROM_TIMESTAMP; + } + } + + public SqlStartMode(SqlLiteral kind, @Nullable SqlLiteral literal, SqlParserPos pos) { + this.kind = SqlParseUtils.extractEnum(kind, SqlStartModeKind.class); + if (literal == null) { + this.intervalLiteral = null; + this.timestampLiteral = null; + } else if (literal instanceof SqlIntervalLiteral) { + this.intervalLiteral = (SqlIntervalLiteral) literal; + this.timestampLiteral = null; + } else { + this.intervalLiteral = null; + + final SqlUnknownLiteral unknownLiteral = (SqlUnknownLiteral) literal; + this.timestampLiteral = + (SqlTimestampLiteral) + unknownLiteral.resolve(SqlTypeName.lookup(unknownLiteral.tag)); + } Review Comment: `literal` is not a type of `SqlTimestampLiteral` however the result of `unknownLiteral.resolve(...)` is a type of `SqlTimestampLiteral` in this case -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
