-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IGNITE-22717 SQL Calcite: User defined SQL views #11467
Changes from 4 commits
b6d5f2b
e274258
2c3d27d
08a1f61
3e7fb40
fbe6d33
3492fcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import org.apache.ignite.internal.processors.cache.GridCacheContextInfo; | ||
import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor; | ||
import org.apache.ignite.internal.processors.query.QueryField; | ||
import org.apache.ignite.internal.processors.query.QueryUtils; | ||
import org.apache.ignite.internal.processors.query.calcite.exec.exp.IgniteScalarFunction; | ||
import org.apache.ignite.internal.processors.query.calcite.trait.TraitUtils; | ||
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory; | ||
|
@@ -367,6 +368,26 @@ private static Object affinityIdentity(CacheConfiguration<?, ?> ccfg) { | |
rebuild(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void onViewCreated(String schemaName, String viewName, String viewSql) { | ||
IgniteSchema schema = igniteSchemas.computeIfAbsent(schemaName, IgniteSchema::new); | ||
|
||
schema.addView(viewName, viewSql); | ||
|
||
rebuild(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void onViewDropped(String schemaName, String viewName) { | ||
IgniteSchema schema = igniteSchemas.get(schemaName); | ||
|
||
if (schema != null) { | ||
schema.removeView(viewName); | ||
|
||
rebuild(); | ||
} | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public SchemaPlus schema(@Nullable String schema) { | ||
return schema != null ? calciteSchema.getSubSchema(schema) : calciteSchema; | ||
|
@@ -385,10 +406,14 @@ private IgniteCacheTable table(String schemaName, String tableName) { | |
/** */ | ||
private void rebuild() { | ||
SchemaPlus newCalciteSchema = Frameworks.createRootSchema(false); | ||
|
||
newCalciteSchema.add("UUID", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(UUID.class)); | ||
newCalciteSchema.add("OTHER", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(Object.class)); | ||
newCalciteSchema.add("PUBLIC", new IgniteSchema("PUBLIC")); | ||
igniteSchemas.forEach(newCalciteSchema::add); | ||
newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA)); | ||
alex-plekhanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for (IgniteSchema schema : igniteSchemas.values()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like similar to the previous: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a matter of taste. |
||
schema.register(newCalciteSchema); | ||
|
||
calciteSchema = newCalciteSchema; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.internal.processors.query.calcite.schema; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.calcite.rel.type.RelProtoDataType; | ||
import org.apache.calcite.schema.impl.ViewTable; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Ignite SQL view table implementation. | ||
*/ | ||
public class ViewTableImpl extends ViewTable { | ||
/** Fields origins. */ | ||
private final Map<String, List<String>> origins; | ||
|
||
/** Ctor. */ | ||
public ViewTableImpl( | ||
Type elementType, | ||
RelProtoDataType rowType, | ||
String viewSql, | ||
List<String> schemaPath, | ||
Map<String, List<String>> origins | ||
) { | ||
super(elementType, rowType, viewSql, schemaPath, null); | ||
|
||
this.origins = Collections.unmodifiableMap(origins); | ||
} | ||
|
||
/** Get field origin. */ | ||
public @Nullable List<String> fieldOrigin(String fieldName) { | ||
return origins.get(fieldName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the tables and the functions we store interfaces like
Function
orIgniteTable
. For views a string/sql/request instead. Could we similary keep something likeTableMacro
. If I'm right, functionregister
would not be required in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TableMacro requires schamaPlus. We don't have a schemaPlus until register method, so we can't use table macro here.