Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -259,8 +259,11 @@ public class CalciteQueryProcessor extends GridProcessorAdapter implements Query
public CalciteQueryProcessor(GridKernalContext ctx) {
super(ctx);

FrameworkConfig customFrameworkCfg = ctx.plugins().createComponent(FrameworkConfig.class);
frameworkCfg = customFrameworkCfg != null ? customFrameworkCfg : FRAMEWORK_CONFIG;

failureProcessor = ctx.failure();
schemaHolder = new SchemaHolderImpl(ctx);
schemaHolder = new SchemaHolderImpl(ctx, frameworkCfg);
qryPlanCache = new QueryPlanCacheImpl(ctx);
parserMetrics = new QueryParserMetricsHolder(ctx.metric());
mailboxRegistry = new MailboxRegistryImpl(ctx);
Expand All @@ -277,9 +280,6 @@ public CalciteQueryProcessor(GridKernalContext ctx) {
qryReg = new QueryRegistryImpl(ctx);
injectSvc = new InjectResourcesService(ctx);

FrameworkConfig customFrameworkCfg = ctx.plugins().createComponent(FrameworkConfig.class);
frameworkCfg = customFrameworkCfg != null ? customFrameworkCfg : FRAMEWORK_CONFIG;

QueryEngineConfiguration[] qryEnginesCfg = ctx.config().getSqlConfiguration().getQueryEnginesConfiguration();

if (F.isEmpty(qryEnginesCfg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.AbstractSchema;
import org.apache.calcite.tools.FrameworkConfig;

/**
* Ignite schema.
Expand Down Expand Up @@ -111,12 +112,13 @@ public void removeView(String name) {
* Registers current {@code IgniteSchema} in parent {@code SchemaPlus}.
*
* @param parent Parent schema.
* @param frameworkCfg Framework config.
* @return Registered schema.
*/
public SchemaPlus register(SchemaPlus parent) {
public SchemaPlus register(SchemaPlus parent, FrameworkConfig frameworkCfg) {
SchemaPlus newSchema = parent.add(schemaName, this);

viewMap.forEach((name, sql) -> newSchema.add(name, new ViewTableMacroImpl(sql, newSchema)));
viewMap.forEach((name, sql) -> newSchema.add(name, new ViewTableMacroImpl(sql, newSchema, frameworkCfg)));

return newSchema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.calcite.rel.RelCollations;
import org.apache.calcite.rel.RelFieldCollation;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.mapping.Mappings;
Expand Down Expand Up @@ -65,6 +66,9 @@ public class SchemaHolderImpl extends AbstractService implements SchemaHolder, S
/** */
private final GridKernalContext ctx;

/** */
private final FrameworkConfig frameworkCfg;

/** */
private GridInternalSubscriptionProcessor subscriptionProcessor;

Expand Down Expand Up @@ -136,10 +140,11 @@ public AffinityIdentity(AffinityFunction aff, int backups, IgnitePredicate<Clust
/**
* @param ctx Kernal context.
*/
public SchemaHolderImpl(GridKernalContext ctx) {
public SchemaHolderImpl(GridKernalContext ctx, FrameworkConfig frameworkCfg) {
super(ctx);

this.ctx = ctx;
this.frameworkCfg = frameworkCfg;

subscriptionProcessor(ctx.internalSubscriptionProcessor());

Expand Down Expand Up @@ -412,7 +417,7 @@ private void rebuild() {
newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA));

for (IgniteSchema schema : igniteSchemas.values())
schema.register(newCalciteSchema);
schema.register(newCalciteSchema, frameworkCfg);

calciteSchema = newCalciteSchema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.calcite.schema.TableMacro;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
import org.apache.ignite.internal.processors.query.IgniteSQLException;
import org.apache.ignite.internal.processors.query.calcite.prepare.BaseQueryContext;
Expand All @@ -51,10 +52,14 @@ public class ViewTableMacroImpl implements TableMacro {
/** */
private final SchemaPlus schema;

/** */
private final FrameworkConfig frameworkCfg;

/** Ctor. */
public ViewTableMacroImpl(String viewSql, SchemaPlus schema) {
public ViewTableMacroImpl(String viewSql, SchemaPlus schema, FrameworkConfig frameworkCfg) {
this.viewSql = viewSql;
this.schema = schema;
this.frameworkCfg = frameworkCfg;
}

/** {@inheritDoc} */
Expand All @@ -65,7 +70,7 @@ public ViewTableMacroImpl(String viewSql, SchemaPlus schema) {

try {
IgnitePlanner planner = PlanningContext.builder()
.parentContext(BaseQueryContext.builder().defaultSchema(schema).build())
.parentContext(BaseQueryContext.builder().frameworkConfig(frameworkCfg).defaultSchema(schema).build())
.build()
.planner();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ public void test() throws Exception {
.returns(Timestamp.valueOf("2021-01-01 00:00:00")).check();
}

/** */
@Test
public void testOperatorsCallsInViews() {
sql("create table my_table(id int primary key, val_str varchar)");

sql("insert into my_table values (?, ?)", 0, Integer.toString(0));

sql("create or replace view my_view as select to_number(val_str) val_str from my_table");

assertQuery("SELECT val_str from my_view").returns(new BigDecimal("0")).check();
}

/** Rewrites LTRIM with 2 parameters. */
public static SqlCall rewriteLtrim(SqlValidator validator, SqlCall call) {
if (call.operandCount() != 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ protected BaseQueryContext baseQueryContext(Collection<IgniteSchema> schemas) {
SchemaPlus dfltSchema = null;

for (IgniteSchema igniteSchema : schemas) {
SchemaPlus schema = igniteSchema.register(rootSchema);
SchemaPlus schema = igniteSchema.register(rootSchema, null);

if (dfltSchema == null || DEFAULT_SCHEMA.equals(schema.getName()))
dfltSchema = schema;
Expand Down