forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-14841][table] add create and drop function ddl in SQL parser
this closes apache#10240.
- Loading branch information
1 parent
beba9dc
commit 679398c
Showing
5 changed files
with
337 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...ble/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* 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.sql.parser.ExtendedSqlNode; | ||
import org.apache.flink.sql.parser.error.SqlValidateException; | ||
|
||
import org.apache.calcite.sql.SqlCharStringLiteral; | ||
import org.apache.calcite.sql.SqlCreate; | ||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlOperator; | ||
import org.apache.calcite.sql.SqlSpecialOperator; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.util.ImmutableNullableList; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* CREATE FUNCTION DDL sql call. | ||
*/ | ||
public class SqlCreateFunction extends SqlCreate implements ExtendedSqlNode { | ||
|
||
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE FUNCTION", SqlKind.CREATE_FUNCTION); | ||
|
||
private final SqlIdentifier functionIdentifier; | ||
|
||
private final SqlCharStringLiteral functionClassName; | ||
|
||
private final String functionLanguage; | ||
|
||
private final boolean isTemporary; | ||
|
||
private final boolean isSystemFunction; | ||
|
||
public SqlCreateFunction( | ||
SqlParserPos pos, | ||
SqlIdentifier functionIdentifier, | ||
SqlCharStringLiteral functionClassName, | ||
String functionLanguage, | ||
boolean ifNotExists, | ||
boolean isTemporary, | ||
boolean isSystemFunction) { | ||
super(OPERATOR, pos, false, ifNotExists); | ||
this.functionIdentifier = requireNonNull(functionIdentifier); | ||
this.functionClassName = requireNonNull(functionClassName); | ||
this.isSystemFunction = requireNonNull(isSystemFunction); | ||
this.isTemporary = isTemporary; | ||
this.functionLanguage = functionLanguage; | ||
} | ||
|
||
@Override | ||
public SqlOperator getOperator() { | ||
return OPERATOR; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public List<SqlNode> getOperandList() { | ||
return ImmutableNullableList.of(functionIdentifier, functionClassName); | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
writer.keyword("CREATE"); | ||
if (isTemporary) { | ||
writer.keyword("TEMPORARY"); | ||
} | ||
if (isSystemFunction) { | ||
writer.keyword("SYSTEM"); | ||
} | ||
writer.keyword("FUNCTION"); | ||
if (ifNotExists) { | ||
writer.keyword("IF NOT EXISTS"); | ||
} | ||
functionIdentifier.unparse(writer, leftPrec, rightPrec); | ||
writer.keyword("AS"); | ||
functionClassName.unparse(writer, leftPrec, rightPrec); | ||
if (functionLanguage != null) { | ||
writer.keyword("LANGUAGE"); | ||
writer.keyword(functionLanguage); | ||
} | ||
} | ||
|
||
@Override | ||
public void validate() throws SqlValidateException { | ||
// no-op | ||
} | ||
|
||
public boolean isIfNotExists() { | ||
return ifNotExists; | ||
} | ||
|
||
public boolean isSystemFunction() { | ||
return isSystemFunction; | ||
} | ||
|
||
public SqlCharStringLiteral getFunctionClassName() { | ||
return this.functionClassName; | ||
} | ||
|
||
public String getFunctionLanguage() { | ||
return this.functionLanguage; | ||
} | ||
|
||
public String[] getFunctionIdentifier() { | ||
return functionIdentifier.names.toArray(new String[0]); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlDropFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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.sql.parser.ExtendedSqlNode; | ||
import org.apache.flink.sql.parser.error.SqlValidateException; | ||
|
||
import org.apache.calcite.sql.SqlDrop; | ||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlSpecialOperator; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.util.ImmutableNullableList; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* DROP FUNCTION DDL sql call. | ||
*/ | ||
public class SqlDropFunction extends SqlDrop implements ExtendedSqlNode { | ||
|
||
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("DROP FUNCTION", SqlKind.DROP_FUNCTION); | ||
|
||
private final SqlIdentifier functionIdentifier; | ||
|
||
private final boolean isTemporary; | ||
|
||
private final boolean isSystemFunction; | ||
|
||
public SqlDropFunction( | ||
SqlParserPos pos, | ||
SqlIdentifier functionIdentifier, | ||
boolean ifExists, | ||
boolean isTemporary, | ||
boolean isSystemFunction) { | ||
super(OPERATOR, pos, ifExists); | ||
this.functionIdentifier = requireNonNull(functionIdentifier); | ||
this.isSystemFunction = requireNonNull(isSystemFunction); | ||
this.isTemporary = isTemporary; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public List<SqlNode> getOperandList() { | ||
return ImmutableNullableList.of(functionIdentifier); | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
writer.keyword("DROP"); | ||
if (isTemporary) { | ||
writer.keyword("TEMPORARY"); | ||
} | ||
if (isSystemFunction) { | ||
writer.keyword("SYSTEM"); | ||
} | ||
writer.keyword("FUNCTION"); | ||
if (ifExists) { | ||
writer.keyword("IF EXISTS"); | ||
} | ||
functionIdentifier.unparse(writer, leftPrec, rightPrec); | ||
} | ||
|
||
@Override | ||
public void validate() throws SqlValidateException { | ||
// no-op | ||
} | ||
|
||
public String[] getFunctionIdentifier() { | ||
return functionIdentifier.names.toArray(new String[0]); | ||
} | ||
|
||
public boolean getIfExists() { | ||
return this.ifExists; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters