You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by rm...@apache.org on 2009/08/09 00:03:06 UTC

svn commit: r802462 [2/2] - in /hadoop/hive/trunk: ./ metastore/if/ metastore/src/gen-javabean/org/apache/hadoop/hive/metastore/api/ metastore/src/gen-php/ metastore/src/gen-py/hive_metastore/ metastore/src/java/org/apache/hadoop/hive/metastore/ metast...

Modified: hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java?rev=802462&r1=802461&r2=802462&view=diff
==============================================================================
--- hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (original)
+++ hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java Sat Aug  8 22:03:06 2009
@@ -654,6 +654,42 @@
           }
         }
       }
+      
+      /**
+       * Return the schema of the table. This function includes partition columns
+       * in addition to the regular columns.
+       * @param db Name of the database
+       * @param tableName Name of the table
+       * @return List of columns, each column is a FieldSchema structure
+       * @throws MetaException
+       * @throws UnknownTableException
+       * @throws UnknownDBException
+       */
+      public List<FieldSchema> get_schema(String db, String tableName) 
+        throws MetaException, UnknownTableException, UnknownDBException {
+        this.incrementCounter("get_schema");
+        logStartFunction("get_schema: db=" + db + "tbl=" + tableName);
+        String [] names = tableName.split("\\.");
+        String base_table_name = names[0];
+        
+        Table tbl;
+        try {
+          tbl = this.get_table(db, base_table_name);
+        } catch (NoSuchObjectException e) {
+          throw new UnknownTableException(e.getMessage());
+        }
+        List<FieldSchema> fieldSchemas = this.get_fields(db, base_table_name);
+
+        if (tbl == null || fieldSchemas == null) {
+          throw new UnknownTableException(tableName + " doesn't exist");
+        }
+        
+        if (tbl.getPartitionKeys() != null) {
+          // Combine the column field schemas and the partition keys to create the whole schema
+          fieldSchemas.addAll(tbl.getPartitionKeys());
+        }
+        return fieldSchemas;
+      }
 
       public String getCpuProfile(int profileDurationInSec) throws TException {
         return "";

Modified: hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java?rev=802462&r1=802461&r2=802462&view=diff
==============================================================================
--- hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (original)
+++ hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java Sat Aug  8 22:03:06 2009
@@ -28,6 +28,7 @@
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
 import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
 import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
 import org.apache.hadoop.hive.metastore.api.MetaException;
@@ -37,6 +38,7 @@
 import org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore;
 import org.apache.hadoop.hive.metastore.api.Type;
 import org.apache.hadoop.hive.metastore.api.UnknownDBException;
+import org.apache.hadoop.hive.metastore.api.UnknownTableException;
 
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
@@ -439,7 +441,7 @@
   public Type getType(String name) throws MetaException, TException {
     return client.get_type(name);
   }
-
+  
   public List<String> getTables(String dbname, String tablePattern) throws MetaException {
     try {
       return client.get_tables(dbname, tablePattern);
@@ -478,5 +480,33 @@
       TException {
     client.alter_partition(dbName, tblName, newPart);
   }
+  
+  /**
+   * @param db
+   * @param tableName
+   * @throws UnknownTableException
+   * @throws UnknownDBException
+   * @throws MetaException
+   * @throws TException
+   * @see org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface#get_fields(java.lang.String, java.lang.String)
+   */
+  public List<FieldSchema> getFields(String db, String tableName) 
+      throws MetaException, TException, UnknownTableException, UnknownDBException {
+    return client.get_fields(db, tableName);
+  }
+
+  /**
+   * @param db
+   * @param tableName
+   * @throws UnknownTableException
+   * @throws UnknownDBException
+   * @throws MetaException
+   * @throws TException
+   * @see org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface#get_schema(java.lang.String, java.lang.String)
+   */
+  public List<FieldSchema> getSchema(String db, String tableName) 
+      throws MetaException, TException, UnknownTableException, UnknownDBException {
+    return client.get_schema(db, tableName);
+  }
 
 }

Modified: hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java?rev=802462&r1=802461&r2=802462&view=diff
==============================================================================
--- hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java (original)
+++ hadoop/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java Sat Aug  8 22:03:06 2009
@@ -21,6 +21,7 @@
 import java.util.List;
 
 import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
 import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
 import org.apache.hadoop.hive.metastore.api.MetaException;
@@ -190,4 +191,27 @@
   public void alter_partition(String dbName, String tblName,
       Partition newPart) throws InvalidOperationException, MetaException,
       TException;
+  
+  /**
+   * @param db
+   * @param tableName
+   * @throws UnknownTableException
+   * @throws UnknownDBException
+   * @throws MetaException
+   * @throws TException
+   * @see org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface#get_fields(java.lang.String, java.lang.String)
+   */
+  public List<FieldSchema> getFields(String db, String tableName) 
+      throws MetaException, TException, UnknownTableException, UnknownDBException;
+  /**
+   * @param db
+   * @param tableName
+   * @throws UnknownTableException
+   * @throws UnknownDBException
+   * @throws MetaException
+   * @throws TException
+   * @see org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface#get_schema(java.lang.String, java.lang.String)
+   */
+  public List<FieldSchema> getSchema(String db, String tableName) 
+      throws MetaException, TException, UnknownTableException, UnknownDBException;
 }

Modified: hadoop/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java?rev=802462&r1=802461&r2=802462&view=diff
==============================================================================
--- hadoop/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java (original)
+++ hadoop/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java Sat Aug  8 22:03:06 2009
@@ -400,6 +400,8 @@
     sd.getSerdeInfo().setName(tbl.getTableName());
     sd.getSerdeInfo().setParameters(new HashMap<String, String>());
     sd.getSerdeInfo().getParameters().put(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_FORMAT, "1");
+    sd.getSerdeInfo().setSerializationLib(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
+    tbl.setPartitionKeys(new ArrayList<FieldSchema>());
     
     client.createTable(tbl);
     
@@ -420,6 +422,23 @@
     tbl2.getParameters().put("EXTERNAL", "TRUE");
     tbl2.getSd().setLocation(tbl.getSd().getLocation() +"-2");
     
+    List<FieldSchema> fieldSchemas = client.getFields(dbName, tblName);
+    assertNotNull(fieldSchemas);
+    assertEquals(fieldSchemas.size(), tbl.getSd().getCols().size());
+    for (FieldSchema fs : tbl.getSd().getCols()) {
+      assertTrue(fieldSchemas.contains(fs));
+    }
+    
+    List<FieldSchema> fieldSchemasFull = client.getSchema(dbName, tblName);
+    assertNotNull(fieldSchemasFull);
+    assertEquals(fieldSchemasFull.size(), tbl.getSd().getCols().size()+tbl.getPartitionKeys().size());
+    for (FieldSchema fs : tbl.getSd().getCols()) {
+      assertTrue(fieldSchemasFull.contains(fs));
+    }
+    for (FieldSchema fs : tbl.getPartitionKeys()) {
+      assertTrue(fieldSchemasFull.contains(fs));
+    }
+    
     client.createTable(tbl2);
   
     Table tbl3 = client.getTable(dbName, tblName2);
@@ -432,6 +451,23 @@
     assertEquals(tbl3.getSd().getLocation(), tbl2.getSd().getLocation());
     assertEquals(tbl3.getParameters(), tbl2.getParameters());
     
+    fieldSchemas = client.getFields(dbName, tblName2);
+    assertNotNull(fieldSchemas);
+    assertEquals(fieldSchemas.size(), tbl2.getSd().getCols().size());
+    for (FieldSchema fs : tbl2.getSd().getCols()) {
+      assertTrue(fieldSchemas.contains(fs));
+    }
+    
+    fieldSchemasFull = client.getSchema(dbName, tblName2);
+    assertNotNull(fieldSchemasFull);
+    assertEquals(fieldSchemasFull.size(), tbl2.getSd().getCols().size()+tbl2.getPartitionKeys().size());
+    for (FieldSchema fs : tbl2.getSd().getCols()) {
+      assertTrue(fieldSchemasFull.contains(fs));
+    }
+    for (FieldSchema fs : tbl2.getPartitionKeys()) {
+      assertTrue(fieldSchemasFull.contains(fs));
+    }
+    
   
     assertEquals("Use this for comments etc", tbl2.getSd().getParameters().get("test_param_1"));
     assertEquals("name", tbl2.getSd().getBucketCols().get(0));
@@ -574,6 +610,7 @@
       sd.getSerdeInfo().setName(tbl.getTableName());
       sd.getSerdeInfo().setParameters(new HashMap<String, String>());
       sd.getSerdeInfo().getParameters().put(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_FORMAT, "9");
+      sd.getSerdeInfo().setSerializationLib(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
   
       tbl.setPartitionKeys(new ArrayList<FieldSchema>(2));
       tbl.getPartitionKeys().add(new FieldSchema("ds", org.apache.hadoop.hive.serde.Constants.DATE_TYPE_NAME, ""));
@@ -597,6 +634,23 @@
       assertEquals(Constants.INT_TYPE_NAME, tbl2.getPartitionKeys().get(1).getType());
       assertEquals("ds", tbl2.getPartitionKeys().get(0).getName());
       assertEquals("hr", tbl2.getPartitionKeys().get(1).getName());
+      
+      List<FieldSchema> fieldSchemas = client.getFields(dbName, tblName);
+      assertNotNull(fieldSchemas);
+      assertEquals(fieldSchemas.size(), tbl.getSd().getCols().size());
+      for (FieldSchema fs : tbl.getSd().getCols()) {
+        assertTrue(fieldSchemas.contains(fs));
+      }
+      
+      List<FieldSchema> fieldSchemasFull = client.getSchema(dbName, tblName);
+      assertNotNull(fieldSchemasFull);
+      assertEquals(fieldSchemasFull.size(), tbl.getSd().getCols().size()+tbl.getPartitionKeys().size());
+      for (FieldSchema fs : tbl.getSd().getCols()) {
+        assertTrue(fieldSchemasFull.contains(fs));
+      }
+      for (FieldSchema fs : tbl.getPartitionKeys()) {
+        assertTrue(fieldSchemasFull.contains(fs));
+      }
     } catch (Exception e) {
       System.err.println(StringUtils.stringifyException(e));
       System.err.println("testComplexTable() failed.");