Changing license header to Apache for blur-demo.

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

Branch: refs/heads/master
Commit: 358a209d24d09ec3b57d2b20a07f82ce2809bc3a
Parents: 85a1252
Author: Aaron McCurry <[email protected]>
Authored: Sun Sep 2 21:52:53 2012 -0400
Committer: Aaron McCurry <[email protected]>
Committed: Sun Sep 2 21:52:53 2012 -0400

----------------------------------------------------------------------
 src/blur-demo/jar.sh                               |   17 +
 src/blur-demo/pom.xml                              |   19 +
 .../com/nearinfinity/blur/demo/DemoClient.java     |   63 ---
 .../java/com/nearinfinity/blur/demo/Indexer.java   |  360 ---------------
 .../com/nearinfinity/blur/demo/SampleProgram.java  |  288 ++++++------
 5 files changed, 183 insertions(+), 564 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/358a209d/src/blur-demo/jar.sh
----------------------------------------------------------------------
diff --git a/src/blur-demo/jar.sh b/src/blur-demo/jar.sh
index b3ec201..ae52d94 100755
--- a/src/blur-demo/jar.sh
+++ b/src/blur-demo/jar.sh
@@ -1 +1,18 @@
+#!/bin/sh
+
+# 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.
+
 mvn assembly:single

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/358a209d/src/blur-demo/pom.xml
----------------------------------------------------------------------
diff --git a/src/blur-demo/pom.xml b/src/blur-demo/pom.xml
index 485a022..5edb28f 100644
--- a/src/blur-demo/pom.xml
+++ b/src/blur-demo/pom.xml
@@ -1,3 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+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.
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
        <parent>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/358a209d/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/DemoClient.java
