Skip to content

Commit

Permalink
Merge pull request #42 from Functor10/master
Browse files Browse the repository at this point in the history
Add qsql 0.6 related features.
  • Loading branch information
Functor10 authored Mar 6, 2019
2 parents a257be1 + 57425d1 commit a9706f9
Show file tree
Hide file tree
Showing 110 changed files with 2,617 additions and 1,278 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ nbbuild/
nbdist/
.nb-gradle/

/log/
### Sqlite ###
*-journal

/log/

2 changes: 1 addition & 1 deletion analysis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
<parent>
<groupId>com.qihoo.qsql</groupId>
<artifactId>qsql</artifactId>
<version>0.5</version>
<version>0.6</version>
</parent>

<artifactId>qsql-calcite-analysis</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion analysis/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ data: {
statementParserMethods: [
"SqlShowTables()",
"SqlShowSchemas()",
"SqlUseSchema()"
"SqlUseSchema()",
"SqlInsertOutput()"
]

# List of methods for parsing custom literals.
Expand Down
39 changes: 39 additions & 0 deletions analysis/src/main/codegen/includes/parserImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,42 @@ SqlNode SqlUseSchema():
}
}

SqlNode SqlInsertOutput():
{
SqlParserPos pos;
SqlNode position;
SqlNodeList extendList = null;
SqlNodeList columnList = null;
SqlIdentifier dataSource;
SqlNode select;
}
{
<INSERT> { pos = getPos(); }
<INTO> position = CompoundIdentifier()
[
LOOKAHEAD(5)
[ <EXTEND> ]
extendList = ExtendList() {
position = extend(position, extendList);
}
]
[
LOOKAHEAD(2)
{ final Pair<SqlNodeList, SqlNodeList> p; }
p = ParenthesizedCompoundIdentifierList() {
if (p.right.size() > 0) {
position = extend(position, p.right);
}
if (p.left.size() > 0) {
columnList = p.left;
}
}
]

<IN> dataSource = CompoundIdentifier()
select = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
{
return new SqlInsertOutput(pos, position, dataSource, columnList, select);
}
}

14 changes: 10 additions & 4 deletions analysis/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,6 @@ SqlNode SqlStmt() :
stmt = SqlExplain()
|
stmt = SqlDescribe()
|
stmt = SqlInsert()
|
stmt = SqlDelete()
|
Expand All @@ -984,6 +982,11 @@ SqlNode SqlStmt() :
}
}

/**
* Updated by qsql-team
* | stmt = SqlInsert()
*/

/**
* Parses an SQL statement followed by the end-of-file symbol.
*/
Expand Down Expand Up @@ -1102,6 +1105,11 @@ SqlNode SqlExplain() :
}
}

/**
* Updated by qsql-team
* | stmt = SqlInsert()
*/

/** Parses a query (SELECT or VALUES)
* or DML statement (INSERT, UPDATE, DELETE, MERGE). */
SqlNode SqlQueryOrDml() :
Expand All @@ -1111,8 +1119,6 @@ SqlNode SqlQueryOrDml() :
{
(
stmt = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
|
stmt = SqlInsert()
|
stmt = SqlDelete()
|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.apache.calcite.adapter.mysql;

import org.apache.calcite.schema.impl.AbstractSchema;

//TODO reduce all of default schemas like this which has no field and param
public class MySQLSchema extends AbstractSchema {
public MySQLSchema() {}
}
package org.apache.calcite.adapter.custom;

import org.apache.calcite.schema.impl.AbstractSchema;

//TODO reduce all of default schemas like this which has no field and param
public class JdbcSchema extends AbstractSchema {
public JdbcSchema() {}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.apache.calcite.adapter.mysql;

import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.SchemaFactory;
import org.apache.calcite.schema.SchemaPlus;

import java.util.Map;

public class MySQLSchemaFactory implements SchemaFactory {

public static final MySQLSchemaFactory INSTANCE = new MySQLSchemaFactory();

private MySQLSchemaFactory() {}

@Override
public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) {
return new MySQLSchema();
}
}
package org.apache.calcite.adapter.custom;

import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.SchemaFactory;
import org.apache.calcite.schema.SchemaPlus;

import java.util.Map;

public class JdbcSchemaFactory implements SchemaFactory {

public static final JdbcSchemaFactory INSTANCE = new JdbcSchemaFactory();

private JdbcSchemaFactory() {}

@Override
public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) {
return new JdbcSchema();
}
}
Original file line number Diff line number Diff line change
@@ -1,63 +1,67 @@
package org.apache.calcite.adapter.mysql;

import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.schema.impl.AbstractTable;

import java.util.Properties;

public class MySQLTable extends AbstractTable implements TranslatableTable {
public final String jdbcDriver;
public final String jdbcUrl;
public final String jdbcUser;
public final String jdbcPassword;
public final String tableName;
public final String modelUri;
public final String dbName;

public Properties properties;

public Properties getProperties() {
return properties;
}

MySQLTable(String tableName, String dbName,
String driver, String url, String user,
String password, String modelUri) {
this.modelUri = modelUri;
this.jdbcDriver = driver;
this.jdbcUrl = url;
this.jdbcUser = user;
this.jdbcPassword = password;
this.tableName = tableName;
this.dbName = dbName;

this.properties = new Properties();
properties.put("jdbcDriver", driver);
properties.put("jdbcUrl", url);
properties.put("jdbcUser", user);
properties.put("jdbcPassword", password);
properties.put("tableName", tableName);
properties.put("dbName", dbName);
}

@Override
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
final RelOptCluster cluster = context.getCluster();
return new MySQLTableScan(cluster, cluster.traitSet(), relOptTable);
}

@Override
public String getBaseName() {
return dbName;
}

@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
return super.getRowType(modelUri, dbName, tableName, typeFactory);
}
}
package org.apache.calcite.adapter.custom;

