Repository: incubator-trafodion
Updated Branches:
  refs/heads/master a4ec8cd68 -> 75aebedcb


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/regress/seabase/EXPECTED011
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED011 
b/core/sql/regress/seabase/EXPECTED011
index 6f88f5a..3afc2ae 100644
--- a/core/sql/regress/seabase/EXPECTED011
+++ b/core/sql/regress/seabase/EXPECTED011
@@ -7,7 +7,7 @@
 >>invoke T011T1;
 
 -- Definition of Trafodion table TRAFODION.SCH.T011T1
--- Definition current  Tue Mar  8 05:49:30 2016
+-- Definition current  Fri Jun 17 18:21:40 2016
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -143,7 +143,7 @@ A            B
 ------------------------------------------------------------------ PLAN SUMMARY
 MODULE_NAME .............. DYNAMICALLY COMPILED
 STATEMENT_NAME ........... NOT NAMED
-PLAN_ID .................. 212324176171390042
+PLAN_ID .................. 212332947701427332
 ROWS_OUT ................. 7
 EST_TOTAL_COST ........... 0.01
 STATEMENT ................ select * from t011t1 where a >= 3 and a < 5;
@@ -182,7 +182,7 @@ DESCRIPTION
   SCHEMA ................. TRAFODION.SCH
   QUERY_CACHE ............ 0
   GENERATE_EXPLAIN ....... ON
-  ObjectUIDs ............. 7433846178641183029
+  ObjectUIDs ............. 4977141353440105723
   select_list ............ TRAFODION.SCH.T011T1.A, TRAFODION.SCH.T011T1.B
 
 
@@ -1247,9 +1247,9 @@ a                     bbbbbbbbbb  c                       
                  dddd
 --- 3 row(s) selected.
 >>
 >>-- negative test
->>create table t011t5 (a char(200000), b varchar(200000), c char(200000 bytes) 
character set utf8, d varchar(200001 bytes) character set utf8);
+>>create table t011t5 (a char(200000), b varchar(200000), c char(200000 bytes) 
character set utf8, d varchar(1000001 bytes) character set utf8);
 
-*** ERROR[4247] Specified size in bytes (200001) exceeds the maximum size 
allowed (200000) for column D.
+*** ERROR[4247] Specified size in bytes (1000001) exceeds the maximum size 
allowed (1000000) for column D.
 
 --- SQL operation failed with errors.
 >>
@@ -1269,7 +1269,7 @@ METRIC_TEXT_TABLE
 >>invoke trafodion."_REPOS_".metric_query_table;
 
 -- Definition of Trafodion table TRAFODION."_REPOS_".METRIC_QUERY_TABLE
