-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from burhanxz/feature/support_create_filestorage
Feature/support create filestorage
- Loading branch information
Showing
36 changed files
with
750 additions
and
75 deletions.
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
49 changes: 49 additions & 0 deletions
49
polardbx-calcite/src/main/java/org/apache/calcite/rel/ddl/CreateFileStorage.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,49 @@ | ||
package org.apache.calcite.rel.ddl; | ||
|
||
import org.apache.calcite.plan.Convention; | ||
import org.apache.calcite.plan.RelOptCluster; | ||
import org.apache.calcite.plan.RelTraitSet; | ||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.core.DDL; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.sql.SqlDdl; | ||
import org.apache.calcite.sql.SqlIdentifier; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CreateFileStorage extends DDL { | ||
private final String engineName; | ||
private final Map<String, String> with; | ||
|
||
protected CreateFileStorage(RelOptCluster cluster, RelTraitSet traits, SqlDdl ddl, | ||
RelDataType rowType, String engineName, Map<String, String> with) { | ||
super(cluster, traits, ddl, rowType); | ||
this.engineName = engineName; | ||
this.with = with; | ||
this.sqlNode = ddl; | ||
this.setTableName(new SqlIdentifier(engineName, SqlParserPos.ZERO)); | ||
} | ||
|
||
public static CreateFileStorage create(RelOptCluster cluster, RelTraitSet traits, SqlDdl ddl, | ||
RelDataType rowType, String engineName, Map<String, String> with) { | ||
|
||
return new CreateFileStorage(cluster, traits, ddl, rowType, engineName, with); | ||
} | ||
|
||
@Override | ||
public CreateFileStorage copy( | ||
RelTraitSet traitSet, List<RelNode> inputs) { | ||
assert traitSet.containsIfApplicable(Convention.NONE); | ||
return new CreateFileStorage(this.getCluster(), traitSet, this.ddl, rowType, engineName, with); | ||
} | ||
|
||
public String getEngineName() { | ||
return engineName; | ||
} | ||
|
||
public Map<String, String> getWith() { | ||
return with; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlCreateFileStorage.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 @@ | ||
package org.apache.calcite.sql; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
import org.apache.calcite.rel.type.RelDataTypeField; | ||
import org.apache.calcite.rel.type.RelDataTypeFieldImpl; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.apache.calcite.sql.validate.SqlValidator; | ||
import org.apache.calcite.sql.validate.SqlValidatorScope; | ||
import org.apache.calcite.util.Pair; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SqlCreateFileStorage extends SqlDdl { | ||
private static final SqlOperator OPERATOR = new SqlCreateFileStorageOperator(); | ||
|
||
private SqlIdentifier engineName; | ||
private List<Pair<SqlIdentifier, SqlIdentifier>> with; | ||
|
||
public SqlCreateFileStorage(SqlParserPos pos, | ||
SqlIdentifier engineName, | ||
List<Pair<SqlIdentifier, SqlIdentifier>> with) { | ||
super(OPERATOR, pos); | ||
this.engineName = engineName; | ||
this.with = with; | ||
} | ||
|
||
public SqlIdentifier getEngineName() { | ||
return engineName; | ||
} | ||
|
||
public SqlCreateFileStorage setEngineName(SqlIdentifier engineName) { | ||
this.engineName = engineName; | ||
return this; | ||
} | ||
|
||
public List<Pair<SqlIdentifier, SqlIdentifier>> getWith() { | ||
return with; | ||
} | ||
|
||
public Map<String, String> getWithValue() { | ||
Map<String, String> map = new HashMap<>(); | ||
for (Pair<SqlIdentifier, SqlIdentifier> pair : with) { | ||
map.put(pair.left.toString().toUpperCase(), pair.right.toString()); | ||
} | ||
return map; | ||
} | ||
|
||
public SqlCreateFileStorage setWith( | ||
List<Pair<SqlIdentifier, SqlIdentifier>> with) { | ||
this.with = with; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<SqlNode> getOperandList() { | ||
return ImmutableList.of(); | ||
} | ||
|
||
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.SELECT, "CREATE FILESTORAGE", ""); | ||
|
||
engineName.unparse(writer, leftPrec, rightPrec); | ||
|
||
final SqlWriter.Frame withFrame = writer.startList(SqlWriter.FrameTypeEnum.SELECT, " WITH (", ")"); | ||
|
||
for (Pair<SqlIdentifier, SqlIdentifier> pair : with) { | ||
pair.left.unparse(writer, leftPrec, rightPrec); | ||
writer.sep("="); | ||
pair.right.unparse(writer, leftPrec, rightPrec); | ||
} | ||
|
||
writer.endList(withFrame); | ||
|
||
writer.endList(frame); | ||
} | ||
|
||
public static class SqlCreateFileStorageOperator extends SqlSpecialOperator { | ||
|
||
public SqlCreateFileStorageOperator(){ | ||
super("CREATE FILESTORAGE", SqlKind.CREATE_FILESTORAGE); | ||
} | ||
|
||
@Override | ||
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { | ||
final RelDataTypeFactory typeFactory = validator.getTypeFactory(); | ||
final RelDataType columnType = typeFactory.createSqlType(SqlTypeName.CHAR); | ||
|
||
return typeFactory.createStructType(ImmutableList.of((RelDataTypeField) new RelDataTypeFieldImpl("CREATE FILESTORAGE RESULT", | ||
0, columnType))); | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.