Skip to content

Commit 033a354

Browse files
Merge remote-tracking branch 'origin/master' into UserInInterpreterContext
2 parents e4a5165 + 39417c0 commit 033a354

File tree

21 files changed

+772
-59
lines changed

21 files changed

+772
-59
lines changed

conf/zeppelin-site.xml.template

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,33 @@
8383
</property>
8484
-->
8585

86+
<!-- If using Azure for storage use the following settings -->
87+
<!--
88+
<property>
89+
<name>zeppelin.notebook.azure.user</name>
90+
<value>user</value>
91+
<description>optional user name for Azure folder structure</description>
92+
</property>
93+
94+
<property>
95+
<name>zeppelin.notebook.azure.share</name>
96+
<value>zeppelin</value>
97+
<description>share name for notebook storage</description>
98+
</property>
99+
100+
<property>
101+
<name>zeppelin.notebook.azure.connectionString</name>
102+
<value>DefaultEndpointsProtocol=https;AccountName=<accountName>;AccountKey=<accountKey></value>
103+
<description>share name for notebook storage</description>
104+
</property>
105+
106+
<property>
107+
<name>zeppelin.notebook.storage</name>
108+
<value>org.apache.zeppelin.notebook.repo.AzureNotebookRepo</value>
109+
<description>notebook persistence layer implementation</description>
110+
</property>
111+
-->
112+
86113
<!-- For versioning your local norebook storage using Git repository
87114
<property>
88115
<name>zeppelin.notebook.storage</name>

docs/README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ See https://help.github.com/articles/using-jekyll-with-pages#installing-jekyll
88

99
**tl;dr version:**
1010

11+
```
1112
ruby --version >= 1.9.3
1213
gem install bundler
14+
# go to /docs under your Zeppelin source
1315
bundle install
14-
16+
```
17+
1518
*On OS X 10.9 you may need to do "xcode-select --install"*
1619

1720

@@ -20,28 +23,28 @@ See https://help.github.com/articles/using-jekyll-with-pages#installing-jekyll
2023
bundle exec jekyll serve --watch
2124

2225

23-
## Deploy to ASF svnpubsub infra (commiters only)
26+
## Adding a new page
27+
28+
rake page name="new-page.md"
29+
30+
31+
## Bumping up version in a new release
32+
33+
* `ZEPPELIN_VERSION` and `BASE_PATH` property in _config.yml
34+
* `Zeppelin <small>([VERSION])</small>` in _includes/themes/zeppelin/_navigation.html
35+
should be updated
36+
37+
38+
## Deploy to ASF svnpubsub infra (for committers only)
2439
1. generate static website in `./_site`
2540
```
41+
# go to /docs under Zeppelin source
2642
bundle exec jekyll build --safe
2743
```
2844
2945
2. checkout ASF repo
3046
```
31-
svn co https://svn.apache.org/repos/asf/incubator/zeppelin asf-zepplelin
47+
svn co https://svn.apache.org/repos/asf/incubator/zeppelin asf-zeppelin
3248
```
33-
3. copy zeppelin/_site to asf-zepplelin/site/docs/[VERSION]
49+
3. copy `zeppelin/docs/_site` to `asf-zeppelin/site/docs/[VERSION]`
3450
4. ```svn commit```
35-
36-
## Adding a new page
37-
38-
rake page name="new-page.md"
39-
40-
41-
42-
## Bumping up version
43-
44-
* `BASE_PATH` property in _config.yml
45-
* `ZEPPELIN <small>([VERSION])</small>` in _includes/themes/zeppelin/_navigation.html
46-
47-
need to be updated

