Skip to content

Commit

Permalink
Merge branch 'master' into txsql
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Sep 30, 2024
2 parents 90f4aba + 03bbc2d commit c118f60
Show file tree
Hide file tree
Showing 96 changed files with 8,309 additions and 5,938 deletions.
3 changes: 2 additions & 1 deletion docs/_docs/monitoring-metrics/system-views.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,9 @@ This view exposes information about SQL views.
[{table_opts}]
|===
|NAME | TYPE | DESCRIPTION
|NAME | string | Name
|SCHEMA | string | Schema
|NAME | string | Name
|SQL | string | SQL query for view
|DESCRIPTION | string | Description
|===

Expand Down
60 changes: 60 additions & 0 deletions docs/_docs/sql-reference/ddl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,66 @@ DROP INDEX idx_person_name;
----


== CREATE VIEW

Creates an user definded SQL view.


[source,sql]
----
CREATE [OR REPLACE] VIEW [schemaName.]viewName AS query
----

Parameters:

* `schemaName` - the name of the schema, where to create view.
* `viewName` - the name of the view to create.
* `OR REPLACE` - replace view if a view with the specified name already exists.
* `query` - valid SQL query.

Schema changes applied by this command are persisted on disk if link:persistence/native-persistence[Ignite persistence] is enabled. Thus, the changes can survive full cluster restarts.

[discrete]
=== Examples
Create a view:


[source,sql]
----
CREATE VIEW adult AS SELECT * FROM person WHERE age >= 18;
----


== DROP VIEW

Deletes an existing user defined SQL view.


[source,sql]
----
DROP VIEW [IF EXISTS] [schemaName.]viewName
----

Parameters:

* `schemaName` - the schema of the view to drop.
* `viewName` - the name of the view to drop.
* `IF EXISTS` - do not throw an error if a view with the specified name does not exist.

Schema changes applied by this command are persisted on disk if link:persistence/native-persistence[Ignite persistence] is enabled. Thus, the changes can survive full cluster restarts.


[discrete]
=== Examples
Drop a view:


[source,sql]
----
DROP VIEW adult;
----


== CREATE USER

The command creates a user with a given name and password.
Expand Down
2 changes: 1 addition & 1 deletion modules/calcite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<checker.version>3.10.0</checker.version>
<failureaccess.version>1.0.1</failureaccess.version>
<immutables.version>2.8.2</immutables.version>
<janino.version>3.1.8</janino.version>
<janino.version>3.1.12</janino.version>
<javacc-maven-plugin>2.4</javacc-maven-plugin>
<jsonpath.version>2.9.0</jsonpath.version>
<reflections.version>0.10.2</reflections.version>
Expand Down
6 changes: 4 additions & 2 deletions modules/calcite/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ data: {
createStatementParserMethods: [
"SqlCreateTable",
"SqlCreateIndex",
"SqlCreateUser"
"SqlCreateUser",
"SqlCreateView"
]

# List of methods for parsing extensions to "DROP" calls.
Expand All @@ -459,7 +460,8 @@ data: {
dropStatementParserMethods: [
"SqlDropTable",
"SqlDropIndex",
"SqlDropUser"
"SqlDropUser",
"SqlDropView"
]

# List of methods for parsing extensions to "ALTER <scope>" calls.
Expand Down
38 changes: 38 additions & 0 deletions modules/calcite/src/main/codegen/includes/parserImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ SqlCreate SqlCreateTable(Span s, boolean replace) :
final SqlNode query;
}
{
{
if (replace)
throw SqlUtil.newContextException(getPos(), IgniteResource.INSTANCE.unsupportedClause("REPLACE"));
}

<TABLE>
ifNotExists = IfNotExistsOpt()
id = CompoundIdentifier()
Expand Down Expand Up @@ -258,6 +263,11 @@ SqlCreate SqlCreateIndex(Span s, boolean replace) :
SqlNumericLiteral inlineSize = null;
}
{
{
if (replace)
throw SqlUtil.newContextException(getPos(), IgniteResource.INSTANCE.unsupportedClause("REPLACE"));
}

<INDEX>
ifNotExists = IfNotExistsOpt()
[ idxId = SimpleIdentifier() ]
Expand Down Expand Up @@ -412,6 +422,11 @@ SqlCreate SqlCreateUser(Span s, boolean replace) :
final SqlNode password;
}
{
{
if (replace)
throw SqlUtil.newContextException(getPos(), IgniteResource.INSTANCE.unsupportedClause("REPLACE"));
}

<USER> user = SimpleIdentifier()
<WITH> <PASSWORD> password = StringLiteral() {
return new IgniteSqlCreateUser(s.end(this), user, SqlLiteral.unchain(password));
Expand Down Expand Up @@ -752,3 +767,26 @@ SqlNode SqlStatisticsAnalyze():
return new IgniteSqlStatisticsAnalyze(tablesList, optionsList, s.end(this));
}
}

SqlCreate SqlCreateView(Span s, boolean replace) :
{
final SqlIdentifier id;
final SqlNode query;
}
{
<VIEW> id = CompoundIdentifier()
<AS> query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY) {
return SqlDdlNodes.createView(s.end(this), replace, id, null, query);
}
}

