incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1202861 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog: common/ interfaces/ tablestore/
Date Wed, 16 Nov 2011 19:51:16 GMT
Author: kwright
Date: Wed Nov 16 19:51:16 2011
New Revision: 1202861

URL: http://svn.apache.org/viewvc?rev=1202861&view=rev
Log:
More fleshing out of table and index definitions

Added:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java
  (with props)
Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java?rev=1202861&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java
Wed Nov 16 19:51:16 2011
@@ -0,0 +1,85 @@
+/* $Id$ */
+
+/**
+* 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.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+/** Boolean value, serializable.
+*/
+public class BooleanValue implements WHKey
+{
+  boolean value;
+  
+  public BooleanValue(boolean value)
+  {
+    this.value = value;
+  }
+  
+  public BooleanValue()
+  {
+  }
+  
+  public BooleanValue(byte[] bytes)
+  {
+    value = readObject(new BufferPointer(bytes));
+  }
+  
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject()];
+    writeObject(new BufferPointer(rval),value);
+    return rval;
+  }
+  
+  public boolean getValue()
+  {
+    return value;
+  }
+  
+  public int hashCode()
+  {
+    return value?12351:31;
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof BooleanValue))
+      return false;
+    BooleanValue other = (BooleanValue)o;
+    return value == other.value;
+  }
+
+  public static boolean readObject(BufferPointer bp)
+  {
+    return ((((int)bp.readValue()) & 0xff) == 0)?false:true;
+  }
+  
+  public static int sizeObject()
+  {
+    return 1;
+  }
+  
+  public static void writeObject(BufferPointer bp, boolean value)
+  {
+    bp.writeValue((byte)(value?1:0));
+  }
+}
+
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BooleanValue.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java?rev=1202861&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java
Wed Nov 16 19:51:16 2011
@@ -0,0 +1,87 @@
+/* $Id$ */
+
+/**
+* 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.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+/** String array, serializable.
+*/
+public class StringArray implements WHValue
+{
+  String[] value;
+  
+  public StringArray(String[] value)
+  {
+    this.value = value;
+  }
+  
+  public StringArray()
+  {
+  }
+  
+  public StringArray(byte[] bytes)
+  {
+    value = readObject(new BufferPointer(bytes));
+  }
+  
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject(value)];
+    writeObject(new BufferPointer(rval),value);
+    return rval;
+  }
+  
+  public String[] getValue()
+  {
+    return value;
+  }
+  
+  public static String[] readObject(BufferPointer bp)
+  {
+    int size = IntegerValue.readObject(bp);
+    String[] rval = new String[size];
+    for (int i = 0 ; i < size ; i++)
+    {
+      rval[i] = StringValue.readObject(bp);
+    }
+    return rval;
+  }
+  
+  public static int sizeObject(String[] value)
+  {
+    int rval = IntegerValue.sizeObject();
+    for (int i = 0 ; i < value.length ; i++)
+    {
+      rval += StringValue.sizeObject(value[i]);
+    }
+    return rval;
+  }
+  
+  public static void writeObject(BufferPointer bp, String[] value)
+  {
+    IntegerValue.writeObject(bp,value.length);
+    for (int i = 0 ; i < value.length ; i++)
+    {
+      StringValue.writeObject(bp,value[i]);
+    }
+  }
+}
+
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringArray.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java?rev=1202861&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java
Wed Nov 16 19:51:16 2011
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/**
+* 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.warthog.interfaces;
+
+/** Interface describing a return value for a result set.
+* This interface must describe both row-based calculations AND
+* cross-row aggregations.  In order to do that, each instance receives
+* data from each row, and optionally coughs out a result.  Aggregation
+* may therefore require results to ordered in a certain way for the aggregation to 
+* work appropriately.
+*/
+public interface WHColumnDescription
+{
+  /** Get the name of the return column */
+  public String getReturnColumnName()
+    throws WHException;
+  
+  /** Feed a row to the column calculator.
+  *@return a non-null value if there is a result, or null if no result yet.
+  */
+  public WHValue appendRowValue(WHRelationship relationship, int rowNumber)
+    throws WHException;
+  
+  /** End, obtaining the current aggregate value, if any.  Also resets in preparation for
calculation
+  * of another aggregate value.
+  */
+  public WHValue done()
+    throws WHException;
+
+}
\ No newline at end of file

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHColumnDescription.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java?rev=1202861&r1=1202860&r2=1202861&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
Wed Nov 16 19:51:16 2011
@@ -28,13 +28,19 @@ public class Index implements WHIndex
   protected TableStore ts;
   protected Table table;
   protected String indexName;
+  protected String[] columnNames;
+  protected String[] comparatorClasses;
+  protected boolean unique;
   
   /** Constructor */