docs/install/install.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ You can configure Zeppelin with both **environment variables** in `conf/zeppelin
178178
<td>user</td>
179179
<td>A user name of S3 bucket<br />i.e. <code>bucket/user/notebook/2A94M5J1Z/note.json</code></td>
180180
</tr>
181+
<tr>
182+
<td>ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING</td>
183+
<td>zeppelin.notebook.azure.connectionString</td>
184+
<td></td>
185+
<td>The Azure storage account connection string<br />i.e. <code>DefaultEndpointsProtocol=https;AccountName=&lt;accountName&gt;;AccountKey=&lt;accountKey&gt;</code></td>
186+
</tr>
187+
<tr>
188+
<td>ZEPPELIN_NOTEBOOK_AZURE_SHARE</td>
189+
<td>zeppelin.notebook.azure.share</td>
190+
<td>zeppelin</td>
191+
<td>Share where the Zeppelin notebook files will be saved</td>
192+
</tr>
193+
<tr>
194+
<td>ZEPPELIN_NOTEBOOK_AZURE_USER</td>
195+
<td>zeppelin.notebook.azure.user</td>
196+
<td>user</td>
197+
<td>An optional user name of Azure file share<br />i.e. <code>share/user/notebook/2A94M5J1Z/note.json</code></td>
198+
</tr>
181199
<tr>
182200
<td>ZEPPELIN_NOTEBOOK_STORAGE</td>
183201
<td>zeppelin.notebook.storage</td>

docs/interpreter/jdbc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This interpreter lets you create a JDBC connection to any data source, by now it
1616
* MariaDB
1717
* Redshift
1818
* Hive
19+
* Apache Drill
20+
* Details on using [Drill JDBC Driver](https://drill.apache.org/docs/using-the-jdbc-driver)
1921

2022
If someone else used another database please report how it works to improve functionality.
2123

hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public void close() {
169169

170170
public Connection getConnection(String propertyKey) throws ClassNotFoundException, SQLException {
171171
Connection connection = null;
172+
if (propertyKey == null || propertiesMap.get(propertyKey) == null) {
173+
return null;
174+
}
172175
if (propertyKeyUnusedConnectionListMap.containsKey(propertyKey)) {
173176
ArrayList<Connection> connectionList = propertyKeyUnusedConnectionListMap.get(propertyKey);
174177
if (0 != connectionList.size()) {
@@ -203,6 +206,10 @@ public Statement getStatement(String propertyKey, String paragraphId)
203206
} else {
204207
connection = getConnection(propertyKey);
205208
}
209+
210+
if (connection == null) {
211+
return null;
212+
}
206213

207214
Statement statement = connection.createStatement();
208215
if (isStatementClosed(statement)) {
@@ -232,6 +239,10 @@ public InterpreterResult executeSql(String propertyKey, String sql,
232239

233240
Statement statement = getStatement(propertyKey, paragraphId);
234241

242+
if (statement == null) {
243+
return new InterpreterResult(Code.ERROR, "Prefix not found.");
244+
}
245+
235246
statement.setMaxRows(getMaxResult());
236247

237248
StringBuilder msg;
@@ -315,10 +326,8 @@ private void moveConnectionToUnused(String propertyKey, String paragraphId) {
315326
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
316327
String propertyKey = getPropertyKey(cmd);
317328

318-
if (null != propertyKey) {
329+
if (null != propertyKey && !propertyKey.equals(DEFAULT_KEY)) {
319330
cmd = cmd.substring(propertyKey.length() + 2);
320-
} else {
321-
propertyKey = DEFAULT_KEY;
322331
}
323332

324333
cmd = cmd.trim();
@@ -334,17 +343,19 @@ private int getMaxResult() {
334343
}
335344

336345
public String getPropertyKey(String cmd) {
337-
int firstLineIndex = cmd.indexOf("\n");
338-
if (-1 == firstLineIndex) {
339-
firstLineIndex = cmd.length();
340-
}
341-
int configStartIndex = cmd.indexOf("(");
342-
int configLastIndex = cmd.indexOf(")");
343-
if (configStartIndex != -1 && configLastIndex != -1
344-
&& configLastIndex < firstLineIndex && configLastIndex < firstLineIndex) {
345-
return cmd.substring(configStartIndex + 1, configLastIndex);
346+
boolean firstLineIndex = cmd.startsWith("(");
347+
348+
if (firstLineIndex) {
349+
int configStartIndex = cmd.indexOf("(");
350+
int configLastIndex = cmd.indexOf(")");
351+
if (configStartIndex != -1 && configLastIndex != -1) {
352+
return cmd.substring(configStartIndex + 1, configLastIndex);
353+
} else {
354+
return null;
355+
}
356+
} else {
357+
return DEFAULT_KEY;
346358
}
347-
return null;
348359
}
349360

350361
@Override

hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,53 @@ public static void setUp() throws Exception {
6666
@After
6767
public void tearDown() throws Exception {
6868
}
69+
70+
@Test
71+
public void testForParsePropertyKey() throws IOException {
72+
HiveInterpreter t = new HiveInterpreter(new Properties());
73+
74+
assertEquals(t.getPropertyKey("(fake) select max(cant) from test_table where id >= 2452640"),
75+
"fake");
76+
77+
assertEquals(t.getPropertyKey("() select max(cant) from test_table where id >= 2452640"),
78+
"");
79+
80+
assertEquals(t.getPropertyKey(")fake( select max(cant) from test_table where id >= 2452640"),
81+
"default");
82+
83+
// when you use a %hive(prefix1), prefix1 is the propertyKey as form part of the cmd string
84+
assertEquals(t.getPropertyKey("(prefix1)\n select max(cant) from test_table where id >= 2452640"),
85+
"prefix1");
86+
87+
assertEquals(t.getPropertyKey("(prefix2) select max(cant) from test_table where id >= 2452640"),
88+
"prefix2");
89+
90+
// when you use a %hive, prefix is the default
91+
assertEquals(t.getPropertyKey("select max(cant) from test_table where id >= 2452640"),
92+
"default");
93+
}
94+
95+
@Test
96+
public void testForMapPrefix() throws SQLException, IOException {
97+
Properties properties = new Properties();
98+
properties.setProperty("common.max_count", "1000");
99+
properties.setProperty("common.max_retry", "3");
100+
properties.setProperty("default.driver", "org.h2.Driver");
101+
properties.setProperty("default.url", getJdbcConnection());
102+
properties.setProperty("default.user", "");
103+
properties.setProperty("default.password", "");
104+
HiveInterpreter t = new HiveInterpreter(properties);
105+
t.open();
69106

107+
String sqlQuery = "(fake) select * from test_table";
108+
109+
InterpreterResult interpreterResult = t.interpret(sqlQuery, new InterpreterContext("", "1", "", "", null, null, null, null, null, null, null));
110+
111+
// if prefix not found return ERROR and Prefix not found.
112+
assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
113+
assertEquals("Prefix not found.", interpreterResult.message());
114+
}
115+
70116
@Test
71117
public void readTest() throws IOException {
72118
Properties properties = new Properties();

jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.apache.zeppelin.interpreter.Interpreter;
3535
import org.apache.zeppelin.interpreter.InterpreterContext;
36+
import org.apache.zeppelin.interpreter.InterpreterException;
3637
import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder;
3738
import org.apache.zeppelin.interpreter.InterpreterResult;
3839
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
@@ -172,6 +173,9 @@ public void open() {
172173

173174
public Connection getConnection(String propertyKey) throws ClassNotFoundException, SQLException {
174175
Connection connection = null;
176+
if (propertyKey == null || propertiesMap.get(propertyKey) == null) {
177+
return null;
178+
}
175179
if (propertyKeyUnusedConnectionListMap.containsKey(propertyKey)) {
176180
ArrayList<Connection> connectionList = propertyKeyUnusedConnectionListMap.get(propertyKey);
177181
if (0 != connectionList.size()) {
@@ -206,6 +210,10 @@ public Statement getStatement(String propertyKey, String paragraphId)
206210
} else {
207211
connection = getConnection(propertyKey);
208212
}
213+
214+
if (connection == null) {
215+
return null;
216+
}
209217

210218
Statement statement = connection.createStatement();
211219
if (isStatementClosed(statement)) {
@@ -260,6 +268,10 @@ private InterpreterResult executeSql(String propertyKey, String sql,
260268
try {
261269

262270
Statement statement = getStatement(propertyKey, paragraphId);
271+
272+
if (statement == null) {
273+
return new InterpreterResult(Code.ERROR, "Prefix not found.");
274+
}
263275
statement.setMaxRows(getMaxResult());
264276

265277
StringBuilder msg = null;
@@ -344,12 +356,10 @@ public InterpreterResult interpret(String cmd, InterpreterContext contextInterpr
344356
logger.info("Run SQL command '{}'", cmd);
345357
String propertyKey = getPropertyKey(cmd);
346358

347-
if (null != propertyKey) {
359+
if (null != propertyKey && !propertyKey.equals(DEFAULT_KEY)) {
348360
cmd = cmd.substring(propertyKey.length() + 2);
349-
} else {
350-
propertyKey = DEFAULT_KEY;
351361
}
352-
362+
353363
cmd = cmd.trim();
354364

355365
logger.info("PropertyKey: {}, SQL command: '{}'", propertyKey, cmd);
@@ -371,17 +381,19 @@ public void cancel(InterpreterContext context) {
371381
}
372382

373383
public String getPropertyKey(String cmd) {
374-
int firstLineIndex = cmd.indexOf("\n");
375-
if (-1 == firstLineIndex) {
376-
firstLineIndex = cmd.length();
377-
}
378-
int configStartIndex = cmd.indexOf("(");
379-
int configLastIndex = cmd.indexOf(")");
380-
if (configStartIndex != -1 && configLastIndex != -1
381-
&& configLastIndex < firstLineIndex && configLastIndex < firstLineIndex) {
382-
return cmd.substring(configStartIndex + 1, configLastIndex);
384+
boolean firstLineIndex = cmd.startsWith("(");
385+
386+
if (firstLineIndex) {
387+
int configStartIndex = cmd.indexOf("(");
388+
int configLastIndex = cmd.indexOf(")");
389+
if (configStartIndex != -1 && configLastIndex != -1) {
390+
return cmd.substring(configStartIndex + 1, configLastIndex);
391+
} else {
392+
return null;
393+
}
394+
} else {
395+
return DEFAULT_KEY;
383396
}
384-
return null;
385397
}
386398

387399
@Override

jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,53 @@ public void setUp() throws Exception {
6969
);
7070
}
7171

72+
73+
@Test
74+
public void testForParsePropertyKey() throws IOException {
75+
JDBCInterpreter t = new JDBCInterpreter(new Properties());
76+
77+
assertEquals(t.getPropertyKey("(fake) select max(cant) from test_table where id >= 2452640"),
78+
"fake");
79+
80+
assertEquals(t.getPropertyKey("() select max(cant) from test_table where id >= 2452640"),
81+
"");
82+
83+
assertEquals(t.getPropertyKey(")fake( select max(cant) from test_table where id >= 2452640"),
84+
"default");
85+
86+
// when you use a %jdbc(prefix1), prefix1 is the propertyKey as form part of the cmd string
87+
assertEquals(t.getPropertyKey("(prefix1)\n select max(cant) from test_table where id >= 2452640"),
88+
"prefix1");
89+
90+
assertEquals(t.getPropertyKey("(prefix2) select max(cant) from test_table where id >= 2452640"),
91+
"prefix2");
92+
93+
// when you use a %jdbc, prefix is the default
94+
assertEquals(t.getPropertyKey("select max(cant) from test_table where id >= 2452640"),
95+
"default");
96+
}
97+
98+
@Test
99+
public void testForMapPrefix() throws SQLException, IOException {
100+
Properties properties = new Properties();
101+
properties.setProperty("common.max_count", "1000");
102+
properties.setProperty("common.max_retry", "3");
103+
properties.setProperty("default.driver", "org.h2.Driver");
104+
properties.setProperty("default.url", getJdbcConnection());
105+
properties.setProperty("default.user", "");
106+
properties.setProperty("default.password", "");
107+
JDBCInterpreter t = new JDBCInterpreter(properties);
108+
t.open();
109+
110+
String sqlQuery = "(fake) select * from test_table";
111+
112+
InterpreterResult interpreterResult = t.interpret(sqlQuery, new InterpreterContext("", "1", "","", null,null,null,null,null,null));
113+
114+
// if prefix not found return ERROR and Prefix not found.
115+
assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
116+
assertEquals("Prefix not found.", interpreterResult.message());
117+
}
118+
72119
@Test
73120
public void testDefaultProperties() throws SQLException {
74121
JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(new Properties());

0 commit comments

Comments
 (0)