----------------------------------------------------------------------
diff --git 
a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/DemoClient.java 
b/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/DemoClient.java
deleted file mode 100644
index 42722bf..0000000
--- a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/DemoClient.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.nearinfinity.blur.demo;
-
-
-public class DemoClient {
-
-    public static void main(String[] args) throws Exception {
-//        BlurCommand<Void> command = new BlurCommand<Void>() {
-//            @Override
-//            public Void call(Client client) throws Exception {
-//                Random random = new Random();
-//                BlurQuery blurQuery = new BlurQuery();
-//                
-//                
-//                blurQuery.queryStr = "employee.name:john";
-//                blurQuery.queryStr = "manager.salary:000000001*";
-////                blurQuery.queryStr = "department.moreThanOneDepartment:T";
-////                blurQuery.queryStr = "salary.makesMoreThanManager:T";
-////                blurQuery.queryStr = "employee.birthDate:[1960-02-08 TO 
1964-02-08]";
-//                blurQuery.queryStr = "+title.title:\"Technique Leader\" 
+department.name:\"Overpowering Department\"";
-////                blurQuery.queryStr = "+title.title:\"Senior Staff\" 
+salary.salary:[00000000100000 TO 00000000101000] 
+department.name:(\"Retreating Department\" \"Overpowering Department\")";
-//                
-//                
-//                
-//                blurQuery.fetch = 25;
-//                blurQuery.superQueryOn = true;
-//                blurQuery.uuid = random.nextLong();
-//                String table = "employee_super_mart";
-//                BlurResults results = client.query(table, blurQuery);
-//                System.out.println("totalResults=" + results.totalResults);
-//                for (BlurResult result : results.results) {
-//                    Selector selector = new Selector();
-//                    selector.setLocationId(result.locationId);
-//                    FetchResult fetchRow = client.fetchRow(table, selector);
-//                    FetchRowResult rowResult = fetchRow.rowResult;
-//                    Row row = rowResult.row;
-//                    System.out.println(row.id);
-//                    for (ColumnFamily columnFamily : row.columnFamilies) {
-//                        System.out.println("\t" + columnFamily.family);
-//                        Map<String, Set<Column>> records = 
columnFamily.records;
-//                        for (String recordId : records.keySet()) {
-//                            System.out.print("\t\t" + recordId);
-//                            for (Column column : records.get(recordId)) {
-//                                System.out.print(" " + column.name + ":" + 
column.values.get(0));
-//                            }
-//                            System.out.println();
-//                        }
-//                        
-//                    }
-//                }
-//                return null;
-//            }
-//        };
-//        
-//        for (int i = 0; i < 1000000; i++) {
-//            long s = System.nanoTime();
-//            BlurClientManager.execute("blur04.nearinfinity.com:40020", 
command);
-//            long e = System.nanoTime();
-//            System.out.println((e-s) / 1000000.0);
-//        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/358a209d/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/Indexer.java
----------------------------------------------------------------------
diff --git 
a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/Indexer.java 
b/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/Indexer.java
deleted file mode 100644
index 587f30e..0000000
--- a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/Indexer.java
+++ /dev/null
@@ -1,360 +0,0 @@
-package com.nearinfinity.blur.demo;
-
-
-public class Indexer {
-
-//    public static void main(String[] args) throws CorruptIndexException, 
LockObtainFailedException, IOException, URISyntaxException {
-//        
//"hdfs://localhost:9000/user/hive/warehouse/employee_super_mart/000000_0"
-//        URI uri = new URI(args[0]);
-//        BlurAnalyzer analyzer = new BlurAnalyzer(new 
StandardAnalyzer(Version.LUCENE_30));
-//        Directory dir = FSDirectory.open(new File("./index"));
-//        IndexWriter indexWriter = new IndexWriter(dir, analyzer, 
MaxFieldLength.UNLIMITED);
-//        indexWriter.setUseCompoundFile(false);
-//        indexWriter.setSimilarity(new FairSimilarity());
-//        RowIndexWriter writer  = new RowIndexWriter(indexWriter, analyzer);
-//        
-//        FileSystem fileSystem = FileSystem.get(uri, new Configuration());
-//        FSDataInputStream inputStream = fileSystem.open(new 
Path(uri.getPath()));
-//        BufferedReader reader = new BufferedReader(new 
InputStreamReader(inputStream));
-//        String line;
-//        Row row = new Row();
-//        String[] values = new String[25];
-//        int max = 1000;
-//        int total = 0;
-//        int count = 0;
-//        while ((line = reader.readLine()) != null) {
-//            if (count >= max) {
-//                System.out.println("Total [" + total + "]");
-//                count = 0;
-//            }
-//            long hash = parse(line,values);
-//            String rowId = values[0];
-//            if (!rowId.equals(row.id)) {
-//                addRow(row,writer);
-//                row = new Row().setId(rowId);
-//            }
-//            addRecord(row,values,hash);
-//            total++;
-//            count++;
-//        }
-//        addRow(row,writer);
-//        indexWriter.optimize();
-//        indexWriter.close();
-//    }
-//
-//    private static void addRow(Row row, RowIndexWriter writer) throws 
IOException {
-//        if (row.id != null) {
-//            fixStuff(row);
-//            writer.replace(row);
-//        }
-//    }
-//
-//    private static void fixStuff(Row row) {
-//        String managerSalary = null;
-//        String employeeSalary = null;
-//        Set<ColumnFamily> columnFamilies = row.columnFamilies;
-//        ColumnFamily empCf = null;
-//        for (ColumnFamily cf : columnFamilies) {
-//            if (cf.family.equals("manager")) {
-//                Collection<Set<Column>> values = cf.records.values();
-//                for (Set<Column> cols : values) {
-//                    for (Column column : cols) {
-//                        if (column.name.equals("salary")) {
-//                            managerSalary = column.values.get(0);
-//                        }
-//                    }
-//                }
-//            }
-//            if (cf.family.equals("salary")) {
-//                empCf = cf;
-//                Collection<Set<Column>> values = cf.records.values();
-//                for (Set<Column> cols : values) {
-//                    for (Column column : cols) {
-//                        if (column.name.equals("salary")) {
-//                            employeeSalary = column.values.get(0);
-//                        }
-//                    }
-//                }
-//            }
-//        }
-//        long man = Long.parseLong(managerSalary);
-//        long emp = Long.parseLong(employeeSalary);
-//        if (emp > man) {
-//            Collection<Set<Column>> values = empCf.records.values();
-//            Set<Column> cols = values.iterator().next();
-//            Column column = new Column().setName("makesMoreThanManager");
-//            column.addToValues("T");
-//            cols.add(column);
-//        }
-//    }
-//
-//    private static void addRecord(Row row, String[] values, long hash) {
-//        String cf = values[11];
-//        if ("employee".equals(cf)) {
-//            addEmployee(row,values,hash);
-//        } else if ("title".equals(cf)) {
-//            addTitle(row,values,hash);
-//        } else if ("title_history".equals(cf)) {
-//            addTitleHistory(row,values,hash);
-//        } else if ("salary".equals(cf)) {
-//            addSalary(row,values,hash);
-//        } else if ("salary_history".equals(cf)) {
-//            addSalaryHistory(row,values,hash);
-//        } else if ("manager".equals(cf)) {
-//            addManager(row,values,hash);
-//        } else if ("department".equals(cf)) {
-//            addDepartment(row,values,hash);
-//        } else if ("department_history".equals(cf)) {
-//            addDepartmentHistory(row,values,hash);
-////        } else if ("title_salary".equals(cf)) {
-////            addTitleSalary(row,values,hash);
-//        } else {
-//            for (int i = 0; i < values.length; i++) {
-//                System.out.println("i=" + i + " value=" + values[i]);
-//            }
-//            throw new RuntimeException("Column Family [" + cf + "] Not 
Found");
-//        }
-//    }
-//
-//    private static void addTitleHistory(Row row, String[] values, long hash) 
{
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "titleHistory";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        //from_date, to_date, title
-//        Column fromDate = new Column().setName("fromDate");
-//        fromDate.addToValues(values[2]);
-//        Column toDate = new Column().setName("toDate");
-//        toDate.addToValues(values[3]);
-//        Column title = new Column().setName("title");
-//        title.addToValues(values[1]);
-//        
-//        cols.add(fromDate);
-//        cols.add(toDate);
-//        cols.add(title);
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//    
-//    private static void addManager(Row row, String[] values, long hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "manager";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-////        de.from_date, 
-////        de.to_date, 
-////        d.dept_name as col1, 
-////        dm.from_date as col2, 
-////        dm.to_date as col3, 
-////        e2.emp_no as col4, 
-////        e2.first_name as col5, 
-////        e2.last_name as col6,
-//        
-//        //from_date, to_date, title
-//        Column manEmpNo = new Column().setName("managerEmpNo");
-//        manEmpNo.addToValues(values[1]);
-//        Column birthDate = new Column().setName("birthDate");
-//        birthDate.addToValues(values[2]);
-//        Column firstName = new Column().setName("firstName");
-//        firstName.addToValues(values[3]);
-//        Column lastName = new Column().setName("lastName");
-//        lastName.addToValues(values[4]);
-//        Column gender = new Column().setName("gender");
-//        gender.addToValues(values[5]);
-//        Column hireDate = new Column().setName("hireDate");
-//        hireDate.addToValues(values[6]);
-//        Column salary = new Column().setName("salary");
-//        salary.addToValues(bufferSalary(values[7]));
-//        Column fromDate = new Column().setName("fromDate");
-//        fromDate.addToValues(values[8]);
-//        Column toDate = new Column().setName("toDate");
-//        toDate.addToValues(values[9]);
-//        
-//        cols.add(manEmpNo);
-//        cols.add(birthDate);
-//        cols.add(firstName);
-//        cols.add(lastName);
-//        cols.add(gender);
-//        cols.add(hireDate);
-//        cols.add(salary);
-//        cols.add(fromDate);
-//        cols.add(toDate);
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//
-//    private static void addDepartment(Row row, String[] values, long hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "department";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        Column deptNo = new Column().setName("deptNo");
-//        deptNo.addToValues(values[1]);
-//        Column name = new Column().setName("name");
-//        name.addToValues(values[2]);
-//        Column moreThanOneDepartment = new 
Column().setName("moreThanOneDepartment");
-//        moreThanOneDepartment.addToValues(values[3]);
-//        
-//        cols.add(moreThanOneDepartment);
-//        cols.add(name);
-//        cols.add(deptNo);
-//        
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//    
-//    private static void addDepartmentHistory(Row row, String[] values, long 
hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "departmentHistory";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        Column deptNo = new Column().setName("deptNo");
-//        deptNo.addToValues(values[1]);
-//        Column name = new Column().setName("name");
-//        name.addToValues(values[2]);
-//        
-//        cols.add(name);
-//        cols.add(deptNo);
-//        
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//
-////    private static void addTitleSalary(Row row, String[] values, long 
hash) {
-////        
-////    }
-//
-//    private static void addTitle(Row row, String[] values, long hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "title";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        //from_date, to_date, title
-//        Column fromDate = new Column().setName("fromDate");
-//        fromDate.addToValues(values[2]);
-//        Column toDate = new Column().setName("toDate");
-//        toDate.addToValues(values[3]);
-//        Column title = new Column().setName("title");
-//        title.addToValues(values[1]);
-//        
-//        cols.add(fromDate);
-//        cols.add(toDate);
-//        cols.add(title);
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//
-//    private static void addSalary(Row row, String[] values, long hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "salary";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        //from_date, to_date, salary
-//        Column fromDate = new Column().setName("fromDate");
-//        fromDate.addToValues(values[2]);
-//        Column toDate = new Column().setName("toDate");
-//        toDate.addToValues(values[3]);
-//        Column salary = new Column().setName("salary");
-//        salary.addToValues(bufferSalary(values[1]));
-//        
-//        cols.add(fromDate);
-//        cols.add(toDate);
-//        cols.add(salary);
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//    
-//    private static void addSalaryHistory(Row row, String[] values, long 
hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "salaryHistory";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        //from_date, to_date, salary
-//        Column fromDate = new Column().setName("fromDate");
-//        fromDate.addToValues(values[2]);
-//        Column toDate = new Column().setName("toDate");
-//        toDate.addToValues(values[3]);
-//        Column salary = new Column().setName("salary");
-//        salary.addToValues(bufferSalary(values[1]));
-//        
-//        cols.add(fromDate);
-//        cols.add(toDate);
-//        cols.add(salary);
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//
-//    private static String bufferSalary(String s) {
-//        while (s.length() < 14) {
-//            s = "0" + s;
-//        }
-//        return s;
-//    }
-//
-//    private static void addEmployee(Row row, String[] values, long hash) {
-//        ColumnFamily columnFamily = new ColumnFamily();
-//        columnFamily.family = "employee";
-//        Set<Column> cols = new HashSet<Column>();
-//        
-//        //from_date, to_date, birth_date, first_name, last_name, gender
-////        Column fromDate = new Column().setName("fromDate");
-////        fromDate.addToValues(values[2]);
-////        Column toDate = new Column().setName("toDate");
-////        toDate.addToValues(values[3]);
-//        Column birthDate = new Column().setName("birthDate");
-//        birthDate.addToValues(values[1]);
-//        Column firstName = new Column().setName("firstName");
-//        firstName.addToValues(values[2]);
-//        Column lastName = new Column().setName("lastName");
-//        lastName.addToValues(values[3]);
-//        Column gender = new Column().setName("gender");
-//        gender.addToValues(values[4]);
-//        Column hireDate = new Column().setName("hireDate");
-//        hireDate.addToValues(values[5]);
-//        
-//        Column name = new Column().setName("name");
-//        name.addToValues(values[2] + " " + values[3]);
-//        
-////        cols.add(fromDate);
-////        cols.add(toDate);
-//        cols.add(birthDate);
-//        cols.add(firstName);
-//        cols.add(lastName);
-//        cols.add(gender);
-//        cols.add(name);
-//        cols.add(hireDate);
-//        
-//        columnFamily.putToRecords(Long.toString(Math.abs(hash)), cols);
-//        row.addToColumnFamilies(columnFamily);
-//    }
-//
-//    private static long parse(String line, String[] values) {
-//        int start = 0;
-//        int index = line.indexOf('\t',start);
-//        int i = 0;
-//        long hash = line.length();
-//        while (index >= 0) {
-//            String token = line.substring(start, index);
-//            values[i++] = token;
-//            start = index + 1;
-//            index = line.indexOf('\t',start);
-//            hash += 31L * token.hashCode();
-//        }
-//        String token = line.substring(start);
-//        values[i++] = token;
-//        
-////        StringTokenizer tokenizer = new StringTokenizer(line,"\t");
-////        int i = 0;
-////        long hash = line.length();
-////        while (tokenizer.hasMoreTokens()) {
-////            String token = tokenizer.nextToken();
-////            values[i++] = token;
-////            hash += 31L * token.hashCode();
-////        }
-////        for (; i < values.length; i++) {
-////            values[i] = null;
-////        }
-//        return hash;
-//    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/358a209d/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
----------------------------------------------------------------------
diff --git 
a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java 
b/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
index f287535..2af4c1d 100644
--- a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
+++ b/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
@@ -1,5 +1,21 @@
 package com.nearinfinity.blur.demo;
 
+/**
+ * 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.
+ */
 import static com.nearinfinity.blur.utils.BlurUtil.newColumn;
 import static com.nearinfinity.blur.utils.BlurUtil.newRecordMutation;
 import static com.nearinfinity.blur.utils.BlurUtil.newRowMutation;
@@ -22,147 +38,137 @@ import com.nearinfinity.blur.thrift.generated.Selector;
 import com.nearinfinity.blur.thrift.generated.TableDescriptor;
 
 public class SampleProgram {
-       
-       private static final String BLUR_CLUSTER_NAME = "default";
-       public static final String BLUR_CONTROLLER_HOSTNAME = "localhost";
-       public static final String BLUR_CONTROLLER_PORT = "40010";
-       
-       public static final String HDFS_NAMENODE_HOSTNAME = "localhost";
-       public static final String HDFS_NAMENODE_PORT = "9000";
-       
-       public static final String BLUR_TABLES_LOCATION = "/blur/tables/"; 
//Path must include trailing slash character
-       private static final int  MAX_SAMPLE_ROWS = 1000;
-       private static final int MAX_SEARCHES = 500;
-
-       public static void main(String[] args) {
-               try {
-                       //Connect
-                       Blur.Iface client = connect();
-                       
-                       //Delete all tables
-                       deleteAllTables(client);
-                       
-                       //Create a table
-                       String tableName = "SAMPLE_TABLE_" + 
System.currentTimeMillis();
-                       createTable(client, tableName);
-                       
-                       //List all the tables
-                       listTables(client);
-                       
-                       //Populate the table with data
-                       populateTable(client, tableName);
-                       
-                       //Run searches
-                       searchTable(client, tableName); 
-                       
-                       //Delete the table
-                       deleteTable(client, tableName);
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-               }
-
-       }
-
-
-       private static void deleteAllTables(Iface client) throws BlurException, 
TException {
-               List<String> tableList = listTables(client);
-               for (String tableName: tableList) {
-                       deleteTable(client, tableName);
-               }
-       }
-
-
-       private static Blur.Iface connect() {
-               String blurConnectionString = BLUR_CONTROLLER_HOSTNAME + ":" + 
BLUR_CONTROLLER_PORT;
-               System.out.println("Connecting to " + blurConnectionString);
-               Blur.Iface client = BlurClient.getClient(blurConnectionString);
-               System.out.println("Successfully connected to " + 
blurConnectionString);
-               return client;
-       }
-
-       private static void createTable(Iface client, String tableName) {
-               try {
-                       AnalyzerDefinition ad = new AnalyzerDefinition();
-
-                       TableDescriptor tableDescriptor = new 
TableDescriptor(); 
-                       tableDescriptor.setTableUri("hdfs://"+ 
HDFS_NAMENODE_HOSTNAME + ":" + HDFS_NAMENODE_PORT + BLUR_TABLES_LOCATION + 
tableName); 
-                       tableDescriptor.setAnalyzerDefinition(ad);
-                       tableDescriptor.setName(tableName);
-                       tableDescriptor.setCluster(BLUR_CLUSTER_NAME);
-
-                       System.out.println("About to create table " + 
tableName);
-                       client.createTable(tableDescriptor);
-                       System.out.println("Created table " + tableName);
-               } catch (BlurException e) {
-                       e.printStackTrace();
-               } catch (TException e) {
-                       e.printStackTrace();
-               }
-       }
-
-       
-       private static List<String> listTables(Blur.Iface client) {
-               try {
-                       System.out.println("Listing all tables");
-                       List<String> tableNames = client.tableList();
-                       for (String tableName:tableNames) {
-                               System.out.println("tableName=" + tableName);
-                       }
-                       return tableNames;
-               } catch (BlurException e) {
-                       e.printStackTrace();
-               } catch (TException e) {
-                       e.printStackTrace();
-               }
-               return null;
-       }
-       
-       
-       private static void populateTable(Iface client, String tableName) 
throws BlurException, TException {
-               Random random = new Random();
-               for (int count=1; count<= MAX_SAMPLE_ROWS; count++) {
-                       RowMutation mutation = newRowMutation(tableName, 
"rowid_" + count,
-                               newRecordMutation("sample", "recordid_1",
-                                       newColumn("sampleData", "data_" + 
random.nextInt(50000))));
-                       System.out.println("About to add rowid_" + count);
-                       client.mutate(mutation);
-                       System.out.println("Added rowid_" + count);
-               }
-               
-       }
-
-       private static void searchTable(Iface client, String tableName) throws 
BlurException, TException {
-               Random random = new Random();
-               for (int count=1; count<=MAX_SEARCHES; count++) {
-                       String rowid = "rowid_" + 
random.nextInt(MAX_SAMPLE_ROWS);
-                       Selector selector = new Selector();
-                       selector.setRowId(rowid);
-                       FetchResult fetchRow = client.fetchRow(tableName, 
selector);
-                       if (fetchRow != null) {
-                               FetchRowResult rowResult = 
fetchRow.getRowResult();
-                               if (rowResult != null) {
-                                       Row row = rowResult.getRow();
-                                       if (row != null) {
-                                               System.out.println("Found " + 
rowid);
-                                       }
-
-                               }
-                       }
-                       else {
-                               System.out.println("Could not find " + rowid);
-                       }
-               }
-               
-       }
-       
-       
-       private static void deleteTable(Iface client, String tableName) throws 
BlurException, TException {
-               client.disableTable(tableName);
-               client.removeTable(tableName, true);            
-               System.out.println("Deleted table " + tableName);
-       }
-
 
+  private static final String BLUR_CLUSTER_NAME = "default";
+  public static final String BLUR_CONTROLLER_HOSTNAME = "localhost";
+  public static final String BLUR_CONTROLLER_PORT = "40010";
+
+  public static final String HDFS_NAMENODE_HOSTNAME = "localhost";
+  public static final String HDFS_NAMENODE_PORT = "9000";
+
+  // Path must include trailing slash character
+  public static final String BLUR_TABLES_LOCATION = "/blur/tables/";
+  private static final int MAX_SAMPLE_ROWS = 1000;
+  private static final int MAX_SEARCHES = 500;
+
+  public static void main(String[] args) {
+    try {
+      // Connect
+      Blur.Iface client = connect();
+
+      // Delete all tables
+      deleteAllTables(client);
+
+      // Create a table
+      String tableName = "SAMPLE_TABLE_" + System.currentTimeMillis();
+      createTable(client, tableName);
+
+      // List all the tables
+      listTables(client);
+
+      // Populate the table with data
+      populateTable(client, tableName);
+
+      // Run searches
+      searchTable(client, tableName);
+
+      // Delete the table
+      deleteTable(client, tableName);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+  }
+
+  private static void deleteAllTables(Iface client) throws BlurException, 
TException {
+    List<String> tableList = listTables(client);
+    for (String tableName : tableList) {
+      deleteTable(client, tableName);
+    }
+  }
+
+  private static Blur.Iface connect() {
+    String blurConnectionString = BLUR_CONTROLLER_HOSTNAME + ":" + 
BLUR_CONTROLLER_PORT;
+    System.out.println("Connecting to " + blurConnectionString);
+    Blur.Iface client = BlurClient.getClient(blurConnectionString);
+    System.out.println("Successfully connected to " + blurConnectionString);
+    return client;
+  }
+
+  private static void createTable(Iface client, String tableName) {
+    try {
+      AnalyzerDefinition ad = new AnalyzerDefinition();
+
+      TableDescriptor tableDescriptor = new TableDescriptor();
+      tableDescriptor.setTableUri("hdfs://" + HDFS_NAMENODE_HOSTNAME + ":" + 
HDFS_NAMENODE_PORT + BLUR_TABLES_LOCATION + tableName);
+      tableDescriptor.setAnalyzerDefinition(ad);
+      tableDescriptor.setName(tableName);
+      tableDescriptor.setCluster(BLUR_CLUSTER_NAME);
+
+      System.out.println("About to create table " + tableName);
+      client.createTable(tableDescriptor);
+      System.out.println("Created table " + tableName);
+    } catch (BlurException e) {
+      e.printStackTrace();
+    } catch (TException e) {
+      e.printStackTrace();
+    }
+  }
+
+  private static List<String> listTables(Blur.Iface client) {
+    try {
+      System.out.println("Listing all tables");
+      List<String> tableNames = client.tableList();
+      for (String tableName : tableNames) {
+        System.out.println("tableName=" + tableName);
+      }
+      return tableNames;
+    } catch (BlurException e) {
+      e.printStackTrace();
+    } catch (TException e) {
+      e.printStackTrace();
+    }
+    return null;
+  }
+
+  private static void populateTable(Iface client, String tableName) throws 
BlurException, TException {
+    Random random = new Random();
+    for (int count = 1; count <= MAX_SAMPLE_ROWS; count++) {
+      RowMutation mutation = newRowMutation(tableName, "rowid_" + count, 
newRecordMutation("sample", "recordid_1", newColumn("sampleData", "data_" + 
random.nextInt(50000))));
+      System.out.println("About to add rowid_" + count);
+      client.mutate(mutation);
+      System.out.println("Added rowid_" + count);
+    }
+
+  }
+
+  private static void searchTable(Iface client, String tableName) throws 
BlurException, TException {
+    Random random = new Random();
+    for (int count = 1; count <= MAX_SEARCHES; count++) {
+      String rowid = "rowid_" + random.nextInt(MAX_SAMPLE_ROWS);
+      Selector selector = new Selector();
+      selector.setRowId(rowid);
+      FetchResult fetchRow = client.fetchRow(tableName, selector);
+      if (fetchRow != null) {
+        FetchRowResult rowResult = fetchRow.getRowResult();
+        if (rowResult != null) {
+          Row row = rowResult.getRow();
+          if (row != null) {
+            System.out.println("Found " + rowid);
+          }
+
+        }
+      } else {
+        System.out.println("Could not find " + rowid);
+      }
+    }
+
+  }
+
+  private static void deleteTable(Iface client, String tableName) throws 
BlurException, TException {
+    client.disableTable(tableName);
+    client.removeTable(tableName, true);
+    System.out.println("Deleted table " + tableName);
+  }
 
 }

Reply via email to