-  public Index(TableStore ts, Table table, String indexName)
+  public Index(TableStore ts, Table table, String indexName, String[] columnNames, String[]
comparatorClasses, boolean unique)
   {
     this.ts = ts;
     this.table = table;
     this.indexName = indexName;
+    this.columnNames = columnNames;
+    this.comparatorClasses = comparatorClasses;
+    this.unique = unique;
   }
   
   /** Get the table the index applies to.

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java?rev=1202861&r1=1202860&r2=1202861&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
Wed Nov 16 19:51:16 2011
@@ -27,12 +27,14 @@ public class Table implements WHTable
 {
   protected TableStore ts;
   protected String tableName;
+  protected String[] columns;
   
   /** Constructor */
-  public Table(TableStore ts, String tableName)
+  public Table(TableStore ts, String tableName, String[] columns)
   {
     this.ts = ts;
     this.tableName = tableName;
+    this.columns = columns;
   }
   
   /** Get the column names.
@@ -40,8 +42,7 @@ public class Table implements WHTable
   public String[] getColumnNames()
     throws WHException
   {
-    // MHL
-    return null;
+    return columns;
   }
   
   /** Compact the table.

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java?rev=1202861&r1=1202860&r2=1202861&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
Wed Nov 16 19:51:16 2011
@@ -88,9 +88,10 @@ public class TableStore implements WHTab
     Table t = tables.get(name);
     if (t != null)
       return t;
-    if (currentTransaction.get(new TableKey(name)) == null)
+    TableValue tv = (TableValue)currentTransaction.get(new TableKey(name));
+    if (tv == null)
       throw new WHException("No such table '"+name+"'");
-    t = new Table(this,name);
+    t = new Table(this,name,tv.getColumns());
     tables.put(name,t);
     return t;
   }
@@ -126,7 +127,8 @@ public class TableStore implements WHTab
     IndexValue indexValue = (IndexValue)currentTransaction.get(new IndexKey(name));
     if (indexValue == null)
       throw new WHException("No such index '"+name+"'");
-    i = new Index(this,findTable(indexValue.getTableName()),name);
+    i = new Index(this,findTable(indexValue.getTableName()),name,
+      indexValue.getColumnNames(),indexValue.getComparatorClassNames(),indexValue.getUnique());
     indexes.put(name,i);
     return i;
   }
@@ -177,6 +179,27 @@ public class TableStore implements WHTab
     
   }
   
+  protected static class TableValue extends StringArray
+  {
+    protected String[] columns;
+    
+    /** Constructor */
+    public TableValue(String[] columns)
+    {
+      super(columns);
+    }
+    
+    public TableValue(byte[] data)
+    {
+      columns = StringArray.readObject(new BufferPointer(data));
+    }
+    
+    public String[] getColumns()
+    {
+      return getValue();
+    }
+  }
+  
   protected static class IndexKey extends StringValue
   {
     /** Constructor */
@@ -191,22 +214,63 @@ public class TableStore implements WHTab
     }
   }
   
-  protected static class IndexValue extends StringValue
+  protected static class IndexValue implements WHValue
   {
+    protected String tableName;
+    protected String[] columnNames;
+    protected String[] comparatorClassNames;
+    protected boolean unique;
+    
     /** Constructor */
-    public IndexValue(String tableName)
+    public IndexValue(String tableName, String[] columnNames, String[] comparatorClassNames,
boolean unique)
     {
-      super(tableName);
+      this.tableName = tableName;
+      this.columnNames = columnNames;
+      this.comparatorClassNames = comparatorClassNames;
+      this.unique = unique;
     }
     
     public IndexValue(byte[] data)
     {
-      super(data);
+      BufferPointer bp = new BufferPointer(data);
+      tableName = StringValue.readObject(bp);
+      columnNames = StringArray.readObject(bp);
+      comparatorClassNames = StringArray.readObject(bp);
+      unique = BooleanValue.readObject(bp);
+    }
+    
+    public byte[] serializeObject()
+    {
+      byte[] rval = new byte[StringValue.sizeObject(tableName) +
+        StringArray.sizeObject(columnNames) +
+        StringArray.sizeObject(comparatorClassNames) +
+        BooleanValue.sizeObject()];
+      BufferPointer bp = new BufferPointer(rval);
+      StringValue.writeObject(bp,tableName);
+      StringArray.writeObject(bp,columnNames);
+      StringArray.writeObject(bp,comparatorClassNames);
+      BooleanValue.writeObject(bp,unique);
+      return rval;
     }
     
     public String getTableName()
     {
-      return getValue();
+      return tableName;
+    }
+    
+    public String[] getColumnNames()
+    {
+      return columnNames;
+    }
+    
+    public String[] getComparatorClassNames()
+    {
+      return comparatorClassNames;
+    }
+    
+    public boolean getUnique()
+    {
+      return unique;
     }
   }
 }



Mime
View raw message