Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -41,7 +42,17 @@
public class SqlPartitionSpecProperty extends SqlCall {

/** Use this operator only if you don't have a better one. */
protected static final SqlOperator OPERATOR = new SqlSpecialOperator("Pair", SqlKind.OTHER);
protected static final SqlOperator OPERATOR =
new SqlSpecialOperator("Pair", SqlKind.OTHER) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlPartitionSpecProperty(
(SqlIdentifier) operands[0],
operands.length > 1 ? operands[1] : null,
pos);
}
};

private final SqlIdentifier key;
private final @Nullable SqlNode value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -38,7 +39,14 @@
public class SqlProperty extends SqlCall {

/** Use this operator only if you don't have a better one. */
protected static final SqlOperator OPERATOR = new SqlSpecialOperator("Property", SqlKind.OTHER);
protected static final SqlOperator OPERATOR =
new SqlSpecialOperator("Property", SqlKind.OTHER) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlProperty((SqlIdentifier) operands[0], operands[1], pos);
}
};

private final SqlIdentifier key;
private final SqlNode value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package org.apache.flink.sql.parser.ddl;

import org.apache.calcite.sql.SqlAlter;
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlCharStringLiteral;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -34,7 +36,14 @@
/** Add Jar command to add jar into the classloader. */
public class SqlAddJar extends SqlAlter {

public static final SqlOperator OPERATOR = new SqlSpecialOperator("ADD JAR", SqlKind.OTHER_DDL);
public static final SqlOperator OPERATOR =
new SqlSpecialOperator("ADD JAR", SqlKind.OTHER_DDL) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlAddJar(pos, (SqlCharStringLiteral) operands[0]);
}
};

private final SqlCharStringLiteral jarPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
import org.apache.flink.sql.parser.SqlParseUtils;
import org.apache.flink.sql.parser.ddl.table.SqlAlterTable;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
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;

Expand All @@ -36,6 +41,28 @@
/** ALTER TABLE DDL to add partitions to a table. */
public class SqlAddPartitions extends SqlAlterTable {

private static final SqlSpecialOperator ADD_PARTITION_OPERATOR =
new SqlSpecialOperator("ALTER TABLE ADD PARTITION", SqlKind.ALTER_TABLE) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
List<SqlNodeList> partSpecs = new ArrayList<>();
for (SqlNode spec : (SqlNodeList) operands[2]) {
partSpecs.add((SqlNodeList) spec);
}
List<SqlNodeList> partProps = new ArrayList<>();
for (SqlNode prop : (SqlNodeList) operands[3]) {
partProps.add((SqlNodeList) prop);
}
return new SqlAddPartitions(
pos,
(SqlIdentifier) operands[0],
((SqlLiteral) operands[1]).booleanValue(),
partSpecs,
partProps);
}
};

private final boolean ifPartitionNotExists;
private final List<SqlNodeList> partSpecs;
private final List<SqlNodeList> partProps;
Expand Down Expand Up @@ -68,14 +95,19 @@ public List<SqlNodeList> getPartProps() {
return partProps;
}

@Override
public SqlOperator getOperator() {
return ADD_PARTITION_OPERATOR;
}

@Nonnull
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> operands = new ArrayList<>();
operands.add(tableIdentifier);
operands.addAll(partSpecs);
operands.addAll(partProps);
return operands;
return List.of(
tableIdentifier,
SqlLiteral.createBoolean(ifPartitionNotExists, SqlParserPos.ZERO),
new SqlNodeList(partSpecs, SqlParserPos.ZERO),
new SqlNodeList(partProps, SqlParserPos.ZERO));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import org.apache.flink.sql.parser.SqlParseUtils;
import org.apache.flink.sql.parser.SqlUnparseUtils;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.SqlOperator;
Expand All @@ -40,7 +42,14 @@
public class SqlAlterDatabase extends SqlAlterObject {

public static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("ALTER DATABASE", SqlKind.OTHER_DDL);
new SqlSpecialOperator("ALTER DATABASE", SqlKind.OTHER_DDL) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlAlterDatabase(
pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1]);
}
};

private final SqlNodeList propertyList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

import org.apache.flink.sql.parser.SqlUnparseUtils;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlCharStringLiteral;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlSpecialOperator;
import org.apache.calcite.sql.SqlWriter;
Expand All @@ -39,7 +41,24 @@
public class SqlAlterFunction extends SqlAlterObject {

public static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("ALTER FUNCTION", SqlKind.OTHER_DDL);
new SqlSpecialOperator("ALTER FUNCTION", SqlKind.OTHER_DDL) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
String language =
operands[2] instanceof SqlCharStringLiteral
? ((SqlCharStringLiteral) operands[2]).getValueAs(String.class)
: null;
return new SqlAlterFunction(
pos,
(SqlIdentifier) operands[0],
(SqlCharStringLiteral) operands[1],
language,
((SqlLiteral) operands[3]).booleanValue(),
((SqlLiteral) operands[4]).booleanValue(),
((SqlLiteral) operands[5]).booleanValue());
}
};

