{"action":"created","comment":{"url":"https://api.github.com/repos/klarna/HiveRunner/pulls/comments/50022251","id":50022251,"diff_hunk":"@@ -148,6 +151,42 @@ public void executeScriptNotStarted() throws IOException {\n       shell.execute(UTF_8, Paths.get(file.toURI()));\n     }\n \n+    @Test\n+    public void scriptFilesAreImportedInQueries() throws IOException {\n+      String hql = \"use default\";\n+\n+      File importedFile = new File(tempFolder.getRoot(), \"imported_script.hql\");\n+      Files.write(hql, importedFile, UTF_8);\n+\n+      HiveShell shell = createHiveShell();\n+      shell.start();\n+\n+      String importHql = \"source \" + importedFile.getAbsolutePath();\n+      List<String> results = shell.executeQuery(importHql);\n+\n+      assertThat(results, is(empty()));\n+      verify(container).executeStatement(hql);\n+    }\n+\n+    @Test\n+    public void scriptFilesAreImportedInOtherScripts() throws IOException {\n+      String hql = \"use default\";\n+\n+      File importedFile = new File(tempFolder.getRoot(), \"imported_script.hql\");\n+      Files.write(hql, importedFile, UTF_8);\n+\n+      HiveShell shell = createHiveShell();\n+      shell.start();\n+\n+      String importHql = \"source \" + importedFile.getAbsolutePath();\n+      File file = new File(tempFolder.getRoot(), \"script.hql\");\n+      Files.write(importHql, file, UTF_8);\n+\n+      shell.execute(file);\n+\n+      verify(container).executeStatement(hql);","path":"src/test/java/com/klarna/hiverunner/builder/HiveShellBaseTest.java","position":115,"original_position":115,"commit_id":"94f362b262b79787667adf402304bfcdc90c7121","original_commit_id":"cf7a8ec63e98ae08d85af782475f58599262cd91","user":{"login":"stefansperber","id":1471307,"avatar_url":"https://avatars.githubusercontent.com/u/1471307?v=3","gravatar_id":"","url":"https://api.github.com/users/stefansperber","html_url":"https://github.com/stefansperber","followers_url":"https://api.github.com/users/stefansperber/followers","following_url":"https://api.github.com/users/stefansperber/following{/other_user}","gists_url":"https://api.github.com/users/stefansperber/gists{/gist_id}","starred_url":"https://api.github.com/users/stefansperber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefansperber/subscriptions","organizations_url":"https://api.github.com/users/stefansperber/orgs","repos_url":"https://api.github.com/users/stefansperber/repos","events_url":"https://api.github.com/users/stefansperber/events{/privacy}","received_events_url":"https://api.github.com/users/stefansperber/received_events","type":"User","site_admin":false},"body":"`HiveShell` will read the file into a string, which is then executed the same way as a multi-statement script. Do you think this needs a extra testing? I'm reusing existing functionality.","created_at":"2016-01-18T17:04:45Z","updated_at":"2016-01-18T17:04:45Z","html_url":"https://github.com/klarna/HiveRunner/pull/25#discussion_r50022251","pull_request_url":"https://api.github.com/repos/klarna/HiveRunner/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/klarna/HiveRunner/pulls/comments/50022251"},"html":{"href":"https://github.com/klarna/HiveRunner/pull/25#discussion_r50022251"},"pull_request":{"href":"https://api.github.com/repos/klarna/HiveRunner/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/klarna/HiveRunner/pulls/25","id":55622278,"html_url":"https://github.com/klarna/HiveRunner/pull/25","diff_url":"https://github.com/klarna/HiveRunner/pull/25.diff","patch_url":"https://github.com/klarna/HiveRunner/pull/25.patch","issue_url":"https://api.github.com/repos/klarna/HiveRunner/issues/25","number":25,"state":"open","locked":false,"title":"Support CLI-specific import file statements","user":{"login":"stefansperber","id":1471307,"avatar_url":"https://avatars.githubusercontent.com/u/1471307?v=3","gravatar_id":"","url":"https://api.github.com/users/stefansperber","html_url":"https://github.com/stefansperber","followers_url":"https://api.github.com/users/stefansperber/followers","following_url":"https://api.github.com/users/stefansperber/following{/other_user}","gists_url":"https://api.github.com/users/stefansperber/gists{/gist_id}","starred_url":"https://api.github.com/users/stefansperber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefansperber/subscriptions","organizations_url":"https://api.github.com/users/stefansperber/orgs","repos_url":"https://api.github.com/users/stefansperber/repos","events_url":"https://api.github.com/users/stefansperber/events{/privacy}","received_events_url":"https://api.github.com/users/stefansperber/received_events","type":"User","site_admin":false},"body":"I added support for `source` (HiveCli) and `!run` (Beeline) commands. These commands allow to import and execute scripts in statements or scripts. This allows to compose and reuse HQL scripts.\r\n\r\nSince these commands are not part of the core language I limited changes to the parts that emulate CLI-specific behaviour. Let me know what you think.\r\n\r\nSome remarks:\r\n\r\n(1) To keep `HiveServerContainer` agnostic to the used CLI I moved splitting scripts into statements out of the class. Afterwards, I removed the now unused `HiveServerContainer#executeScript` (it does not support `source/!run`). This breaks backwards compatibility. If deprecation is a better option commit `2d495443b8cc31ac99ca7c7fec77e4b193d78f0b` can be reverted.\r\n\r\n(2) I noticed that [Beeline's SQLLine](https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-BeelineCommands) commands are not supported/emulated (for example, `!run` or `!quit`). If these should be supported in the future further refactorings could be done.\r\n\r\nHere's an idea instead of string statements:\r\n```\r\nclass Statement {\r\n\r\n  private final StatementType type;\r\n  private final String value;\r\n  \r\n  // ... constructor + getters for members omitted\r\n  \r\n  String[] getTokens() {\r\n    return value.trim().split(\"\\\\s+\");\r\n  } \r\n}\r\n```\r\n```\r\nenum StatementType {\r\n  /* */\r\n  HQL,\r\n  /* supported by both CLIs */\r\n  IMPORT_FILE,\r\n  /* */\r\n  HIVE_CLI_SPECIFIC_COMMAND,\r\n  /* */\r\n  BEELINE_SPECIFIC_COMMAND,\r\n  \r\n  // ...\r\n}\r\n```\r\n\r\nThis would also simplify my changes a bit more.\r\n\r\nExample usage:\r\n```\r\nfor (Statement statement : StatementsSplitter.splitStatements(commandShellEmulation.transformScript(script))) {\r\n  if (StatementType.HQL == statement.getType()) {\r\n    execute(statement);\r\n  } else if (StatementType.IMPORT_FILE == statement.getType()) {\r\n  \t// ...\r\n  }\r\n}\r\n```","created_at":"2016-01-11T13:34:35Z","updated_at":"2016-01-18T17:04:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af07035d8013428b0c6fe92747efcf6f118b1eac","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/klarna/HiveRunner/pulls/25/commits","review_comments_url":"https://api.github.com/repos/klarna/HiveRunner/pulls/25/comments","review_comment_url":"https://api.github.com/repos/klarna/HiveRunner/pulls/comments{/number}","comments_url":"https://api.github.com/repos/klarna/HiveRunner/issues/25/comments","statuses_url":"https://api.github.com/repos/klarna/HiveRunner/statuses/94f362b262b79787667adf402304bfcdc90c7121","head":{"label":"stefansperber:support_cli_specific_import_file_statements","ref":"support_cli_specific_import_file_statements","sha":"94f362b262b79787667adf402304bfcdc90c7121","user":{"login":"stefansperber","id":1471307,"avatar_url":"https://avatars.githubusercontent.com/u/1471307?v=3","gravatar_id":"","url":"https://api.github.com/users/stefansperber","html_url":"https://github.com/stefansperber","followers_url":"https://api.github.com/users/stefansperber/followers","following_url":"https://api.github.com/users/stefansperber/following{/other_user}","gists_url":"https://api.github.com/users/stefansperber/gists{/gist_id}","starred_url":"https://api.github.com/users/stefansperber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefansperber/subscriptions","organizations_url":"https://api.github.com/users/stefansperber/orgs","repos_url":"https://api.github.com/users/stefansperber/repos","events_url":"https://api.github.com/users/stefansperber/events{/privacy}","received_events_url":"https://api.github.com/users/stefansperber/received_events","type":"User","site_admin":false},"repo":{"id":49427289,"name":"HiveRunner","full_name":"stefansperber/HiveRunner","owner":{"login":"stefansperber","id":1471307,"avatar_url":"https://avatars.githubusercontent.com/u/1471307?v=3","gravatar_id":"","url":"https://api.github.com/users/stefansperber","html_url":"https://github.com/stefansperber","followers_url":"https://api.github.com/users/stefansperber/followers","following_url":"https://api.github.com/users/stefansperber/following{/other_user}","gists_url":"https://api.github.com/users/stefansperber/gists{/gist_id}","starred_url":"https://api.github.com/users/stefansperber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefansperber/subscriptions","organizations_url":"https://api.github.com/users/stefansperber/orgs","repos_url":"https://api.github.com/users/stefansperber/repos","events_url":"https://api.github.com/users/stefansperber/events{/privacy}","received_events_url":"https://api.github.com/users/stefansperber/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stefansperber/HiveRunner","description":"An Open Source unit test framework for hadoop hive queries based on JUnit4","fork":true,"url":"https://api.github.com/repos/stefansperber/HiveRunner","forks_url":"https://api.github.com/repos/stefansperber/HiveRunner/forks","keys_url":"https://api.github.com/repos/stefansperber/HiveRunner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stefansperber/HiveRunner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stefansperber/HiveRunner/teams","hooks_url":"https://api.github.com/repos/stefansperber/HiveRunner/hooks","issue_events_url":"https://api.github.com/repos/stefansperber/HiveRunner/issues/events{/number}","events_url":"https://api.github.com/repos/stefansperber/HiveRunner/events","assignees_url":"https://api.github.com/repos/stefansperber/HiveRunner/assignees{/user}","branches_url":"https://api.github.com/repos/stefansperber/HiveRunner/branches{/branch}","tags_url":"https://api.github.com/repos/stefansperber/HiveRunner/tags","blobs_url":"https://api.github.com/repos/stefansperber/HiveRunner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stefansperber/HiveRunner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stefansperber/HiveRunner/git/refs{/sha}","trees_url":"https://api.github.com/repos/stefansperber/HiveRunner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stefansperber/HiveRunner/statuses/{sha}","languages_url":"https://api.github.com/repos/stefansperber/HiveRunner/languages","stargazers_url":"https://api.github.com/repos/stefansperber/HiveRunner/stargazers","contributors_url":"https://api.github.com/repos/stefansperber/HiveRunner/contributors","subscribers_url":"https://api.github.com/repos/stefansperber/HiveRunner/subscribers","subscription_url":"https://api.github.com/repos/stefansperber/HiveRunner/subscription","commits_url":"https://api.github.com/repos/stefansperber/HiveRunner/commits{/sha}","git_commits_url":"https://api.github.com/repos/stefansperber/HiveRunner/git/commits{/sha}","comments_url":"https://api.github.com/repos/stefansperber/HiveRunner/comments{/number}","issue_comment_url":"https://api.github.com/repos/stefansperber/HiveRunner/issues/comments{/number}","contents_url":"https://api.github.com/repos/stefansperber/HiveRunner/contents/{+path}","compare_url":"https://api.github.com/repos/stefansperber/HiveRunner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stefansperber/HiveRunner/merges","archive_url":"https://api.github.com/repos/stefansperber/HiveRunner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stefansperber/HiveRunner/downloads","issues_url":"https://api.github.com/repos/stefansperber/HiveRunner/issues{/number}","pulls_url":"https://api.github.com/repos/stefansperber/HiveRunner/pulls{/number}","milestones_url":"https://api.github.com/repos/stefansperber/HiveRunner/milestones{/number}","notifications_url":"https://api.github.com/repos/stefansperber/HiveRunner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stefansperber/HiveRunner/labels{/name}","releases_url":"https://api.github.com/repos/stefansperber/HiveRunner/releases{/id}","created_at":"2016-01-11T13:12:24Z","updated_at":"2016-01-11T13:12:24Z","pushed_at":"2016-01-18T16:23:43Z","git_url":"git://github.com/stefansperber/HiveRunner.git","ssh_url":"git@github.com:stefansperber/HiveRunner.git","clone_url":"https://github.com/stefansperber/HiveRunner.git","svn_url":"https://github.com/stefansperber/HiveRunner","homepage":null,"size":518,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"klarna:master","ref":"master","sha":"a9acddd8ea90b9bd7e6c165229ea927fb30f5f5f","user":{"login":"klarna","id":394540,"avatar_url":"https://avatars.githubusercontent.com/u/394540?v=3","gravatar_id":"","url":"https://api.github.com/users/klarna","html_url":"https://github.com/klarna","followers_url":"https://api.github.com/users/klarna/followers","following_url":"https://api.github.com/users/klarna/following{/other_user}","gists_url":"https://api.github.com/users/klarna/gists{/gist_id}","starred_url":"https://api.github.com/users/klarna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/klarna/subscriptions","organizations_url":"https://api.github.com/users/klarna/orgs","repos_url":"https://api.github.com/users/klarna/repos","events_url":"https://api.github.com/users/klarna/events{/privacy}","received_events_url":"https://api.github.com/users/klarna/received_events","type":"Organization","site_admin":false},"repo":{"id":14613496,"name":"HiveRunner","full_name":"klarna/HiveRunner","owner":{"login":"klarna","id":394540,"avatar_url":"https://avatars.githubusercontent.com/u/394540?v=3","gravatar_id":"","url":"https://api.github.com/users/klarna","html_url":"https://github.com/klarna","followers_url":"https://api.github.com/users/klarna/followers","following_url":"https://api.github.com/users/klarna/following{/other_user}","gists_url":"https://api.github.com/users/klarna/gists{/gist_id}","starred_url":"https://api.github.com/users/klarna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/klarna/subscriptions","organizations_url":"https://api.github.com/users/klarna/orgs","repos_url":"https://api.github.com/users/klarna/repos","events_url":"https://api.github.com/users/klarna/events{/privacy}","received_events_url":"https://api.github.com/users/klarna/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/klarna/HiveRunner","description":"An Open Source unit test framework for hadoop hive queries based on JUnit4","fork":false,"url":"https://api.github.com/repos/klarna/HiveRunner","forks_url":"https://api.github.com/repos/klarna/HiveRunner/forks","keys_url":"https://api.github.com/repos/klarna/HiveRunner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/klarna/HiveRunner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/klarna/HiveRunner/teams","hooks_url":"https://api.github.com/repos/klarna/HiveRunner/hooks","issue_events_url":"https://api.github.com/repos/klarna/HiveRunner/issues/events{/number}","events_url":"https://api.github.com/repos/klarna/HiveRunner/events","assignees_url":"https://api.github.com/repos/klarna/HiveRunner/assignees{/user}","branches_url":"https://api.github.com/repos/klarna/HiveRunner/branches{/branch}","tags_url":"https://api.github.com/repos/klarna/HiveRunner/tags","blobs_url":"https://api.github.com/repos/klarna/HiveRunner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/klarna/HiveRunner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/klarna/HiveRunner/git/refs{/sha}","trees_url":"https://api.github.com/repos/klarna/HiveRunner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/klarna/HiveRunner/statuses/{sha}","languages_url":"https://api.github.com/repos/klarna/HiveRunner/languages","stargazers_url":"https://api.github.com/repos/klarna/HiveRunner/stargazers","contributors_url":"https://api.github.com/repos/klarna/HiveRunner/contributors","subscribers_url":"https://api.github.com/repos/klarna/HiveRunner/subscribers","subscription_url":"https://api.github.com/repos/klarna/HiveRunner/subscription","commits_url":"https://api.github.com/repos/klarna/HiveRunner/commits{/sha}","git_commits_url":"https://api.github.com/repos/klarna/HiveRunner/git/commits{/sha}","comments_url":"https://api.github.com/repos/klarna/HiveRunner/comments{/number}","issue_comment_url":"https://api.github.com/repos/klarna/HiveRunner/issues/comments{/number}","contents_url":"https://api.github.com/repos/klarna/HiveRunner/contents/{+path}","compare_url":"https://api.github.com/repos/klarna/HiveRunner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/klarna/HiveRunner/merges","archive_url":"https://api.github.com/repos/klarna/HiveRunner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/klarna/HiveRunner/downloads","issues_url":"https://api.github.com/repos/klarna/HiveRunner/issues{/number}","pulls_url":"https://api.github.com/repos/klarna/HiveRunner/pulls{/number}","milestones_url":"https://api.github.com/repos/klarna/HiveRunner/milestones{/number}","notifications_url":"https://api.github.com/repos/klarna/HiveRunner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/klarna/HiveRunner/labels{/name}","releases_url":"https://api.github.com/repos/klarna/HiveRunner/releases{/id}","created_at":"2013-11-22T09:19:09Z","updated_at":"2016-01-13T14:38:32Z","pushed_at":"2016-01-18T16:23:44Z","git_url":"git://github.com/klarna/HiveRunner.git","ssh_url":"git@github.com:klarna/HiveRunner.git","clone_url":"https://github.com/klarna/HiveRunner.git","svn_url":"https://github.com/klarna/HiveRunner","homepage":null,"size":668,"stargazers_count":49,"watchers_count":49,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":9,"forks":20,"open_issues":9,"watchers":49,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/klarna/HiveRunner/pulls/25"},"html":{"href":"https://github.com/klarna/HiveRunner/pull/25"},"issue":{"href":"https://api.github.com/repos/klarna/HiveRunner/issues/25"},"comments":{"href":"https://api.github.com/repos/klarna/HiveRunner/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/klarna/HiveRunner/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/klarna/HiveRunner/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/klarna/HiveRunner/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/klarna/HiveRunner/statuses/94f362b262b79787667adf402304bfcdc90c7121"}}}}