Reamer commented on a change in pull request #4271:
URL: https://github.com/apache/zeppelin/pull/4271#discussion_r777325332



##########
File path: 
jdbc/src/main/java/org/apache/zeppelin/jdbc/ResultDataFileProcessor.java
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.zeppelin.jdbc;
+
+import org.apache.zeppelin.interpreter.InterpreterContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static java.lang.System.getProperty;
+
+public class ResultDataFileProcessor {
+
+  Logger logger = LoggerFactory.getLogger(ResultDataFileProcessor.class);
+
+  static final String RESULT_DATA_PATH = "zeppelin.result.data.path";
+
+  String resultDataDir;
+  Properties property;
+  Map<Integer, File> map = new HashMap<>();
+
+  public ResultDataFileProcessor(Properties property) {
+
+    if (property == null) {
+      property = new Properties();
+    }
+    this.property = property;
+
+    prepare();
+  }
+
+  public synchronized void createFile(InterpreterContext context, int hashCode)
+          throws IOException, InterruptedException {
+
+    String resultFilePath = getFileName(context);
+    File resultFile = new File(resultFilePath);
+    if (resultFile.exists()) {
+      if (!resultFile.delete()) {
+        return;
+      }
+    }
+
+    if (!resultFile.createNewFile()) {
+      return;
+    }
+
+    map.put(hashCode, resultFile);
+  }
+
+  public File getFile(int hashCode) {
+    File file = map.get(hashCode);
+    map.remove(hashCode);
+    return file;
+  }
+
+  public void deleteFile(InterpreterContext context) {
+    String resultFilePath = getFileName(context);
+    File resultFile = new File(resultFilePath);
+    if (resultFile.exists()) {
+      resultFile.delete();
+    }
+  }
+
+  void prepare() {
+    resultDataDir = getProperty(RESULT_DATA_PATH);
+    if (resultDataDir == null) {
+      String defaultBaseDir = System.getProperty("java.io.tmpdir");
+      // set tmpdir to /tmp on MacOS, because docker can not share the /var 
folder which will
+      // cause PythonDockerInterpreter fails.
+      // 
https://stackoverflow.com/questions/45122459/docker-mounts-denied-the-paths-are-not-shared-
+      // from-os-x-and-are-not-known
+      if (System.getProperty("os.name", "").contains("Mac")) {

Review comment:
       Please use 
[createTempDirectory(....)](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#createTempDirectory(java.lang.String,%20java.nio.file.attribute.FileAttribute...))
  to create your temp directory.
   This should work on MacOS, Windows, Linux etc. 

##########
File path: 
zeppelin-interpreter/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java
##########
@@ -989,6 +1003,9 @@ public void save(String location) throws 
ConfigurationException {
     
ZEPPELIN_NOTEBOOK_AUTO_INTERPRETER_BINDING("zeppelin.notebook.autoInterpreterBinding",
 true),
     ZEPPELIN_CONF_DIR("zeppelin.conf.dir", "conf"),
     ZEPPELIN_CONFIG_FS_DIR("zeppelin.config.fs.dir", ""),
+    ZEPPELIN_RESULT_DATA_DIR("zeppelin.result.data.path",

Review comment:
       A default property should not depend on a `user.name`. At the moment of 
review, I don't even know what value is returned at this point.
   A system property `user.name`, which is part of the Zeppelin startup 
parameters, is unknown to me.

##########
File path: 
jdbc/src/main/java/org/apache/zeppelin/jdbc/ResultDataFileCleaner.java
##########
@@ -0,0 +1,91 @@
+/**
+ * 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.zeppelin.jdbc;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.Objects;
+
+public class ResultDataFileCleaner extends Thread {

Review comment:
       Instead of a long-lived thread, I would prefer to delete the files when 
the [interpreter is 
closed](https://github.com/apache/zeppelin/blob/de3a88ee1732ece6ca167f3399f759c43c7cb76d/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java#L65).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to