import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.schema.impl.AbstractTable;

import java.util.Properties;

public class JdbcTable extends AbstractTable implements TranslatableTable {
public final String jdbcDriver;
public final String jdbcUrl;
public final String jdbcUser;
public final String jdbcPassword;
public final String tableName;
public final String modelUri;
public final String dbName;
public final String dbType;


public Properties properties;

public Properties getProperties() {
return properties;
}

JdbcTable(String tableName, String dbName,
String driver, String url, String user,
String password, String modelUri, String dbType) {
this.modelUri = modelUri;
this.jdbcDriver = driver;
this.jdbcUrl = url;
this.jdbcUser = user;
this.jdbcPassword = password;
this.tableName = tableName;
this.dbName = dbName;
this.dbType = dbType;

this.properties = new Properties();
properties.put("jdbcDriver", driver);
properties.put("jdbcUrl", url);
properties.put("jdbcUser", user);
properties.put("jdbcPassword", password);
properties.put("tableName", tableName);
properties.put("dbName", dbName);
properties.put("dbType", dbType);
}

@Override
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
final RelOptCluster cluster = context.getCluster();
return new JdbcTableScan(cluster, cluster.traitSet(), relOptTable);
}

@Override
public String getBaseName() {
return dbName;
}

@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
return super.getRowType(modelUri, dbName, tableName, typeFactory);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package org.apache.calcite.adapter.mysql;

import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.TableFactory;

import java.util.Map;

public class MySQLTableFactory implements TableFactory {

@Override
public Table create(SchemaPlus schema, String name, Map operand, RelDataType rowType) {
String tableName = operand.get("tableName").toString();
String dbName = operand.get("dbName").toString();
String jdbcUrl = operand.get("jdbcUrl").toString();
String jdbcUser = operand.get("jdbcUser").toString();
String jdbcPassword = operand.get("jdbcPassword").toString();
String jdbcDriver = operand.get("jdbcDriver").toString();
String modelUri = operand.get("modelUri").toString();

return new MySQLTable(tableName, dbName,
jdbcDriver, jdbcUrl,
jdbcUser, jdbcPassword,
modelUri);
}
package org.apache.calcite.adapter.custom;

import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.TableFactory;

import java.util.Map;

public class JdbcTableFactory implements TableFactory {

@Override
public Table create(SchemaPlus schema, String name, Map operand, RelDataType rowType) {
String tableName = operand.get("tableName").toString();
String dbName = operand.get("dbName").toString();
String jdbcUrl = operand.get("jdbcUrl").toString();
String jdbcUser = operand.get("jdbcUser").toString();
String jdbcPassword = operand.get("jdbcPassword").toString();
String jdbcDriver = operand.get("jdbcDriver").toString();
String modelUri = operand.get("modelUri").toString();
String dbType = operand.get("dbType").toString();

return new JdbcTable(tableName, dbName,
jdbcDriver, jdbcUrl,
jdbcUser, jdbcPassword,
modelUri, dbType);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.apache.calcite.adapter.mysql;

import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.core.TableScan;

public class MySQLTableScan extends TableScan {

protected MySQLTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table) {
super(cluster, traitSet, table);
}
}
package org.apache.calcite.adapter.custom;

import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.core.TableScan;

public class JdbcTableScan extends TableScan {

protected JdbcTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table) {
super(cluster, traitSet, table);
}
}
Loading

0 comments on commit a9706f9

Please sign in to comment.