private final SqlCharStringLiteral functionClassName;

Expand Down Expand Up @@ -79,7 +98,15 @@ public void unparseAlterOperation(SqlWriter writer, int leftPrec, int rightPrec)
@Nonnull
@Override
public List<SqlNode> getOperandList() {
return ImmutableNullableList.of(name, functionClassName);
return ImmutableNullableList.of(
name,
functionClassName,
functionLanguage == null
? SqlLiteral.createNull(SqlParserPos.ZERO)
: SqlLiteral.createCharString(functionLanguage, SqlParserPos.ZERO),
SqlLiteral.createBoolean(ifExists, SqlParserPos.ZERO),
SqlLiteral.createBoolean(isTemporary, SqlParserPos.ZERO),
SqlLiteral.createBoolean(isSystemFunction, SqlParserPos.ZERO));
}

public String getFunctionLanguage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -33,7 +34,6 @@

import javax.annotation.Nonnull;

import java.util.Collections;
import java.util.List;

/**
Expand All @@ -44,7 +44,17 @@
public class SqlCompilePlan extends SqlCall {

public static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("COMPILE PLAN", SqlKind.OTHER);
new SqlSpecialOperator("COMPILE PLAN", SqlKind.OTHER) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlCompilePlan(
pos,
operands[1],
((SqlLiteral) operands[2]).booleanValue(),
operands[0]);
}
};

private final SqlNode planFile;
private final boolean ifNotExists;
Expand Down Expand Up @@ -75,7 +85,7 @@ public SqlOperator getOperator() {
@Nonnull
@Override
public List<SqlNode> getOperandList() {
return Collections.singletonList(operand);
return List.of(operand, planFile, SqlLiteral.createBoolean(ifNotExists, SqlParserPos.ZERO));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

package org.apache.flink.sql.parser.ddl;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlCharStringLiteral;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -35,7 +37,18 @@
public class SqlCreateDatabase extends SqlCreateObject {

public static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("CREATE DATABASE", SqlKind.OTHER_DDL);
new SqlSpecialOperator("CREATE DATABASE", SqlKind.OTHER_DDL) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlCreateDatabase(
pos,
(SqlIdentifier) operands[0],
(SqlNodeList) operands[1],
(SqlCharStringLiteral) operands[2],
((SqlLiteral) operands[3]).booleanValue());
}
};

public SqlCreateDatabase(
SqlParserPos pos,
Expand All @@ -49,7 +62,11 @@ public SqlCreateDatabase(

@Override
public List<SqlNode> getOperandList() {
return ImmutableNullableList.of(name, properties, comment);
return ImmutableNullableList.of(
name,
properties,
comment,
SqlLiteral.createBoolean(isIfNotExists(), SqlParserPos.ZERO));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

import org.apache.flink.sql.parser.SqlUnparseUtils;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlCharStringLiteral;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -40,7 +42,26 @@
public class SqlCreateFunction extends SqlCreateObject {

private static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("CREATE FUNCTION", SqlKind.CREATE_FUNCTION);
new SqlSpecialOperator("CREATE FUNCTION", SqlKind.CREATE_FUNCTION) {
@Override
public SqlCall createCall(
SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
String language =
operands[4] instanceof SqlCharStringLiteral
? ((SqlCharStringLiteral) operands[4]).getValueAs(String.class)
: null;
return new SqlCreateFunction(
pos,
(SqlIdentifier) operands[0],
(SqlCharStringLiteral) operands[1],
language,
((SqlLiteral) operands[5]).booleanValue(),
((SqlLiteral) operands[6]).booleanValue(),
((SqlLiteral) operands[7]).booleanValue(),
(SqlNodeList) operands[2],
(SqlNodeList) operands[3]);
}
};

private final SqlCharStringLiteral functionClassName;
private final String functionLanguage;
Expand Down Expand Up @@ -76,7 +97,17 @@ public SqlCreateFunction(
@Nonnull
@Override
public List<SqlNode> getOperandList() {
return ImmutableNullableList.of(name, functionClassName, resourceInfos);
return ImmutableNullableList.of(
name,
functionClassName,
resourceInfos,
properties,
functionLanguage == null
? SqlLiteral.createNull(SqlParserPos.ZERO)
: SqlLiteral.createCharString(functionLanguage, SqlParserPos.ZERO),
SqlLiteral.createBoolean(isIfNotExists(), SqlParserPos.ZERO),
SqlLiteral.createBoolean(isTemporary(), SqlParserPos.ZERO),
SqlLiteral.createBoolean(isSystemFunction, SqlParserPos.ZERO));
}

public boolean isSystemFunction() {
Expand Down
Loading