[
https://issues.apache.org/jira/browse/DRILL-8543?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18057118#comment-18057118
]
ASF GitHub Bot commented on DRILL-8543:
---------------------------------------
cgivre commented on code in PR #3036:
URL: https://github.com/apache/drill/pull/3036#discussion_r2778456904
##########
exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java:
##########
@@ -351,6 +354,253 @@ public void dropView(String viewName) throws IOException {
getFS().delete(getViewPath(viewName), false);
}
+ private Path getMaterializedViewPath(String name) {
+ return DotDrillType.MATERIALIZED_VIEW.getPath(config.getLocation(),
name);
+ }
+
+ private Path getMaterializedViewDataPath(String name) {
+ // Use _mv_data suffix to distinguish data directory from MV definition
lookup
+ return new Path(config.getLocation(), name + "_mv_data");
+ }
+
+ @Override
+ public boolean createMaterializedView(MaterializedView materializedView)
throws IOException {
+ String viewName = materializedView.getName();
+ Path viewPath = getMaterializedViewPath(viewName);
+ Path dataPath = getMaterializedViewDataPath(viewName);
+
+ boolean replaced = getFS().exists(viewPath);
+
+ // If replacing, first drop the old data
+ if (replaced) {
+ if (getFS().exists(dataPath)) {
+ getFS().delete(dataPath, true);
+ }
+ }
+
+ // Create the data directory for the materialized view
+ final FsPermission dirPerms = new FsPermission(
+
schemaConfig.getOption(ExecConstants.NEW_VIEW_DEFAULT_PERMS_KEY).string_val);
+ getFS().mkdirs(dataPath, dirPerms);
+
+ // Set the data storage path in the materialized view
+ materializedView.setDataStoragePath(viewName);
+
+ // Write the materialized view definition file
+ final FsPermission viewPerms = new FsPermission(
+
schemaConfig.getOption(ExecConstants.NEW_VIEW_DEFAULT_PERMS_KEY).string_val);
+ try (OutputStream stream = DrillFileSystem.create(getFS(), viewPath,
viewPerms)) {
+ mapper.writeValue(stream, materializedView);
+ }
+
+ // Sync to metastore if enabled
+ syncMaterializedViewToMetastore(materializedView);
+
+ // Mark as complete (data will be populated by the handler via CTAS-like
operation)
+ return replaced;
+ }
+
+ @Override
+ public void dropMaterializedView(String viewName) throws IOException {
+ Path viewPath = getMaterializedViewPath(viewName);
+ Path dataPath = getMaterializedViewDataPath(viewName);
+
+ // Delete the definition file
+ if (getFS().exists(viewPath)) {
+ getFS().delete(viewPath, false);
+ }
+
+ // Delete the data directory
+ if (getFS().exists(dataPath)) {
+ getFS().delete(dataPath, true);
+ }
+
+ // Remove from metastore if enabled
+ removeMaterializedViewFromMetastore(viewName);
+ }
+
+ @Override
+ public void refreshMaterializedView(String viewName) throws IOException {
+ // Read the existing materialized view definition
+ MaterializedView mv = getMaterializedView(viewName);
+ if (mv == null) {
+ throw UserException.validationError()
+ .message("Materialized view [%s] not found in schema [%s]",
viewName, getFullSchemaName())
+ .build(logger);
+ }
+
+ Path dataPath = getMaterializedViewDataPath(viewName);
+
+ // Delete existing data
+ if (getFS().exists(dataPath)) {
+ getFS().delete(dataPath, true);
+ }
+
+ // Recreate the data directory
+ final FsPermission dirPerms = new FsPermission(
+
schemaConfig.getOption(ExecConstants.NEW_VIEW_DEFAULT_PERMS_KEY).string_val);
+ getFS().mkdirs(dataPath, dirPerms);
+
+ // Update the materialized view with new refresh time
+ MaterializedView updatedMV = mv.withRefreshInfo(
Review Comment:
Fixed.
> Add Support for Materialized Views
> ----------------------------------
>
> Key: DRILL-8543
> URL: https://issues.apache.org/jira/browse/DRILL-8543
> Project: Apache Drill
> Issue Type: New Feature
> Components: Metadata, Query Planning & Optimization
> Affects Versions: 1.22.0
> Reporter: Charles Givre
> Assignee: Charles Givre
> Priority: Major
> Fix For: 1.23.0
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)