incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/3] git commit: Updates to the jdbc code and adding docs.
Date Tue, 27 Aug 2013 20:36:53 GMT
Updates to the jdbc code and adding docs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/22960213
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/22960213
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/22960213

Branch: refs/heads/master
Commit: 2296021315e41d743aece287a810f28932c30308
Parents: 7c22a82
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Aug 27 16:35:30 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Aug 27 16:35:30 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/jdbc/BlurResultSetRecords.java  |   2 +-
 .../org/apache/blur/jdbc/BlurResultSetRows.java |   2 +-
 .../org/apache/blur/jdbc/BlurStatement.java     |   4 ++
 .../org/apache/blur/jdbc/parser/Parser.java     |  70 ++++++++++++-------
 .../org/apache/blur/jdbc/parser/ParserTest.java |  44 ++++++++++++
 docs/resources/css/bs-docs.css                  |  13 ++++
 docs/resources/img/SQuirrel.png                 | Bin 0 -> 77735 bytes
 docs/using-blur.base.html                       |  19 ++++-
 8 files changed, 125 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRecords.java
----------------------------------------------------------------------
diff --git a/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRecords.java b/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRecords.java
index 407a263..7c05cdf 100644
--- a/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRecords.java
+++ b/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRecords.java
@@ -152,7 +152,7 @@ public class BlurResultSetRecords extends AbstractBlurResultSet {
         final BlurResult result = results.results.get(resultPosition);
         try {
           FetchRecordResult recordResult = result.getFetchResult().getRecordResult();
-          selector.setRecordId(recordResult.getRowid());
+          selector.setRowId(recordResult.getRowid());
           selector.setRecordId(recordResult.getRecord().getRecordId());
           fetchResult = client.fetchRow(tableName, selector);
           Record record = fetchResult.recordResult.record;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRows.java
----------------------------------------------------------------------
diff --git a/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRows.java b/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRows.java
index a3960d9..910643e 100644
--- a/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRows.java
+++ b/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurResultSetRows.java
@@ -98,7 +98,7 @@ public class BlurResultSetRows extends AbstractBlurResultSet {
       e.printStackTrace();
       throw new SQLException(e);
     }
-
+System.out.println(schema);
     selector = new Selector();
     setupSelector(selector, schema, columnNames);
     selector.recordOnly = !blurQuery.query.rowQuery;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurStatement.java
----------------------------------------------------------------------
diff --git a/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurStatement.java b/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurStatement.java
index eed24a2..b188554 100644
--- a/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurStatement.java
+++ b/blur-jdbc/src/main/java/org/apache/blur/jdbc/BlurStatement.java
@@ -70,6 +70,7 @@ public class BlurStatement extends AbstractBlurStatement {
       Parser parser = new Parser();
       parser.parse(sql);
       if (isSuperQuery(parser, client)) {
+        System.out.println("super");
         return new BlurResultSetRows(client, parser);
       } else {
         return new BlurResultSetRecords(client, parser);
@@ -88,6 +89,9 @@ public class BlurStatement extends AbstractBlurStatement {
       return true;
     }
     int lastIndexOf = tableName.lastIndexOf('.');
+    if (lastIndexOf < 0) {
+      throw new SQLException("Table [" + tableName + "] does not exist.");  
+    }
     if (tableList.contains(tableName.substring(0, lastIndexOf))) {
       return false;
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
----------------------------------------------------------------------
diff --git a/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java b/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
index c8b7287..bb57789 100644
--- a/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
+++ b/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
@@ -26,9 +26,7 @@ public class Parser {
 
   private static final String SELECT = "select";
   private static final String WHERE = "where";
-  private static final String NATURAL = "natural";
   private static final String FROM = "from";
-  private static final String JOIN = "join";
   private static final String SEP = new String(new char[] { 1 });
 
   public static void main(String[] args) {
@@ -47,35 +45,16 @@ public class Parser {
   private String where;
   private String tableName;
   private List<String> columnNames;
-  private String joinTable;
+  private String tableNameAlias;
 
   public Parser parse(String query) {
     columnNames = getColumnNames(query);
     tableName = getTableName(query);
+    tableNameAlias = getTableNameAlias(query);
     where = getWhere(query);
-    joinTable = getJoin(query);
     return this;
   }
 
-  public String getJoinTable() {
-    return joinTable;
-  }
-
-  private String getJoin(String query) {
-    String table = null;
-    StringTokenizer tokenizer = new StringTokenizer(query);
-    while (tokenizer.hasMoreTokens()) {
-      if (NATURAL.equals(tokenizer.nextToken().toLowerCase())) {
-        if (JOIN.equals(tokenizer.nextToken().toLowerCase())) {
-          table = tokenizer.nextToken();
-        } else {
-          throw new RuntimeException();
-        }
-      }
-    }
-    return table;
-  }
-
   private String getWhere(String query) {
     StringBuilder result = new StringBuilder();
     StringTokenizer tokenizer = new StringTokenizer(query);
@@ -159,6 +138,26 @@ public class Parser {
     throw new IllegalArgumentException("Table not found");
   }
 
+  private String getTableNameAlias(String query) {
+    StringTokenizer tokenizer = new StringTokenizer(query);
+    while (tokenizer.hasMoreTokens()) {
+      if (FROM.equals(tokenizer.nextToken().toLowerCase())) {
+        while (tokenizer.hasMoreTokens()) {
+          tokenizer.nextToken();//table
+          if (!tokenizer.hasMoreTokens()) {
+            return null;
+          }
+          String token = tokenizer.nextToken().toLowerCase();
+          if (WHERE.equals(token)) {
+            return null;
+          }
+          return token;
+        }
+      }
+    }
+    return null;
+  }
+
   private List<String> getColumnNames(String query) {
     StringTokenizer tokenizer = new StringTokenizer(query);
     List<String> columnNames = new ArrayList<String>();
@@ -184,11 +183,30 @@ public class Parser {
   }
 
   public String getTableName() {
-    return tableName;
+    return trimLiteralChars(tableName);
+  }
+
+  private static String trimLiteralChars(String s) {
+    if (s.startsWith("'") && s.endsWith("'")) {
+      return s.substring(1, s.length() - 1);
+    }
+    return s;
   }
 
   public List<String> getColumnNames() {
-    return columnNames;
+    return removeTableAliases(columnNames);
+  }
+
+  private List<String> removeTableAliases(List<String> columnNames) {
+    List<String> result = new ArrayList<String>();
+    for (String col : columnNames) {
+      if (col.startsWith(tableNameAlias + ".")) {
+        result.add(col.substring(tableNameAlias.length() + 1));
+      } else {
+        result.add(col);
+      }
+    }
+    return result;
   }
 
   public String getWhere() {
@@ -200,6 +218,6 @@ public class Parser {
 
   @Override
   public String toString() {
-    return "Parser [columnNames=" + columnNames + ", tableName=" + tableName + ", where="
+ where + ", joinTable=" + joinTable + "]";
+    return "Parser [columnNames=" + columnNames + ", tableName=" + tableName + ", where="
+ where + "]";
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java
----------------------------------------------------------------------
diff --git a/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java b/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java
new file mode 100644
index 0000000..8162907
--- /dev/null
+++ b/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java
@@ -0,0 +1,44 @@
+package org.apache.blur.jdbc.parser;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class ParserTest {
+
+  @Test
+  public void test1() {
+    Parser parser = new Parser();
+    parser.parse("select * from table1");
+    assertEquals("table1", parser.getTableName());
+    List<String> columnNames = parser.getColumnNames();
+    assertEquals(1, columnNames.size());
+    assertEquals("*", columnNames.get(0));
+    assertEquals("*", parser.getWhere());
+  }
+  
+  @Test
+  public void test2() {
+    Parser parser = new Parser();
+    parser.parse("select * from 'table1'");
+    assertEquals("table1", parser.getTableName());
+    List<String> columnNames = parser.getColumnNames();
+    assertEquals(1, columnNames.size());
+    assertEquals("*", columnNames.get(0));
+    assertEquals("*", parser.getWhere());
+  }
+  
+  @Test
+  public void test3() {
+    Parser parser = new Parser();
+    parser.parse("select tbl.* from 'table1' tbl");
+    assertEquals("table1", parser.getTableName());
+    List<String> columnNames = parser.getColumnNames();
+    assertEquals(1, columnNames.size());
+    assertEquals("*", columnNames.get(0));
+    assertEquals("*", parser.getWhere());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/docs/resources/css/bs-docs.css
----------------------------------------------------------------------
diff --git a/docs/resources/css/bs-docs.css b/docs/resources/css/bs-docs.css
index f3e3b13..6357f90 100644
--- a/docs/resources/css/bs-docs.css
+++ b/docs/resources/css/bs-docs.css
@@ -927,3 +927,16 @@ body {
   }
 
 }
+
+h1[id] {
+margin-top: -50px;
+padding-top: 80px;
+}
+h3[id] {
+margin-top: -60px;
+padding-top: 80px;
+}
+h4[id] {
+margin-top: -60px;
+padding-top: 80px;
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/docs/resources/img/SQuirrel.png
----------------------------------------------------------------------
diff --git a/docs/resources/img/SQuirrel.png b/docs/resources/img/SQuirrel.png
new file mode 100644
index 0000000..204cd10
Binary files /dev/null and b/docs/resources/img/SQuirrel.png differ

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/22960213/docs/using-blur.base.html
----------------------------------------------------------------------
diff --git a/docs/using-blur.base.html b/docs/using-blur.base.html
index 460ed91..35e70cc 100644
--- a/docs/using-blur.base.html
+++ b/docs/using-blur.base.html
@@ -340,7 +340,24 @@ default text files.
             <div class="page-header">
               <h1 id="jdbc">JDBC</h1>
             </div>
-            <p>TODO</p>
+            <p>
+The JDBC driver is very experimental and is currently read-only.  It has a very basic SQL-ish
+language that should allow for most Blur queries.
+
+Basic SQL syntax will work for example:<br/>
+<pre><code class="bash">select * from testtable where fam1.col1 = 'val1'</code></pre>
+
+You may also use Lucene syntax by wrapping the Lucene query in a &quot;query()&quot;
function:<br/>
+<pre><code class="bash">select * from testtable where query(fam1.col1:val?)</code></pre>
+
+Here is a screenshot of the JDBC driver in SQuirrel:
+
+<img src="resources/img/SQuirrel.png">
+<br/>
+<br/>
+<br/>
+<br/>
+</p>
           </section>
         </div>
       </div>


Mime
View raw message