SqlDrop SqlDropView(Span s, boolean replace) :
{
final boolean ifExists;
final SqlIdentifier id;
}
{
<VIEW> ifExists = IfExistsOpt() id = CompoundIdentifier() {
return SqlDdlNodes.dropView(s.end(this), ifExists, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,16 @@ private boolean hasExchange(RelNode rel) {
else {
CollectNode<Row> replacement = CollectNode.createCountCollector(ctx);

replacement.register(new ScanStorageNode<>(tbl.name(), ctx, rel.getTable().getRowType(), tbl.scan(ctx,
ctx.group(rel.sourceId()), ImmutableBitSet.of(0))));
replacement.register(
new ScanStorageNode<>(
tbl.name(),
ctx,
rel.getTable().getRowType(),
tbl.scan(ctx, ctx.group(rel.sourceId()), ImmutableBitSet.of(rel.fieldIndex())),
rel.notNull() ? r -> ctx.rowHandler().get(0, r) != null : null,
null
)
);

return replacement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.ddl.SqlCreateView;
import org.apache.calcite.sql.ddl.SqlDropView;
import org.apache.calcite.sql.dialect.CalciteSqlDialect;
import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
import org.apache.ignite.internal.processors.query.IgniteSQLException;
Expand Down Expand Up @@ -55,9 +58,11 @@
import org.apache.ignite.internal.sql.command.SqlCommand;
import org.apache.ignite.internal.sql.command.SqlCreateIndexCommand;
import org.apache.ignite.internal.sql.command.SqlCreateUserCommand;
import org.apache.ignite.internal.sql.command.SqlCreateViewCommand;
import org.apache.ignite.internal.sql.command.SqlDropIndexCommand;
import org.apache.ignite.internal.sql.command.SqlDropStatisticsCommand;
import org.apache.ignite.internal.sql.command.SqlDropUserCommand;
import org.apache.ignite.internal.sql.command.SqlDropViewCommand;
import org.apache.ignite.internal.sql.command.SqlIndexColumn;
import org.apache.ignite.internal.sql.command.SqlKillComputeTaskCommand;
import org.apache.ignite.internal.sql.command.SqlKillContinuousQueryCommand;
Expand Down Expand Up @@ -87,7 +92,9 @@ public static boolean isSupported(SqlNode sqlCmd) {
|| sqlCmd instanceof IgniteSqlAlterUser
|| sqlCmd instanceof IgniteSqlDropUser
|| sqlCmd instanceof IgniteSqlKill
|| sqlCmd instanceof IgniteSqlStatisticsCommand;
|| sqlCmd instanceof IgniteSqlStatisticsCommand
|| sqlCmd instanceof SqlCreateView
|| sqlCmd instanceof SqlDropView;
}

/**
Expand Down Expand Up @@ -120,6 +127,10 @@ else if (cmd instanceof IgniteSqlKill)
return convertKill((IgniteSqlKill)cmd, pctx);
else if (cmd instanceof IgniteSqlStatisticsCommand)
return convertStatistics((IgniteSqlStatisticsCommand)cmd, pctx);
else if (cmd instanceof SqlCreateView)
return convertCreateView((SqlCreateView)cmd, pctx);
else if (cmd instanceof SqlDropView)
return convertDropView((SqlDropView)cmd, pctx);

throw new IgniteSQLException("Unsupported native operation [" +
"cmdName=" + (cmd == null ? null : cmd.getClass().getSimpleName()) + "; " +
Expand Down Expand Up @@ -198,6 +209,27 @@ private static SqlDropUserCommand convertDropUser(IgniteSqlDropUser sqlCmd, Plan
return new SqlDropUserCommand(sqlCmd.user().getSimple());
}

/**
* Converts CREATE VIEW ... command.
*/
private static SqlCreateViewCommand convertCreateView(SqlCreateView sqlCmd, PlanningContext ctx) {
String schemaName = deriveSchemaName(sqlCmd.name, ctx);
String viewName = deriveObjectName(sqlCmd.name, ctx, "View name");

return new SqlCreateViewCommand(schemaName, viewName,
sqlCmd.query.toSqlString(CalciteSqlDialect.DEFAULT).toString(), sqlCmd.getReplace());
}

/**
* Converts DROP VIEW ... command.
*/
private static SqlDropViewCommand convertDropView(SqlDropView sqlCmd, PlanningContext ctx) {
String schemaName = deriveSchemaName(sqlCmd.name, ctx);
String viewName = deriveObjectName(sqlCmd.name, ctx, "View name");

return new SqlDropViewCommand(schemaName, viewName, sqlCmd.ifExists);
}

/**
* Converts KILL ... command.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class IgniteIndexCount extends AbstractRelNode implements SourceAwareIgni
/** */
private final boolean notNull;

/** */
private final int fieldIdx;

/**
* Constructor for deserialization.
*
Expand All @@ -70,6 +73,7 @@ public IgniteIndexCount(RelInput input) {
sourceId = -1L;

notNull = input.getBoolean("notNull", false);
fieldIdx = ((Number)input.get("fieldIdx")).intValue();
}

/**
Expand All @@ -86,9 +90,10 @@ public IgniteIndexCount(
RelTraitSet traits,
RelOptTable tbl,
String idxName,
boolean notNull
boolean notNull,
int fieldIdx
) {
this(-1, cluster, traits, tbl, idxName, notNull);
this(-1, cluster, traits, tbl, idxName, notNull, fieldIdx);
}

/**
Expand All @@ -107,14 +112,16 @@ private IgniteIndexCount(
RelTraitSet traits,
RelOptTable tbl,
String idxName,
boolean notNull
boolean notNull,
int fieldIdx
) {
super(cluster, traits);

this.idxName = idxName;
this.tbl = tbl;
this.sourceId = sourceId;
this.notNull = notNull;
this.fieldIdx = fieldIdx;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -156,7 +163,8 @@ public String indexName() {
.item("index", idxName)
.item("table", tbl.getQualifiedName())
.itemIf("sourceId", sourceId, sourceId != -1L)
.item("notNull", notNull);
.item("notNull", notNull)
.item("fieldIdx", fieldIdx);
}

/** {@inheritDoc} */
Expand All @@ -166,16 +174,21 @@ public String indexName() {

/** {@inheritDoc} */
@Override public IgniteRel clone(RelOptCluster cluster, List<IgniteRel> inputs) {
return new IgniteIndexCount(sourceId, cluster, traitSet, tbl, idxName, notNull);
return new IgniteIndexCount(sourceId, cluster, traitSet, tbl, idxName, notNull, fieldIdx);
}

/** {@inheritDoc} */
@Override public IgniteRel clone(long srcId) {
return new IgniteIndexCount(srcId, getCluster(), traitSet, tbl, idxName, notNull);
return new IgniteIndexCount(srcId, getCluster(), traitSet, tbl, idxName, notNull, fieldIdx);
}

/** */
public boolean notNull() {
return notNull;
}

/** */
public int fieldIndex() {
return fieldIdx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private IndexCountRule(IndexCountRule.Config cfg) {

IgniteIndex idx = null;
boolean notNull = false;
int fieldIdx = 0;

if (argList.isEmpty())
idx = table.getIndex(QueryUtils.PRIMARY_KEY_INDEX);
Expand All @@ -84,7 +85,7 @@ private IndexCountRule(IndexCountRule.Config cfg) {
return;

notNull = true;
int fieldIdx = argList.get(0);
fieldIdx = argList.get(0);

if (!scan.requiredColumns().isEmpty())
fieldIdx = scan.requiredColumns().nth(fieldIdx);
Expand Down Expand Up @@ -121,7 +122,8 @@ else if (table.distribution().getType() == RelDistribution.Type.HASH_DISTRIBUTED
idxTraits,
scan.getTable(),
idx.name(),
notNull
notNull,
fieldIdx
);

RelBuilder b = call.builder();
Expand Down
Loading

0 comments on commit c118f60

Please sign in to comment.