--- Definition current  Tue Mar  8 05:51:31 2016
+-- Definition current  Fri Jun 17 18:23:24 2016
 
   (
     INSTANCE_ID                      INT UNSIGNED NO DEFAULT NOT NULL NOT
@@ -1454,7 +1454,7 @@ METRIC_TEXT_TABLE
 >>-- get qid for the prepared stmt
 >>get qid for statement explstmt;
 
-MXID11000029589212324176152856001000000000206U3333300_1994_EXPLSTMT
+MXID11000008841212332947682096000000000000206U3333300_1994_EXPLSTMT
 
 --- SQL operation complete.
 >>
@@ -1506,7 +1506,7 @@ SEQ_NUM      OPERATOR
 --- SQL command prepared.
 >>get qid for statement explstmt2;
 
-MXID11000029589212324176152856001000000000206U3333300_2005_EXPLSTMT2
+MXID11000008841212332947682096000000000000206U3333300_2005_EXPLSTMT2
 
 --- SQL operation complete.
 >>set qid MXID123456 for explstmt2;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/regress/seabase/EXPECTED031
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED031 
b/core/sql/regress/seabase/EXPECTED031
index 6b0951f..81b09dd 100644
--- a/core/sql/regress/seabase/EXPECTED031
+++ b/core/sql/regress/seabase/EXPECTED031
@@ -235,4 +235,241 @@ ABC     ABC
 
 --- 2 row(s) selected.
 >>
+>>-- long varchars
+>>cqd traf_max_character_col_length '1000000';
+
+--- SQL operation complete.
+>>drop table if exists t031t1;
+
+--- SQL operation complete.
+>>create table t031t1 (z int not null primary key, a varchar(1000000), b 
char(1000000));
+
+--- SQL operation complete.
+>>insert into t031t1 values (1, repeat('a', 1000000, 1000000) , 'def');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (2, repeat('a', 1000, 1000) , 'zzz');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (3, repeat('a', 10000, 10000) , 'zzz');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (4, repeat('a', 100000, 100000) , 'zzz');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (5, repeat('a', 100, 100) , 'zzz');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (6, repeat('a', 10, 10) , 'zzz');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (7, repeat('a', 1, 1) , 'zzz');
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (8, repeat('a', 1000000, 1000000) , null);
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (9, repeat('a', 500000, 500000) , null);
+
+--- 1 row(s) inserted.
+>>insert into t031t1 values (10, repeat('a', 100, 100) , null);
+
+--- 1 row(s) inserted.
+>>
+>>select char_length(a), char_length(b) from t031t1;
+
+(EXPR)      (EXPR)    
+----------  ----------
+
+   1000000     1000000
+      1000     1000000
+     10000     1000000
+    100000     1000000
+       100     1000000
+        10     1000000
+         1     1000000
+   1000000           ?
+    500000           ?
+       100           ?
+
+--- 10 row(s) selected.
+>>select substring(a, 1, 10), cast(b as char(10)) from t031t1;
+
+(EXPR)      (EXPR)    
+----------  ----------
+
+aaaaaaaaaa  def       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+a           zzz       
+aaaaaaaaaa  ?         
+aaaaaaaaaa  ?         
+aaaaaaaaaa  ?         
+
+--- 10 row(s) selected.
+>>select [last 0] * from t031t1;
+
+--- 0 row(s) selected.
+>>
+>>drop table if exists t031t2;
+
+--- SQL operation complete.
+>>create table t031t2 (z int, a varchar(1000000), b char(1000000)) attribute 
aligned format;
+
+--- SQL operation complete.
+>>insert into t031t2 select * from t031t1;
+
+--- 10 row(s) inserted.
+>>select char_length(a), char_length(b) from t031t2;
+
+(EXPR)      (EXPR)    
+----------  ----------
+
+   1000000     1000000
+      1000     1000000
+     10000     1000000
+    100000     1000000
+       100     1000000
+        10     1000000
+         1     1000000
+   1000000           ?
+    500000           ?
+       100           ?
+
+--- 10 row(s) selected.
+>>select substring(a, 1, 10), cast(b as char(10)) from t031t2;
+
+(EXPR)      (EXPR)    
+----------  ----------
+
+aaaaaaaaaa  def       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+aaaaaaaaaa  zzz       
+a           zzz       
+aaaaaaaaaa  ?         
+aaaaaaaaaa  ?         
+aaaaaaaaaa  ?         
+
+--- 10 row(s) selected.
+>>select [last 0] * from t031t2;
+
+--- 0 row(s) selected.
+>>
+>>select count(*) from t031t1 x, t031t2 y where x.a = y.a;
+
+(EXPR)              
+--------------------
+
+                  14
+
+--- 1 row(s) selected.
+>>select x.z, y.z, substring(x.a, 1, 5), substring(y.a,1,5) 
++>  from t031t1 x, t031t2 y where x.a = y.a
++>  order by x.z, y.z;
+
+Z            Z            (EXPR)  (EXPR)
+-----------  -----------  ------  ------
+
+          1            1  aaaaa   aaaaa 
+          1            8  aaaaa   aaaaa 
+          2            2  aaaaa   aaaaa 
+          3            3  aaaaa   aaaaa 
+          4            4  aaaaa   aaaaa 
+          5            5  aaaaa   aaaaa 
+          5           10  aaaaa   aaaaa 
+          6            6  aaaaa   aaaaa 
+          7            7  a       a     
+          8            1  aaaaa   aaaaa 
+          8            8  aaaaa   aaaaa 
+          9            9  aaaaa   aaaaa 
+         10            5  aaaaa   aaaaa 
+         10           10  aaaaa   aaaaa 
+
+--- 14 row(s) selected.
+>>select x.z, y.z, substring(x.a, 1, 5), substring(y.a,1,5) 
++>  from t031t1 x, t031t2 y where x.a = y.a and x.b = y.b
++>  order by x.z, y.z;
+
+Z            Z            (EXPR)  (EXPR)
+-----------  -----------  ------  ------
+
+          1            1  aaaaa   aaaaa 
+          2            2  aaaaa   aaaaa 
+          3            3  aaaaa   aaaaa 
+          4            4  aaaaa   aaaaa 
+          5            5  aaaaa   aaaaa 
+          6            6  aaaaa   aaaaa 
+          7            7  a       a     
+
+--- 7 row(s) selected.
+>>
+>>sh echo "drop table t031hive;" > TEST031_junk;
+>>sh regrhive.ksh -f TEST031_junk;
+>>
+>>sh echo "create table t031hive(z int, a string, b string);" > TEST031_junk;
+>>sh regrhive.ksh -f TEST031_junk;
+>>
+>>cqd hive_max_string_length '1000000';
+
+--- SQL operation complete.
+>>insert into hive.hive.t031hive select * from t031t1;
+
+--- 10 row(s) inserted.
+>>select count(*) from hive.hive.t031hive;
+
+(EXPR)              
+--------------------
+
+                  10
+
+--- 1 row(s) selected.
+>>select substring(a, 1, 10), cast(b as char(10)) from hive.hive.t031hive;
+
+(EXPR)                                    (EXPR)
+----------------------------------------  
----------------------------------------
+
+aaaaaaaaaa                                def                                  
   
+aaaaaaaaaa                                zzz                                  
   
+aaaaaaaaaa                                zzz                                  
   
+aaaaaaaaaa                                zzz                                  
   
+aaaaaaaaaa                                zzz                                  
   
+aaaaaaaaaa                                zzz                                  
   
+a                                         zzz                                  
   
+aaaaaaaaaa                                ?                                    
   
+aaaaaaaaaa                                ?                                    
   
+aaaaaaaaaa                                ?                                    
   
+
+--- 10 row(s) selected.
+>>select [last 0] * from hive.hive.t031hive;
+
+--- 0 row(s) selected.
+>>
+>>drop external table if exists t031hive for hive.hive.t031hive;
+
+--- SQL operation complete.
+>>create external table t031hive (z int, a varchar(1000000), b 
varchar(1000000))
++>for hive.hive.t031hive;
+
+--- SQL operation complete.
+>>delete from t031t1;
+
+--- 10 row(s) deleted.
+>>insert into t031t1 select * from hive.hive.t031hive;
+
+--- 10 row(s) inserted.
+>>select count(*) from t031t1;
+
+(EXPR)              
+--------------------
+
+                  10
+
+--- 1 row(s) selected.
+>>
 >>log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/regress/seabase/TEST011
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST011 b/core/sql/regress/seabase/TEST011
index d33bee0..e47a87f 100644
--- a/core/sql/regress/seabase/TEST011
+++ b/core/sql/regress/seabase/TEST011
@@ -308,7 +308,7 @@ upsert into t011t4 values ('a', repeat('b', 100000), 'c', 
repeat('d', 100000)),
 select left (a, 20), left(b, 10), left(c, 10), left (d, 11) from t011t4;
 
 -- negative test
-create table t011t5 (a char(200000), b varchar(200000), c char(200000 bytes) 
character set utf8, d varchar(200001 bytes) character set utf8);
+create table t011t5 (a char(200000), b varchar(200000), c char(200000 bytes) 
character set utf8, d varchar(1000001 bytes) character set utf8);
 
 -- tests for repository explain
 -- check for repository tables

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/regress/seabase/TEST031
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST031 b/core/sql/regress/seabase/TEST031
index c52a3fe..80d124a 100644
--- a/core/sql/regress/seabase/TEST031
+++ b/core/sql/regress/seabase/TEST031
@@ -113,4 +113,57 @@ insert into t031t1 default values;
 upsert into t031t1 default values;
 select * from t031t1;
 
+-- long varchars
+cqd traf_max_character_col_length '1000000';
+drop table if exists t031t1;
+create table t031t1 (z int not null primary key, a varchar(1000000), b 
char(1000000));
+insert into t031t1 values (1, repeat('a', 1000000, 1000000) , 'def');
+insert into t031t1 values (2, repeat('a', 1000, 1000) , 'zzz');
+insert into t031t1 values (3, repeat('a', 10000, 10000) , 'zzz');
+insert into t031t1 values (4, repeat('a', 100000, 100000) , 'zzz');
+insert into t031t1 values (5, repeat('a', 100, 100) , 'zzz');
+insert into t031t1 values (6, repeat('a', 10, 10) , 'zzz');
+insert into t031t1 values (7, repeat('a', 1, 1) , 'zzz');
+insert into t031t1 values (8, repeat('a', 1000000, 1000000) , null);
+insert into t031t1 values (9, repeat('a', 500000, 500000) , null);
+insert into t031t1 values (10, repeat('a', 100, 100) , null);
+
+select char_length(a), char_length(b) from t031t1;
+select substring(a, 1, 10), cast(b as char(10)) from t031t1;
+select [last 0] * from t031t1;
+
+drop table if exists t031t2;
+create table t031t2 (z int, a varchar(1000000), b char(1000000)) attribute 
aligned format;
+insert into t031t2 select * from t031t1;
+select char_length(a), char_length(b) from t031t2;
+select substring(a, 1, 10), cast(b as char(10)) from t031t2;
+select [last 0] * from t031t2;
+
+select count(*) from t031t1 x, t031t2 y where x.a = y.a;
+select x.z, y.z, substring(x.a, 1, 5), substring(y.a,1,5) 
+  from t031t1 x, t031t2 y where x.a = y.a
+  order by x.z, y.z;
+select x.z, y.z, substring(x.a, 1, 5), substring(y.a,1,5) 
+  from t031t1 x, t031t2 y where x.a = y.a and x.b = y.b
+  order by x.z, y.z;
+
+sh echo "drop table t031hive;" > TEST031_junk;
+sh regrhive.ksh -f TEST031_junk;
+
+sh echo "create table t031hive(z int, a string, b string);" > TEST031_junk;
+sh regrhive.ksh -f TEST031_junk;
+
+cqd hive_max_string_length '1000000';
+insert into hive.hive.t031hive select * from t031t1;
+select count(*) from hive.hive.t031hive;
+select substring(a, 1, 10), cast(b as char(10)) from hive.hive.t031hive;
+select [last 0] * from hive.hive.t031hive;
+
+drop external table if exists t031hive for hive.hive.t031hive;
+create external table t031hive (z int, a varchar(1000000), b varchar(1000000))
+for hive.hive.t031hive;
+delete from t031t1;
+insert into t031t1 select * from hive.hive.t031hive;
+select count(*) from t031t1;
+
 log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcat/desc.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/desc.h b/core/sql/sqlcat/desc.h
index 1391843..f6b8beb 100644
--- a/core/sql/sqlcat/desc.h
+++ b/core/sql/sqlcat/desc.h
@@ -125,7 +125,8 @@ struct table_desc_struct {
   char * snapshotName;
   char * default_col_fam;
   char * all_col_fams;
-  Int64 tableFlags;
+  Int64 objectFlags;
+  Int64 tablesFlags;
   desc_struct *columns_desc;
   desc_struct *indexes_desc;
   desc_struct *constrnts_desc;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp
index 2ba9652..c663fb4 100644
--- a/core/sql/sqlcomp/CmpDescribe.cpp
+++ b/core/sql/sqlcomp/CmpDescribe.cpp
@@ -184,6 +184,7 @@ static short CmpDescribeTransaction(
 
 short CmpDescribeHiveTable ( 
                              const CorrName  &dtName,
+                             short type, // 1, invoke. 2, showddl. 3, 
createLike
                              char* &outbuf,
                              ULng32 &outbuflen,
                              CollHeap *heap);
@@ -206,7 +207,8 @@ short CmpDescribeSeabaseTable (
                              char * colName = NULL,
                              short ada = 0, // 0,add. 1,drop. 2,alter
                              const NAColumn * nacol = NULL,
-                             const NAType * natype = NULL);
+                             const NAType * natype = NULL,
+                             Space *inSpace = NULL);
 
 short CmpDescribeSequence ( 
                              const CorrName  &dtName,
@@ -837,12 +839,15 @@ short CmpDescribe(const char *query, const RelExpr 
*queryExpr,
   // check if this is a hive table. If so, describe using hive info from 
NATable.
   // For now, schemaName of HIVE indicates a hive table.
   // Need to fix that at a later time when multiple hive schemas are supported.
-  if ((d->getFormat() == Describe::INVOKE_) &&
+  if (((d->getFormat() == Describe::INVOKE_) ||
+       (d->getFormat() == Describe::LONG_)) &&
       (d->getDescribedTableName().isHive()) &&
       (!d->getDescribedTableName().isSpecialTable()))
     {
       rc = 
-        CmpDescribeHiveTable(d->getDescribedTableName(), outbuf, outbuflen, 
heap);
+        CmpDescribeHiveTable(d->getDescribedTableName(), 
+                             (d->getFormat() == Describe::INVOKE_ ? 1 : 2),
+                             outbuf, outbuflen, heap);
       goto finally;  // we are done
     }
 
@@ -2196,6 +2201,7 @@ static NAString CmpDescribe_ptiToInfCS(const NAString 
&inputInLatin1)
 
 short CmpDescribeHiveTable ( 
                              const CorrName  &dtName,
+                             short type, // 1, invoke. 2, showddl. 3, 
createLike
                              char* &outbuf,
                              ULng32 &outbuflen,
                              CollHeap *heap)
@@ -2209,6 +2215,23 @@ short CmpDescribeHiveTable (
     return -1;
   else
     {
+      // if showddl and this hive table has an associated external table,
+      // show the ddl of underlying hive table first.
+      if ((type == 2) &&
+          (naTable->isHiveTable()) &&
+          (naTable->hasHiveExtTable()))
+        {
+          // remove current cache key and turn off ext table attr cqd.
+          // This will return the underlying hive natable.
+          bindWA.getSchemaDB()->getNATableDB()->remove(naTable->getKey());
+
+          // retrieve underlying hive table definition
+          bindWA.setReturnHiveTableDefn(TRUE);
+          naTable = bindWA.getNATable((CorrName&)dtName); 
+          if (naTable == NULL || bindWA.errStatus())
+            return -1;
+        }
+
       bindWA.createTableDesc(naTable, (CorrName&)dtName);
       if (bindWA.errStatus())
         return -1;
@@ -2217,6 +2240,9 @@ short CmpDescribeHiveTable (
   if (NOT naTable->isHiveTable())
     return -1;
 
+  if (NOT ((type == 1) || (type == 2)))
+    return -1;
+
   char * buf = new (heap) char[15000];
   CMPASSERT(buf);
 
@@ -2228,10 +2254,21 @@ short CmpDescribeHiveTable (
   // emit an initial newline
   outputShortLine(space, " ");
 
-  sprintf(buf,  "-- Definition of hive table %s\n"
-          "-- Definition current  %s",
-          tableName.data(), ctime(&tp));
-  outputShortLine(space, buf);
+  if (type == 1)
+    {
+      sprintf(buf,  "-- Definition of hive table %s\n"
+              "-- Definition current  %s",
+              tableName.data(), ctime(&tp));
+      outputShortLine(space, buf);
+    }
+  else if (type == 2)
+    {
+      outputShortLine(space,"/* Hive DDL */");
+
+      sprintf(buf,  "CREATE TABLE %s",
+              tableName.data());
+      outputShortLine(space, buf);
+    }
   
   outputShortLine(space, "  ( ");
 
@@ -2240,14 +2277,16 @@ short CmpDescribeHiveTable (
       NAColumn * nac = naTable->getNAColumnArray()[i];
 
       const NAString &colName = nac->getColName();
+      const NAType * nat = nac->getType();
 
       sprintf(buf, "%-*s ", CM_SIM_NAME_LEN,
               ANSI_ID(colName.data()));
       
-      const NAType * nat = nac->getType();
-
       NAString nas;
-      ((NAType*)nat)->getMyTypeAsText(&nas, FALSE);
+      if (type == 1)
+        ((NAType*)nat)->getMyTypeAsText(&nas, FALSE);
+      else
+        ((NAType*)nat)->getMyTypeAsHiveText(&nas);
       
       sprintf(&buf[strlen(buf)], "%s", nas.data());
 
@@ -2262,15 +2301,62 @@ short CmpDescribeHiveTable (
     naTable->getClusteringIndex()->getHHDFSTableStats();
   if (hTabStats->isOrcFile())
     {
-      outputShortLine(space, "   /* stored as orc */");
+      if (type == 1)
+        outputShortLine(space, "  /* stored as orc */");
+      else
+        outputShortLine(space, "  stored as orc ");
     }
   else if (hTabStats->isTextFile())
     {
-      outputShortLine(space, "   /* stored as text */");
+      if (type == 1)
+        outputShortLine(space, "  /* stored as textfile */");
+      else
+        outputShortLine(space, "  stored as textfile ");
     }
   else if (hTabStats->isSequenceFile())
     {
-      outputShortLine(space, "   /* stored as sequence */");
+      if (type == 1)
+        outputShortLine(space, "  /* stored as sequence */");
+      else
+        outputShortLine(space, "  stored as sequence ");
+    }
+
+  if (type == 2)
+    outputShortLine(space, ";");
+
+  // if this hive table has an associated external table, show ddl
+  // for that external table.
+  if ((type == 2) &&
+      (bindWA.returnHiveTableDefn()))
+    {
+      // remove table key from natable cache. Next call to get natable
+      // will get the external table defn, if one exists
+      bindWA.getSchemaDB()->getNATableDB()->remove(naTable->getKey());
+
+      bindWA.setReturnHiveTableDefn(FALSE);
+
+      char * dummyBuf;
+      ULng32 dummyLen;
+      
+      NAString extName = ComConvertNativeNameToTrafName(
+           dtName.getQualifiedNameObj().getCatalogName(),
+           dtName.getQualifiedNameObj().getSchemaName(),
+           dtName.getQualifiedNameObj().getObjectName());
+      
+      QualifiedName qn(extName, 3);
+      CorrName cn(qn);
+
+      outputShortLine(space," ");
+      outputShortLine(space,"/* Trafodion DDL */");
+ 
+      short rc = CmpDescribeSeabaseTable(cn, 
+                                         type,
+                                         dummyBuf, dummyLen, heap, 
+                                         NULL, 
+                                         TRUE, FALSE, FALSE, TRUE,
+                                         NULL, 0, NULL, NULL, &space);
+
+      outputShortLine(space, ";");
     }
 
   outbuflen = space.getAllocatedSpaceSize();
@@ -2615,10 +2701,14 @@ short CmpDescribeSeabaseTable (
                                char * colName,
                                short ada,
                                const NAColumn * nacol,
-                               const NAType * natype)
+                               const NAType * natype,
+                               Space *inSpace)
 {
   const NAString& tableName =
     dtName.getQualifiedNameObj().getQualifiedNameAsAnsiString(TRUE);
+
+  const NAString& objectName =
+    dtName.getQualifiedNameObj().getObjectName();
  
   if (CmpCommon::context()->isUninitializedSeabase())
      {
@@ -2651,19 +2741,43 @@ short CmpDescribeSeabaseTable (
   NABoolean isVolatile = naTable->isVolatileTable();
   NABoolean isExternalTable = naTable->isExternalTable();
 
+  NABoolean isExternalHbaseTable = FALSE;
+  NABoolean isExternalHiveTable = FALSE;
+  NAString extName;
+  if (isExternalTable)
+    {
+      extName = ComConvertTrafNameToNativeName(
+           dtName.getQualifiedNameObj().getCatalogName(),
+           dtName.getQualifiedNameObj().getUnqualifiedSchemaNameAsAnsiString(),
+           
dtName.getQualifiedNameObj().getUnqualifiedObjectNameAsAnsiString());
+
+      QualifiedName qn(extName, 3);
+      if (qn.getCatalogName() == HBASE_SYSTEM_CATALOG)
+        isExternalHbaseTable = TRUE;
+      else if (qn.getCatalogName() == HIVE_SYSTEM_CATALOG)
+        isExternalHiveTable = TRUE;
+    }
+
   char * buf = new (heap) char[15000];
   CMPASSERT(buf);
 
   time_t tp;
   time(&tp);
   
-  Space space;
+  Space lSpace;
+
+  Space * space;
+  if (inSpace)
+    space = inSpace;
+  else
+    space = &lSpace;
 
   char * sqlmxRegr = getenv("SQLMX_REGRESS");
 
   NABoolean displayPrivilegeGrants = TRUE;
   if (((CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_SYSTEM) 
&& sqlmxRegr) ||
-       (CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_OFF))
+      (CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_OFF) ||
+      (isExternalTable))
     displayPrivilegeGrants = FALSE;
  
   // display syscols for invoke if not running regrs
@@ -2673,7 +2787,7 @@ short CmpDescribeSeabaseTable (
   NABoolean isView = (naTable->getViewText() ? TRUE : FALSE);
 
   // emit an initial newline
-  outputShortLine(space, " ");
+  outputShortLine(*space, " ");
 
   // Used for context switches
   CmpSeabaseDDL cmpSBD((NAHeap*)heap);
@@ -2737,7 +2851,7 @@ short CmpDescribeSeabaseTable (
       viewtext = viewtext.strip(NAString::trailing, ';');
       viewtext += " ;";
 
-      outputLongLine(space, viewtext, 0);
+      outputLongLine(*space, viewtext, 0);
 
       // Display grant statements
       if (CmpCommon::context()->isAuthorizationEnabled() && 
displayPrivilegeGrants)
@@ -2759,16 +2873,16 @@ short CmpDescribeSeabaseTable (
  
         if (privInterface.describePrivileges(objectInfo, privilegeText))
         {
-          outputShortLine(space, " ");
-          outputLine(space, privilegeText.c_str(), 0);
+          outputShortLine(*space, " ");
+          outputLine(*space, privilegeText.c_str(), 0);
         }
 
         cmpSBD.switchBackCompiler();
       }
 
-      outbuflen = space.getAllocatedSpaceSize();
+      outbuflen = space->getAllocatedSpaceSize();
       outbuf = new (heap) char[outbuflen];
-      space.makeContiguous(outbuf, outbuflen);
+      space->makeContiguous(outbuf, outbuflen);
       
       NADELETEBASIC(buf, heap);
       
@@ -2785,26 +2899,36 @@ short CmpDescribeSeabaseTable (
         sprintf(buf,  "-- Definition of Trafodion%stable %s\n"
                 "-- Definition current  %s",
                 (isVolatile ? " volatile " : isExternalTable ? " external " : 
" "), 
-                tableName.data(), ctime(&tp));
-      outputShortLine(space, buf);
+                tableName.data(), 
+                ctime(&tp));
+      outputShortLine(*space, buf);
     }
   else if (type == 2)
     {
       sprintf(buf,  "CREATE%sTABLE %s",
               (isVolatile ? " VOLATILE " : isExternalTable ? " EXTERNAL " : " 
"), 
-              tableName.data());
-      outputShortLine(space, buf);
+              (isExternalTable ? objectName.data() : tableName.data()));
+      outputShortLine(*space, buf);
     }
 
   Lng32 identityColPos = -1;
-  outputShortLine(space, "  ( ");
-  cmpDisplayColumns(naTable->getNAColumnArray(), 
-                    type, space, buf, 
-                   displaySystemCols, 
-                   FALSE,
-                    identityColPos,
-                    isExternalTable, naTable->isSQLMXAlignedTable(),
-                    colName, ada, nacol, natype);
+  NABoolean closeParan = FALSE;
+  if ((NOT isExternalTable) ||
+      ((isExternalTable) && 
+       ((isExternalHbaseTable && (type == 1)) ||
+        (isExternalHiveTable && (type != 2)) ||
+        (isExternalHiveTable && (type == 2) && (naTable->hiveExtColAttrs())))))
+    {
+      outputShortLine(*space, "  ( ");
+      cmpDisplayColumns(naTable->getNAColumnArray(), 
+                        type, *space, buf, 
+                        displaySystemCols, 
+                        FALSE,
+                        identityColPos,
+                        isExternalTable, naTable->isSQLMXAlignedTable(),
+                        colName, ada, nacol, natype);
+      closeParan = TRUE;
+    }
 
   Int32 nonSystemKeyCols = 0;
   NABoolean isStoreBy = FALSE;
@@ -2850,7 +2974,7 @@ short CmpDescribeSeabaseTable (
     isStoreBy = FALSE;
 
   if (type == 1)
-    outputShortLine(space, "  )");
+    outputShortLine(*space, "  )");
 
   Lng32 numBTpkeys = 0;
 
@@ -2859,12 +2983,11 @@ short CmpDescribeSeabaseTable (
 
   NABoolean isAligned = naTable->isSQLMXAlignedTable();
 
-  NABoolean closeParan = FALSE;
   if ((type == 3) && (pkeyStr))
     {
-      outputShortLine(space, " , PRIMARY KEY ");
+      outputShortLine(*space, " , PRIMARY KEY ");
       
-      outputLine(space, pkeyStr, 2);
+      outputLine(*space, pkeyStr, 2);
     }
   else
     {
@@ -2882,14 +3005,14 @@ short CmpDescribeSeabaseTable (
           cmpDisplayPrimaryKey(naf->getIndexKeyColumns(), 
                                naf->getIndexKeyColumns().entries(),
                                displaySystemCols,
-                               space, buf, TRUE, TRUE, TRUE);
+                               *space, buf, TRUE, TRUE, TRUE);
         } // if
     }
 
   if (type != 1)
     {
-      if (NOT closeParan)
-        outputShortLine(space, "  )");
+      if (closeParan)
+        outputShortLine(*space, "  )");
       if (isStoreBy)
         {
           sprintf(buf,  "  STORE BY ");
@@ -2897,7 +3020,7 @@ short CmpDescribeSeabaseTable (
           cmpDisplayPrimaryKey(naf->getIndexKeyColumns(), 
                                naf->getIndexKeyColumns().entries(),
                                displaySystemCols,
-                               space, buf, TRUE, TRUE, TRUE);
+                               *space, buf, TRUE, TRUE, TRUE);
         }
       
       if ((isSalted) && !withoutSalt)
@@ -2910,7 +3033,7 @@ short CmpDescribeSeabaseTable (
           else
             sprintf(buf,  "  SALT USING %d PARTITIONS", numPartitions);
             
-          outputShortLine(space, buf);
+          outputShortLine(*space, buf);
 
           ValueIdList saltCols;
 
@@ -2952,7 +3075,7 @@ short CmpDescribeSeabaseTable (
                   sc += ANSI_ID(bc->getColName().data());
                 }
               sc += ")";
-              outputShortLine(space, sc.data());
+              outputShortLine(*space, sc.data());
             }
         }
       else if ((NOT isSalted) && (withPartns))
@@ -2963,7 +3086,7 @@ short CmpDescribeSeabaseTable (
             {
               sprintf(buf,  "  /* ACTUAL PARTITIONS %d */", currPartitions);
               
-              outputShortLine(space, buf);
+              outputShortLine(*space, buf);
             }
         }
 
@@ -2979,7 +3102,7 @@ short CmpDescribeSeabaseTable (
               if (!divisioningExprAscOrders[d])
                 divByClause += " DESC";
             }
-          outputShortLine(space, divByClause.data());
+          outputShortLine(*space, divByClause.data());
           divByClause = "     NAMED AS (";
 
           NAFileSet * naf = naTable->getClusteringIndex();
@@ -3001,7 +3124,7 @@ short CmpDescribeSeabaseTable (
             }
 
           divByClause += "))";
-          outputShortLine(space, divByClause.data());
+          outputShortLine(*space, divByClause.data());
         }
 
       NABoolean attributesSet = FALSE;
@@ -3024,14 +3147,14 @@ short CmpDescribeSeabaseTable (
               strcat(attrs, naTable->defaultColFam());
               strcat(attrs, "'");
             }
-          outputShortLine(space, attrs);
+          outputShortLine(*space, attrs);
         }
 
       if (!isView && (naTable->hbaseCreateOptions()) &&
           (naTable->hbaseCreateOptions()->entries() > 0))
         {
-          outputShortLine(space, "  HBASE_OPTIONS ");
-          outputShortLine(space, "  ( ");
+          outputShortLine(*space, "  HBASE_OPTIONS ");
+          outputShortLine(*space, "  ( ");
           
           for (Lng32 i = 0; i < naTable->hbaseCreateOptions()->entries(); i++)
             {
@@ -3042,14 +3165,21 @@ short CmpDescribeSeabaseTable (
                 comma = TRUE;
               sprintf(buf, "    %s = '%s'%s", hco->key().data(), 
hco->val().data(),
                       (comma ? "," : " "));
-              outputShortLine(space, buf);
+              outputShortLine(*space, buf);
             }
 
-          outputShortLine(space, "  ) ");
+          outputShortLine(*space, "  ) ");
+        }
+
+      if ((isExternalTable) &&
+          (type == 2))
+        {
+          sprintf(buf, "  FOR %s", extName.data());
+          outputShortLine(*space, buf);
         }
 
       if (NOT noTrailingSemi)
-        outputShortLine(space, ";");
+        outputShortLine(*space, ";");
     }
 
   // showddl internal sequences created for identity cols
@@ -3066,11 +3196,11 @@ short CmpDescribeSeabaseTable (
       CorrName csn(seqName, STMTHEAP,
                    dtName.getQualifiedNameObj().getSchemaName(), 
                    dtName.getQualifiedNameObj().getCatalogName());
-      outputLine(space, "\n-- The following sequence is a system created 
sequence --", 0);
+      outputLine(*space, "\n-- The following sequence is a system created 
sequence --", 0);
       
       char * dummyBuf;
       ULng32 dummyLen;
-      CmpDescribeSequence(csn, dummyBuf, dummyLen, STMTHEAP, &space);
+      CmpDescribeSequence(csn, dummyBuf, dummyLen, STMTHEAP, space);
     }
 
   if (((type == 1) && (NOT sqlmxRegr)) || (type == 2))
@@ -3103,7 +3233,7 @@ short CmpDescribeSeabaseTable (
                      vu,
                      indexName.data(),
                      ctime(&tp));
-             outputShortLine(space, buf);
+             outputShortLine(*space, buf);
            }
          else
            {
@@ -3116,7 +3246,7 @@ short CmpDescribeSeabaseTable (
 
              if (NOT naf->isCreatedExplicitly())
                {
-                 outputLine(space, "\n-- The following index is a system 
created index --", 0);
+                 outputLine(*space, "\n-- The following index is a system 
created index --", 0);
                }
 
              sprintf(buf,  "%sCREATE%sINDEX %s ON %s",
@@ -3124,24 +3254,24 @@ short CmpDescribeSeabaseTable (
                      vu,
                      indexName.data(),
                      tableName.data());
-             outputLine(space, buf, 0);
+             outputLine(*space, buf, 0);
            }
          
          if (type == 1)
            {
               Lng32 dummy;
-             outputShortLine(space, "  ( ");
+             outputShortLine(*space, "  ( ");
              cmpDisplayColumns(naf->getAllColumns(), 
-                                type, space, buf,
+                                type, *space, buf,
                                displaySystemCols,
                                (type == 2),
                                 dummy,
                                 isExternalTable,
                                 isAligned);
-             outputShortLine(space, "  )");
+             outputShortLine(*space, "  )");
              
              sprintf(buf,  "  PRIMARY KEY ");
-             outputShortLine(space, buf);
+             outputShortLine(*space, buf);
            }
          
          Lng32 numIndexCols = ((type == 1) ? 
@@ -3154,7 +3284,7 @@ short CmpDescribeSeabaseTable (
 
          cmpDisplayPrimaryKey(naf->getIndexKeyColumns(), numIndexCols, 
                               displaySystemCols,
-                              space, buf, FALSE, TRUE, TRUE);
+                              *space, buf, FALSE, TRUE, TRUE);
 
           if ((NOT sqlmxRegr) && isAligned)
           {
@@ -3162,14 +3292,14 @@ short CmpDescribeSeabaseTable (
              strcpy(attrs, " ATTRIBUTES ");
              if (isAligned)
                 strcat(attrs, "ALIGNED FORMAT ");
-             outputShortLine(space, attrs);
+             outputShortLine(*space, attrs);
           }
 
           if ((naf->hbaseCreateOptions()) && (type == 2) &&
                (naf->hbaseCreateOptions()->entries() > 0))
            {
-             outputShortLine(space, "  HBASE_OPTIONS ");
-             outputShortLine(space, "  ( ");
+             outputShortLine(*space, "  HBASE_OPTIONS ");
+             outputShortLine(*space, "  ( ");
           
              for (Lng32 i = 0; i < naf->hbaseCreateOptions()->entries(); i++)
              {
@@ -3179,17 +3309,17 @@ short CmpDescribeSeabaseTable (
                   ',' : ' ') ;
                sprintf(buf, "    %s = '%s'%c", hco->key().data(), 
                        hco->val().data(),separator);
-               outputShortLine(space, buf);
+               outputShortLine(*space, buf);
              }
 
-             outputShortLine(space, "  ) ");
+             outputShortLine(*space, "  ) ");
            }
 
           if ((naf->numSaltPartns() > 0) && (type == 2))
-            outputShortLine(space, " SALT LIKE TABLE ");
+            outputShortLine(*space, " SALT LIKE TABLE ");
          
          if (type == 2)
-           outputShortLine(space, ";");
+           outputShortLine(*space, ";");
          
        } // for
 
@@ -3217,7 +3347,7 @@ short CmpDescribeSeabaseTable (
               sprintf(buf,  "\nALTER TABLE %s ADD CONSTRAINT %s UNIQUE ",
                       ansiTableName.data(),
                       ansiConstrName.data());
-              outputLine(space, buf, 0);
+              outputLine(*space, buf, 0);
 
               NAColumnArray nacarr;
 
@@ -3229,9 +3359,9 @@ short CmpDescribeSeabaseTable (
               cmpDisplayPrimaryKey(nacarr, 
                                    uniqConstr->keyColumns().entries(),
                                    FALSE,
-                                   space, &buf[strlen(buf)], FALSE, FALSE, 
TRUE);
+                                   *space, &buf[strlen(buf)], FALSE, FALSE, 
TRUE);
 
-              outputShortLine(space, ";");
+              outputShortLine(*space, ";");
             } // for
 
           const AbstractRIConstraintList &refList = 
naTable->getRefConstraints();
@@ -3262,7 +3392,7 @@ short CmpDescribeSeabaseTable (
               sprintf(buf,  "\nALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY ",
                       ansiTableName.data(),
                       ansiConstrName.data());
-              outputLine(space, buf, 0);
+              outputLine(*space, buf, 0);
 
               NAColumnArray nacarr;
 
@@ -3274,13 +3404,13 @@ short CmpDescribeSeabaseTable (
               cmpDisplayPrimaryKey(nacarr, 
                                    refConstr->keyColumns().entries(),
                                    FALSE,
-                                   space, &buf[strlen(buf)], FALSE, FALSE, 
TRUE);
+                                   *space, &buf[strlen(buf)], FALSE, FALSE, 
TRUE);
 
               const NAString& ansiOtherTableName = 
                 
uniqueConstraintReferencedByMe.getTableName().getQualifiedNameAsAnsiString(TRUE);
             
               sprintf(buf,  " REFERENCES %s ",
                       ansiOtherTableName.data());
-              outputLine(space, buf, 0);
+              outputLine(*space, buf, 0);
 
               AbstractRIConstraint * otherConstr = 
                 refConstr->findConstraint(&bindWA, 
refConstr->getUniqueConstraintReferencedByMe());
@@ -3294,14 +3424,14 @@ short CmpDescribeSeabaseTable (
               cmpDisplayPrimaryKey(nacarr2, 
                                    otherConstr->keyColumns().entries(),
                                    FALSE,
-                                   space, &buf[strlen(buf)], FALSE, FALSE, 
TRUE);
+                                   *space, &buf[strlen(buf)], FALSE, FALSE, 
TRUE);
 
               if (NOT refConstr->getIsEnforced())
                 {
-                  outputShortLine(space, " NOT ENFORCED ");
+                  outputShortLine(*space, " NOT ENFORCED ");
                 }
 
-              outputShortLine(space, ";");
+              outputShortLine(*space, ";");
             } // for
 
       const CheckConstraintList &checkList = naTable->getCheckConstraints();
@@ -3317,7 +3447,7 @@ short CmpDescribeSeabaseTable (
                   tableName.data(),
                   ansiConstrName.data(), 
                   checkConstr->getConstraintText().data());
-          outputLine(space, buf, 0);
+          outputLine(*space, buf, 0);
           
         } // for
 
@@ -3347,17 +3477,17 @@ short CmpDescribeSeabaseTable (
  
       if (privInterface.describePrivileges(objectInfo, privilegeText))
       {
-        outputShortLine(space, " ");
-        outputLine(space, privilegeText.c_str(), 0);
+        outputShortLine(*space, " ");
+        outputLine(*space, privilegeText.c_str(), 0);
       }
 
       cmpSBD.switchBackCompiler();
     }
   }
 
-  outbuflen = space.getAllocatedSpaceSize();
+  outbuflen = space->getAllocatedSpaceSize();
   outbuf = new (heap) char[outbuflen];
-  space.makeContiguous(outbuf, outbuflen);
+  space->makeContiguous(outbuf, outbuflen);
   
   NADELETEBASIC(buf, heap);
 
@@ -3436,7 +3566,7 @@ short CmpDescribeSequence(
   char * sqlmxRegr = getenv("SQLMX_REGRESS");
   NABoolean displayPrivilegeGrants = TRUE;
   if (((CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_SYSTEM) 
&& sqlmxRegr) ||
-       (CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_OFF))
+      (CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_OFF))
     displayPrivilegeGrants = FALSE;
 
   // If authorization enabled, display grant statements

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 730dff1..2fe6ed8 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -350,72 +350,91 @@ class CmpSeabaseDDL
        const ComTdbVirtTableKeyInfo *keyInfoArray,
        const ComTdbVirtTableColumnInfo *colInfoArray,
        Lng32 numKeys);
-
-   Int64 getObjectUID(
-                     ExeCliInterface *cliInterface,
-                     const char * catName,
-                     const char * schName,
-                     const char * objName,
-                     const char * inObjType,
-                     const char * inObjTypeStr = NULL,
-                     char * outObjType = NULL,
-                     NABoolean lookInObjectsIdx = FALSE,
-                     NABoolean reportErrorNow = TRUE);
-
-   Int64 getObjectInfo(
-                     ExeCliInterface * cliInterface,
-                     const char * catName,
-                     const char * schName,
-                     const char * objName,
-                     const ComObjectType objectType,
-                     Int32 & objectOwner,
-                     Int32 & schemaOwner,
-                     Int64 & objectFlags,
-                     bool reportErrorNow = true,
-                     NABoolean checkForValidDef = FALSE);
-  
-   short getObjectName(
-                       ExeCliInterface *cliInterface,
-                       Int64 objUID,
-                       NAString &catName,
-                       NAString &schName,
-                       NAString &objName,
-                       char * outObjType = NULL,
-                       NABoolean lookInObjects = FALSE,
-                       NABoolean lookInObjectsIdx = FALSE);
-  
-   short getObjectValidDef(ExeCliInterface *cliInterface,
+  
+  Int64 getObjectUID(
+       ExeCliInterface *cliInterface,
+       const char * catName,
+       const char * schName,
+       const char * objName,
+       const char * inObjType,
+       const char * inObjTypeStr = NULL,
+       char * outObjType = NULL,
+       NABoolean lookInObjectsIdx = FALSE,
+       NABoolean reportErrorNow = TRUE);
+  
+  Int64 getObjectInfo(
+       ExeCliInterface * cliInterface,
+       const char * catName,
+       const char * schName,
+       const char * objName,
+       const ComObjectType objectType,
+       Int32 & objectOwner,
+       Int32 & schemaOwner,
+       Int64 & objectFlags,
+       bool reportErrorNow = true,
+       NABoolean checkForValidDef = FALSE);
+  
+  short getObjectName(
+       ExeCliInterface *cliInterface,
+       Int64 objUID,
+       NAString &catName,
+       NAString &schName,
+       NAString &objName,
+       char * outObjType = NULL,
+       NABoolean lookInObjects = FALSE,
+       NABoolean lookInObjectsIdx = FALSE);
+  
+  short getObjectValidDef(ExeCliInterface *cliInterface,
                           const char * catName,
-                           const char * schName,
-                           const char * objName,
-                           const ComObjectType objectType,
-                           NABoolean &validDef);
+                          const char * schName,
+                          const char * objName,
+                          const ComObjectType objectType,
+                          NABoolean &validDef);
   
-   short genTrafColFam(int index, NAString &trafColFam);
+  short genTrafColFam(int index, NAString &trafColFam);
   
-   static short extractTrafColFam(const NAString &trafColFam, int &index);
+  static short extractTrafColFam(const NAString &trafColFam, int &index);
+  
+  short processColFamily(NAString &inColFamily,
+                         NAString &outColFamily,
+                         std::vector<NAString> *userColFamVec,
+                         std::vector<NAString> *trafColFamVec);
+  
+  short switchCompiler(Int32 cntxtType = CmpContextInfo::CMPCONTEXT_TYPE_META);
+  
+  short switchBackCompiler();
   
-   short processColFamily(NAString &inColFamily,
-                          NAString &outColFamily,
-                          std::vector<NAString> *userColFamVec,
-                          std::vector<NAString> *trafColFamVec);
-     
-   short switchCompiler(Int32 cntxtType = 
CmpContextInfo::CMPCONTEXT_TYPE_META);
-
-   short switchBackCompiler();
-
   ExpHbaseInterface* allocEHI(NADefaults * defs = NULL);
   
   short ddlInvalidateNATables();
-
+  
   void deallocEHI(ExpHbaseInterface* &ehi);
   void dropLOBHdfsFiles();
+  
+  static void setMDflags(Int64 &flags, //INOUT
+                         Int64 bitFlags)
+  {
+    flags |= bitFlags;
+  }
+  
+  static void resetMDflags(Int64 &flags, //INOUT
+                           Int64 bitFlags)
+  {
+    flags &= ~bitFlags;
+  }
+  
+  static NABoolean isMDflagsSet(Int64 flags, Int64 bitFlags)
+  {
+    return (flags &= bitFlags) != 0; 
+  }
+  
   enum {
     // set if we need to get the hbase snapshot info of the table
     GET_SNAPSHOTS = 0x0002
   };
- protected:
 
+protected:
+  
   void setFlags(ULng32 &flags, ULng32 flagbits)
   {
     flags |= flagbits;
@@ -786,6 +805,7 @@ class CmpSeabaseDDL
   
   short buildKeyInfoArray(
                          ElemDDLColDefArray *colArray,
+                          NAColumnArray *nacolArray,
                          ElemDDLColRefArray *keyArray,
                          ComTdbVirtTableColumnInfo * colInfoArray,
                          ComTdbVirtTableKeyInfo * keyInfoArray,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index dccb58d..63af191 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -559,7 +559,7 @@ short CmpSeabaseDDL::processDDLandCreateDescs(
           return resetCQDs(hbaseSerialization, hbVal, -1);
         }
 
-      if (buildKeyInfoArray(&colArray, &keyArray, colInfoArray, keyInfoArray, 
FALSE,
+      if (buildKeyInfoArray(&colArray, NULL, &keyArray, colInfoArray, 
keyInfoArray, FALSE,
                            &keyLength, CTXTHEAP))
        {
          return resetCQDs(hbaseSerialization, hbVal, -1);
@@ -4517,6 +4517,7 @@ short CmpSeabaseDDL::updateSeabaseMDTable(
   Int32 objOwnerID = (tableInfo) ? tableInfo->objOwnerID : SUPER_USER;
   Int32 schemaOwnerID = (tableInfo) ? tableInfo->schemaOwnerID : SUPER_USER;
   Int64 objectFlags = (tableInfo) ? tableInfo->objectFlags : 0;
+  Int64 tablesFlags = (tableInfo) ? tableInfo->tablesFlags : 0;
   
   if 
(updateSeabaseMDObjectsTable(cliInterface,catName,schName,objName,objectType,
                                   validDef,objOwnerID, schemaOwnerID, 
objectFlags, inUID))
@@ -4807,7 +4808,7 @@ short CmpSeabaseDDL::updateSeabaseMDTable(
           hbaseCreateOptions = tableInfo->hbaseCreateOptions;
         }
 
-      str_sprintf(buf, "upsert into %s.\"%s\".%s values (%Ld, '%s', '%s', %d, 
%d, %d, %d, 0) ",
+      str_sprintf(buf, "upsert into %s.\"%s\".%s values (%Ld, '%s', '%s', %d, 
%d, %d, %d, %Ld) ",
                   getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_TABLES,
                   objUID, 
                   rowFormat,
@@ -4815,7 +4816,8 @@ short CmpSeabaseDDL::updateSeabaseMDTable(
                   rowDataLength,
                   rowTotalLength,
                   keyLength,
-                  numSaltPartns);
+                  numSaltPartns,
+                  tablesFlags);
       cliRC = cliInterface->executeImmediate(buf);
       if (cliRC < 0)
         {
@@ -5809,6 +5811,7 @@ short CmpSeabaseDDL::buildColInfoArray(
 
 short CmpSeabaseDDL::buildKeyInfoArray(
                                        ElemDDLColDefArray *colArray,
+                                       NAColumnArray * nacolArray,
                                        ElemDDLColRefArray *keyArray,
                                        ComTdbVirtTableColumnInfo * 
colInfoArray,
                                        ComTdbVirtTableKeyInfo * keyInfoArray,
@@ -5829,8 +5832,21 @@ short CmpSeabaseDDL::buildKeyInfoArray(
       keyInfoArray[index].colName = col_name; 
//(*keyArray)[index]->getColumnName();
 
       keyInfoArray[index].keySeqNum = index+1;
+
+      if ((! colArray) && (! nacolArray))
+        {
+          // this col doesn't exist. Return error.
+          *CmpCommon::diags() << DgSqlCode(-1009)
+                              << DgColumnName(keyInfoArray[index].colName);
+          
+          return -1;
+        }
+ 
+      NAString nas((*keyArray)[index]->getColumnName());
       keyInfoArray[index].tableColNum = (Lng32)
-        colArray->getColumnIndex((*keyArray)[index]->getColumnName());
+        (colArray ?
+         colArray->getColumnIndex((*keyArray)[index]->getColumnName()) :
+         nacolArray->getColumnPosition(nas));
 
       if (keyInfoArray[index].tableColNum == -1)
         {
@@ -5845,7 +5861,8 @@ short CmpSeabaseDDL::buildKeyInfoArray(
         ((*keyArray)[index]->getColumnOrdering() == COM_ASCENDING_ORDER ? 0 : 
1);
       keyInfoArray[index].nonKeyCol = 0;
 
-      if ((colInfoArray[keyInfoArray[index].tableColNum].nullable != 0) &&
+      if ((colInfoArray) &&
+          (colInfoArray[keyInfoArray[index].tableColNum].nullable != 0) &&
           (NOT allowNullableUniqueConstr))
         {
           *CmpCommon::diags() << 
DgSqlCode(-CAT_CLUSTERING_KEY_COL_MUST_BE_NOT_NULL_NOT_DROP)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/CmpSeabaseDDLmd.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLmd.h 
b/core/sql/sqlcomp/CmpSeabaseDDLmd.h
index 6f12ac9..ca78cd2 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLmd.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLmd.h
@@ -336,6 +336,14 @@ static const QString seabaseTablesDDL[] =
   {" ; "}
 };
 
+enum SeabaseTablesFlags
+  {
+    MD_TABLES_RESERVED1            = 0x0001,
+    MD_TABLES_RESERVED2            = 0x0002,
+    MD_TABLES_HIVE_EXT_COL_ATTRS   = 0x0004,
+    MD_TABLES_HIVE_EXT_KEY_ATTRS   = 0x0008
+  };
+
 static const QString seabaseTableConstraintsDDL[] =
 {
   {" create table "SEABASE_TABLE_CONSTRAINTS" "},

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 5a2c1d7..f71da4f 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -72,7 +72,8 @@ extern short CmpDescribeSeabaseTable (
                              char * colName = NULL,
                              short ada = 0, // 0,add. 1,drop. 2,alter
                              const NAColumn * nacol = NULL,
-                             const NAType * natype = NULL);
+                             const NAType * natype = NULL,
+                             Space *inSpace = NULL);
 
 // type:  1, invoke. 2, showddl. 3, create_like
 extern short cmpDisplayColumn(const NAColumn *nac,
@@ -431,6 +432,8 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
 
   // go create the schema - if it does not already exist.
   NAString createSchemaStmt ("CREATE SCHEMA IF NOT EXISTS ");
+  createSchemaStmt += tgtTableName.getCatalogNamePartAsAnsiString();
+  createSchemaStmt += ".";
   createSchemaStmt += tgtTableName.getSchemaNamePartAsAnsiString();
   if (isAuthorizationEnabled())
     {
@@ -480,7 +483,7 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
   tableInfo->createTime = 0;
   tableInfo->redefTime = 0;
   tableInfo->objUID = 0;
-  tableInfo->isAudited = 0;
+  tableInfo->isAudited = 1;
   tableInfo->validDef = 1;
   tableInfo->hbaseCreateOptions = NULL;
   tableInfo->numSaltPartns = 0;
@@ -488,6 +491,7 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
                                      COM_HBASE_EXTERNAL_FORMAT_TYPE;
   tableInfo->objectFlags = (isHive) ?  SEABASE_OBJECT_IS_EXTERNAL_HIVE : 
                                        SEABASE_OBJECT_IS_EXTERNAL_HBASE;
+  tableInfo->tablesFlags = 0;
 
   if (isAuthorizationEnabled())
     {
@@ -531,16 +535,94 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
       return -1;
     }
 
+  ElemDDLColDefArray &colArray = createTableNode->getColDefArray();
+  ElemDDLColRefArray &keyArray =
+    (createTableNode->getIsConstraintPKSpecified() ?
+     createTableNode->getPrimaryKeyColRefArray() :
+     (createTableNode->getStoreOption() == COM_KEY_COLUMN_LIST_STORE_OPTION ?
+      createTableNode->getKeyColumnArray() :
+      createTableNode->getPrimaryKeyColRefArray()));
+
+  // cqd HIVE_USE_EXT_TABLE_ATTRS:
+  //  if OFF, col or key attrs cannot be specified during ext table creation.
+  //  if ON,  col attrs could be specified.
+  //  if ALL, col and key attrs could be specified
+  NABoolean extTableAttrsSpecified = FALSE;
+  if (colArray.entries() > 0)
+    {
+      if (CmpCommon::getDefault(HIVE_USE_EXT_TABLE_ATTRS) == DF_OFF)
+        {
+          *CmpCommon::diags()
+            << DgSqlCode(-3242)
+            << DgString0("Cannot specify column attributes for external 
tables.");
+          return -1;
+        }
+
+      extTableAttrsSpecified = TRUE;
+      CmpSeabaseDDL::setMDflags
+        (tableInfo->tablesFlags, MD_TABLES_HIVE_EXT_COL_ATTRS);
+    }
+  
+  if (keyArray.entries() > 0)
+    {
+      if (CmpCommon::getDefault(HIVE_USE_EXT_TABLE_ATTRS) != DF_ALL)
+        {
+          *CmpCommon::diags()
+            << DgSqlCode(-3242)
+            << DgString0("Cannot specify key attribute for external tables.");
+          return -1;
+        }
+
+      extTableAttrsSpecified = TRUE;
+      CmpSeabaseDDL::setMDflags
+        (tableInfo->tablesFlags, MD_TABLES_HIVE_EXT_KEY_ATTRS);
+     }
+  
   // convert column array from NATable into a ComTdbVirtTableColumnInfo struct
-  const NAColumnArray &naColArray = naTable->getNAColumnArray();
+  NAColumnArray naColArray;
+  const NAColumnArray &origColArray = naTable->getNAColumnArray();
+
+  for (CollIndex c=0; c<origColArray.entries(); c++)
+    naColArray.insert(origColArray[c]);
+
   numCols = naColArray.entries();
+
+  // make sure all columns specified in colArray are part of naColArray
+  if (colArray.entries() > 0)
+    {
+      for (CollIndex colIndex = 0; colIndex < colArray.entries(); colIndex++)
+        {
+          const ElemDDLColDef *edcd = colArray[colIndex];          
+          
+          if (naColArray.getColumnPosition((NAString&)edcd->getColumnName()) < 
0)
+            {
+              // not found. return error.
+              *CmpCommon::diags() << DgSqlCode(-1009) 
+                                  << 
DgColumnName(ToAnsiIdentifier(edcd->getColumnName()));
+        
+              return -1;
+             }
+        }
+    }
+
   colInfoArray = new(STMTHEAP) ComTdbVirtTableColumnInfo[numCols];
   for (CollIndex index = 0; index < numCols; index++)
     {
       const NAColumn *naCol = naColArray[index];
+      const NAType * type = naCol->getType();
+      
+      // if colArray has been specified, then look for this column in
+      // that array and use the type specified there.
+      Int32 colIndex = -1;
+      if ((colArray.entries() > 0) &&
+          ((colIndex = colArray.getColumnIndex(naCol->getColName())) >= 0))
+        {
+          ElemDDLColDef *edcd = colArray[colIndex];
+          type = edcd->getColumnDataType();
+        }
 
       // call:  CmpSeabaseDDL::getTypeInfo to get column details
-      retcode = getTypeInfo(naCol->getType(), alignedFormat, serializedOption,
+      retcode = getTypeInfo(type, alignedFormat, serializedOption,
                    datatype, length, precision, scale, dtStart, dtEnd, 
upshifted, nullable,
                    charset, collationSequence, hbaseColFlags);
 
@@ -570,6 +652,32 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
       colInfoArray[index].colFlags = 0;
     }
 
+  ComTdbVirtTableKeyInfo * keyInfoArray = NULL;
+  Lng32 numKeys = 0;
+  numKeys = keyArray.entries();
+  if (numKeys > 0)
+    {
+      if (isHive)
+        {
+          *CmpCommon::diags()
+            << DgSqlCode(-4222)
+            << DgString0("\"PRIMARY KEY on external hive table\"");
+          
+          return -1;
+        }
+
+      keyInfoArray = new(STMTHEAP) ComTdbVirtTableKeyInfo[numKeys];
+      if (buildKeyInfoArray(NULL, (NAColumnArray*)&naColArray, &keyArray, 
+                            colInfoArray, keyInfoArray, TRUE))
+        {
+          *CmpCommon::diags()
+            << DgSqlCode(-CAT_UNABLE_TO_CREATE_OBJECT)
+            << DgTableName(extTgtTableName);
+          
+          return -1;
+        }
+    }
+
   Int64 objUID = -1;
   cliRC = 0;
   if (updateSeabaseMDTable(&cliInterface,
@@ -1771,7 +1879,9 @@ short CmpSeabaseDDL::createSeabaseTable2(
           return -1;
         }
 
-      if (buildKeyInfoArray(&colArray, &keyArray, colInfoArray, keyInfoArray, 
allowNullableUniqueConstr))
+      if (buildKeyInfoArray(&colArray, NULL,
+                            &keyArray, colInfoArray, keyInfoArray, 
+                            allowNullableUniqueConstr))
         {
           processReturn();
 
@@ -1963,6 +2073,7 @@ short CmpSeabaseDDL::createSeabaseTable2(
   tableInfo->validDef = 1;
   tableInfo->hbaseCreateOptions = NULL;
   tableInfo->objectFlags = 0;
+  tableInfo->tablesFlags = 0;
   
   if (fileAttribs.isOwnerSpecified())
     {
@@ -2982,8 +3093,10 @@ short CmpSeabaseDDL::dropSeabaseTable2(
               schemaNamePart,
               catalogNamePart);
 
+  bindWA.setExternalTableDrop(TRUE);
   NATable *naTable = bindWA.getNATable(cn); 
- 
+  bindWA.setExternalTableDrop(FALSE);
+
   const NAColumnArray &nacolArr =  naTable->getNAColumnArray();
   // Restore parser flags settings to what they originally were
   Set_SqlParser_Flags (savedParserFlags);
@@ -9419,6 +9532,7 @@ short CmpSeabaseDDL::getSpecialTableInfo
       tableInfo->schemaOwnerID = schemaOwner;
       tableInfo->hbaseCreateOptions = NULL;
       tableInfo->objectFlags = objectFlags;
+      tableInfo->tablesFlags = 0;
       tableInfo->rowFormat = COM_UNKNOWN_FORMAT_TYPE;
     }
 
@@ -10017,6 +10131,7 @@ desc_struct * 
CmpSeabaseDDL::getSeabaseSequenceDesc(const NAString &catName,
   tableInfo->schemaOwnerID = schemaOwner;
   tableInfo->hbaseCreateOptions = NULL;
   tableInfo->objectFlags = 0;
+  tableInfo->tablesFlags = 0;
 
   tableDesc =
     Generator::createVirtualTableDesc
@@ -10136,10 +10251,10 @@ desc_struct * 
CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName,
     }
   }
 
-  str_sprintf(query, "select is_audited, num_salt_partns, row_format from 
%s.\"%s\".%s where table_uid = %Ld for read committed access",
+  str_sprintf(query, "select is_audited, num_salt_partns, row_format, flags 
from %s.\"%s\".%s where table_uid = %Ld for read committed access",
               getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_TABLES,
               objUID);
-
+  
   Queue * tableAttrQueue = NULL;
   cliRC = cliInterface.fetchAllRows(tableAttrQueue, query, 0, FALSE, FALSE, 
TRUE);
 
@@ -10152,6 +10267,7 @@ desc_struct * 
CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName,
       return NULL;
     }
 
+  Int64 tablesFlags = 0;
   NABoolean isAudited = TRUE;
   Lng32 numSaltPartns = 0;
   NABoolean alignedFormat = FALSE;
@@ -10176,6 +10292,8 @@ desc_struct * 
CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName,
       char * format = vi->get(2);
       alignedFormat = (memcmp(format, COM_ALIGNED_FORMAT_LIT, 2) == 0);
      
+      tablesFlags = *(Int64*)vi->get(3);
+
       if (getTextFromMD(&cliInterface, objUID, COM_HBASE_OPTIONS_TEXT, 0,
                         *hbaseCreateOptions))
         {
@@ -10792,6 +10910,7 @@ desc_struct * 
CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName,
       tableInfo->allColFams = NULL;
     }
   tableInfo->objectFlags = objectFlags;
+  tableInfo->tablesFlags = tablesFlags;
 
   tableDesc =
     Generator::createVirtualTableDesc

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/DefaultConstants.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/DefaultConstants.h 
b/core/sql/sqlcomp/DefaultConstants.h
index 92ccb39..0dfaeeb 100644
--- a/core/sql/sqlcomp/DefaultConstants.h
+++ b/core/sql/sqlcomp/DefaultConstants.h
@@ -3830,6 +3830,9 @@ enum DefaultConstants
   // Otherwise typed as smallint.
   TRAF_TINYINT_SPJ_SUPPORT,
 
+  // use info from external table created on this hive table
+  HIVE_USE_EXT_TABLE_ATTRS,
+
   // This enum constant must be the LAST one in the list; it's a count,
   // not an Attribute (it's not IN DefaultDefaults; it's the SIZE of it)!
   __NUM_DEFAULT_ATTRIBUTES

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b39f7524/core/sql/sqlcomp/nadefaults.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/nadefaults.cpp b/core/sql/sqlcomp/nadefaults.cpp
index 752df9f..c77b954 100644
--- a/core/sql/sqlcomp/nadefaults.cpp
+++ b/core/sql/sqlcomp/nadefaults.cpp
@@ -1973,6 +1973,7 @@ SDDkwd__(EXE_DIAGNOSTIC_EVENTS,           "OFF"),
   DDpct__(HIVE_NUM_ESPS_ROUND_DEVIATION,        "34"),
   DDint__(HIVE_SCAN_SPECIAL_MODE,                "0"),
   DDkwd__(HIVE_SORT_HDFS_HOSTS,                 "ON"),
+  DDkwd__(HIVE_USE_EXT_TABLE_ATTRS,             "ON"),
   DD_____(HIVE_USE_FAKE_SQ_NODE_NAMES,          "" ),
   DDkwd__(HIVE_USE_FAKE_TABLE_DESC,             "OFF"),
   DDkwd__(HIVE_USE_HASH2_AS_PARTFUNCION,        "ON"),
@@ -6673,6 +6674,11 @@ DefaultToken NADefaults::token(Int32 attrEnum,
        isValid = TRUE;
     break;
 
+    case HIVE_USE_EXT_TABLE_ATTRS:
+      if (tok == DF_ALL || tok == DF_OFF || tok == DF_ON )
+       isValid = TRUE;
+      break;
+
     case INDEX_ELIMINATION_LEVEL:
       if  (tok == DF_MINIMUM    || tok == DF_MEDIUM ||
           tok == DF_MAXIMUM     || tok == DF_AGGRESSIVE )

Reply via email to