trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ansha...@apache.org
Subject [1/2] incubator-trafodion git commit: JIRA-2137 Addnl change to metadata improvement based on review comments
Date Thu, 04 Aug 2016 00:38:22 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 2a0a3018d -> 37901fb53


JIRA-2137 Addnl change to metadata improvement based on review comments

Code now handles writing binary data into TEXT after encoding it.
And decodes it during read.

Non-binary data is added using input params  instead of literals.


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

Branch: refs/heads/master
Commit: f6966c703b66fda1d5c2be4377fad72f51a9727d
Parents: 112f1e8
Author: Anoop Sharma <anoop.sharma@esgyn.com>
Authored: Wed Aug 3 21:53:24 2016 +0000
Committer: Anoop Sharma <anoop.sharma@esgyn.com>
Committed: Wed Aug 3 21:53:24 2016 +0000

----------------------------------------------------------------------
 core/sql/sqlcat/TrafDDLdesc.cpp          |   2 +
 core/sql/sqlcat/TrafDDLdesc.h            |   8 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h         |  10 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 129 +++++++-------------------
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp |   2 +-
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp  |  30 +++++-
 6 files changed, 76 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f6966c70/core/sql/sqlcat/TrafDDLdesc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/TrafDDLdesc.cpp b/core/sql/sqlcat/TrafDDLdesc.cpp
index 112bfac..5bfe1d8 100644
--- a/core/sql/sqlcat/TrafDDLdesc.cpp
+++ b/core/sql/sqlcat/TrafDDLdesc.cpp
@@ -396,6 +396,7 @@ Long TrafIndexesDesc::pack(void * space)
 {
   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
   indexname = (indexname ? (char*)(((Space*)space)->convertToOffset(indexname)) : NULL);
+  hbaseSplitClause = (hbaseSplitClause ? (char*)(((Space*)space)->convertToOffset(hbaseSplitClause))
: NULL);
   hbaseCreateOptions = (hbaseCreateOptions ? (char*)(((Space*)space)->convertToOffset(hbaseCreateOptions))
: NULL);
 
   files_desc.pack(space);
@@ -409,6 +410,7 @@ Lng32 TrafIndexesDesc::unpack(void * base, void * reallocator)
 {
   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
   indexname = (indexname ? (char*)((char*)base - (Long)indexname) : NULL);
+  hbaseSplitClause = (hbaseSplitClause ? (char*)((char*)base - (Long)hbaseSplitClause) :
NULL);
   hbaseCreateOptions = (hbaseCreateOptions ? (char*)((char*)base - (Long)hbaseCreateOptions)
: NULL);
 
   if (files_desc.unpack(base, reallocator)) return -1;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f6966c70/core/sql/sqlcat/TrafDDLdesc.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/TrafDDLdesc.h b/core/sql/sqlcat/TrafDDLdesc.h
index 3a599e6..b97f027 100644
--- a/core/sql/sqlcat/TrafDDLdesc.h
+++ b/core/sql/sqlcat/TrafDDLdesc.h
@@ -597,8 +597,12 @@ public:
   Int16 /*ComRowFormat*/          rowFormat_;
   Lng32 numSaltPartns; // number of salted partns created for a seabase table.
 
+  Lng32 numInitialSaltRegions; // initial # of regions created for salted table
+  char filler0[4];
+
   Int64 indexesDescFlags; // my flags
 
+  char*  hbaseSplitClause;
   char*  hbaseCreateOptions;
 
   DescStructPtr files_desc;
@@ -799,13 +803,13 @@ public:
   char* librarySqlName;
   char* libraryFileName;
   char* signature;
-  ComSInt32 paramsCount;
+  Int32 paramsCount;
   DescStructPtr params;
   ComRoutineLanguage language;
   ComRoutineType UDRType;
   ComRoutineSQLAccess sqlAccess;
   ComRoutineTransactionAttributes transactionAttributes;
-  ComSInt32 maxResults;
+  Int32 maxResults;
   ComRoutineParamStyle paramStyle;
   NABoolean isDeterministic;
   NABoolean isCallOnNull;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f6966c70/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 3b583e7..c150a26 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -186,7 +186,8 @@ class CmpSeabaseDDL
        Int64 constrUID,
        ComTextType textType,
        Lng32 textSubID,
-       NAString &constrText);
+       NAString &constrText,
+       NABoolean binaryData = FALSE);
   
   static short createHistogramTables(
     ExeCliInterface *cliInterface,
@@ -770,7 +771,9 @@ protected:
                         Int64 objUID, 
                         ComTextType textType, 
                         Lng32 subID, 
-                        NAString &text,
+                        NAString &textInputData,
+                        char * binaryInputData = NULL,
+                        Lng32 binaryInputDataLen = -1,
                         NABoolean withDelete = FALSE); // del before ins
 
   // input data in non-char format.
@@ -1176,7 +1179,8 @@ protected:
        Int64 constrUID,
        ComTextType textType,
        Lng32 textSubID,
-       NAString &constrText);
+       NAString &constrText,
+       NABoolean binaryData = FALSE);
   
   void alterSeabaseTableAddCheckConstraint(
 					StmtDDLAddConstraint * alterAddConstraint,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f6966c70/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 1a8f16f..a3d834c 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -5318,7 +5318,7 @@ short CmpSeabaseDDL::checkAndGetStoredObjectDesc(
 
   NAString packedDesc;
   cliRC = getTextFromMD(
-       cliInterface, objUID, COM_STORED_DESC_TEXT, 0, packedDesc);
+       cliInterface, objUID, COM_STORED_DESC_TEXT, 0, packedDesc, TRUE);
   if (cliRC < 0)
     {
       *CmpCommon::diags() << DgSqlCode(-4493)
@@ -6122,7 +6122,9 @@ short CmpSeabaseDDL::updateTextTable(ExeCliInterface *cliInterface,
                                      Int64 objUID, 
                                      ComTextType textType, 
                                      Lng32 subID, 
-                                     NAString &text,
+                                     NAString &textInputData,
+                                     char * binaryInputData,
+                                     Lng32 binaryInputDataLen,
                                      NABoolean withDelete)
 {
   Lng32 cliRC = 0;
@@ -6140,113 +6142,38 @@ short CmpSeabaseDDL::updateTextTable(ExeCliInterface *cliInterface,
         }
     }
 
-  Lng32 textLen = text.length();
-  Lng32 bufLen = (textLen>TEXTLEN ? TEXTLEN : textLen) + 1000;
-  char * buf = new(STMTHEAP) char[bufLen];
-  Lng32 numRows = (textLen / TEXTLEN) + 1;
-  Lng32 currPos = 0;
-  for (Lng32 i = 0; i < numRows; i++)
+  char * dataToInsert = NULL;
+  Lng32 dataLen = -1;
+  if (binaryInputData)
     {
-      NAString temp;
-
-      if (i < numRows-1)
-        ToQuotedString(temp, text(currPos, TEXTLEN));
-      else
-        ToQuotedString(temp, text(currPos, (textLen - currPos)));
-
-      if (snprintf(buf, bufLen, "insert into %s.\"%s\".%s values (%ld, %d, %d, %d, 0, %s)",
-                   getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_TEXT,
-                   objUID,
-                   textType,
-                   subID,
-                   i,
-                   temp.data()) >= bufLen)
-        {
-          // we left room in buf for a few hundred quotes, but using
-          // too many could get us here
-          *CmpCommon::diags() << DgSqlCode(-1207);
-          return -1;
-        }
-      cliRC = cliInterface->executeImmediate(buf);
-      
-      if (cliRC < 0)
-        {
-          cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
-          return -1;
-        }
+      Lng32 encodedMaxLen = str_encoded_len(binaryInputDataLen);
+      char * encodedData = new(STMTHEAP) char[encodedMaxLen];
+      Lng32 encodedLen = 
+        str_encode(encodedData, encodedMaxLen, binaryInputData, binaryInputDataLen);
 
-      currPos += TEXTLEN;
+      dataToInsert = encodedData;
+      dataLen =  encodedLen;
     }
-
-  return 0;
-}
-
-short CmpSeabaseDDL::updateTextTableWithBinaryData
-(ExeCliInterface *cliInterface,
- Int64 objUID, 
- ComTextType textType, 
- Lng32 subID, 
- char * inputData,
- Int32 inputDataLen,
- NABoolean withDelete)
-{
-  Lng32 cliRC = 0;
-  if (withDelete)
+  else
     {
-      // Note: It might be tempting to try an upsert instead of a
-      // delete followed by an insert, but this won't work. It is
-      // possible that the metadata text could shrink and take fewer
-      // rows in its new form than the old. So we do the simple thing
-      // to avoid such complications.
-      cliRC = deleteFromTextTable(cliInterface, objUID, textType, subID);
-      if (cliRC < 0)
-        {
-          return -1;
-        }
+      dataToInsert = (char*)textInputData.data();
+      dataLen =  textInputData.length();
     }
 
-  // convert input data to utf8 first.
-  ComDiagsArea * diagsArea = CmpCommon::diags();
-  char * inputDataUTF8 = new(STMTHEAP) char[inputDataLen*4];
-  Lng32 inputDataLenUTF8 = 0;
-  ex_expr::exp_return_type rc =
-    convDoIt(inputData,
-             inputDataLen,
-             REC_BYTE_F_ASCII,
-             0,
-             (Int32)CharInfo::ISO88591,
-             inputDataUTF8,
-             inputDataLen*4,
-             REC_BYTE_V_ASCII,
-             inputDataLen,
-             (Int32)CharInfo::UTF8,
-             (char*)&inputDataLenUTF8,
-             sizeof(Lng32),
-             STMTHEAP,
-             &diagsArea,
-             CONV_ASCII_F_V);
-  if ((rc != ex_expr::EXPR_OK) ||
-      (inputDataLenUTF8 <= 0))
-    {
-      return -1;
-    }
-  
   Int32 maxLen = TEXTLEN;
   char queryBuf[1000];
-  Lng32 numRows = (inputDataLenUTF8 / maxLen) + 1;
+  Lng32 numRows = (dataLen / maxLen) + 1;
   Lng32 currPos = 0;
-  Int32 currDataLen = 0;
+  Lng32 currDataLen = 0;
 
   for (Lng32 i = 0; i < numRows; i++)
     {
-      NAString temp;
-
       if (i < numRows-1)
         currDataLen = maxLen;
       else
-        currDataLen = inputDataLenUTF8 - currPos;
+        currDataLen = dataLen - currPos;
 
-      str_sprintf(queryBuf, "insert into %s.\"%s\".%s values (%Ld, %d, %d, %d, 0, cast(?
as char(%d bytes) character set utf8 not null))",
+      str_sprintf(queryBuf, "insert into %s.\"%s\".%s values (%Ld, %d, %d, %d, 0, cast(?
as char(%d bytes) not null))",
                   getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_TEXT,
                   objUID,
                   textType,
@@ -6254,7 +6181,7 @@ short CmpSeabaseDDL::updateTextTableWithBinaryData
                   i,
                   currDataLen);
       cliRC = cliInterface->executeImmediateCEFC
-        (queryBuf, &inputData[currPos], currDataLen, NULL, NULL, NULL);
+        (queryBuf, &dataToInsert[currPos], currDataLen, NULL, NULL, NULL);
       
       if (cliRC < 0)
         {
@@ -6268,6 +6195,20 @@ short CmpSeabaseDDL::updateTextTableWithBinaryData
   return 0;
 }
 
+short CmpSeabaseDDL::updateTextTableWithBinaryData
+(ExeCliInterface *cliInterface,
+ Int64 objUID, 
+ ComTextType textType, 
+ Lng32 subID, 
+ char * inputData,
+ Int32 inputDataLen,
+ NABoolean withDelete)
+{
+  NAString dummy;
+  return updateTextTable(cliInterface, objUID, textType, subID, dummy,
+                         inputData, inputDataLen, withDelete);
+}
+
 short CmpSeabaseDDL::deleteFromTextTable(ExeCliInterface *cliInterface,
                                          Int64 objUID, 
                                          ComTextType textType, 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f6966c70/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
index b914961..522a4af 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
@@ -1034,7 +1034,7 @@ void CmpSeabaseDDL::alterSeabaseSchema(StmtDDLAlterSchema * alterSchemaNode)
       goto label_error;
    }
 
-   if (!isDDLOperationAuthorized(SQLOperation::DROP_SCHEMA,
+   if (!isDDLOperationAuthorized(SQLOperation::ALTER_SCHEMA,
                                  schemaOwnerID,schemaOwnerID))
    {
       *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f6966c70/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 9454a97..988d382 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -7193,7 +7193,7 @@ void CmpSeabaseDDL::alterSeabaseTableAlterColumnRename(
           NAString renamedQuotedColName = "\"" + renamedColName + "\"";
           saltText = replaceAll(saltText, quotedColName, renamedQuotedColName);
           cliRC = updateTextTable(&cliInterface, objUID, COM_COMPUTED_COL_TEXT,
-                                  saltColPos, saltText, TRUE);
+                                  saltColPos, saltText, NULL, -1, TRUE);
           if (cliRC < 0)
             {
               processReturn();
@@ -8513,14 +8513,16 @@ short CmpSeabaseDDL::getTextFromMD(
                                    Int64 textUID,
                                    ComTextType textType,
                                    Lng32 textSubID,
-                                   NAString &outText)
+                                   NAString &outText,
+                                   NABoolean binaryData)
 {
   short retcode = getTextFromMD(getSystemCatalog(),
                                 cliInterface,
                                 textUID,
                                 textType,
                                 textSubID,
-                                outText);
+                                outText,
+                                binaryData);
 
   if (retcode)
     processReturn();
@@ -8534,7 +8536,8 @@ short CmpSeabaseDDL::getTextFromMD(const char * catalogName,
                                    Int64 textUID,
                                    ComTextType textType,
                                    Lng32 textSubID,
-                                   NAString &outText)
+                                   NAString &outText,
+                                   NABoolean binaryData)
 {
   Lng32 cliRC;
 
@@ -8554,6 +8557,7 @@ short CmpSeabaseDDL::getTextFromMD(const char * catalogName,
     }
   
   // glue text together
+  NAString binaryText;
   for (Lng32 idx = 0; idx < textQueue->numEntries(); idx++)
     {
       OutputInfo * vi = (OutputInfo*)textQueue->getNext(); 
@@ -8562,7 +8566,23 @@ short CmpSeabaseDDL::getTextFromMD(const char * catalogName,
 
       char * text = (char*)vi->get(1);
    
-      outText.append(text, len);
+      if (binaryData)
+        binaryText.append(text, len);
+      else
+        outText.append(text, len);
+    }
+
+  // if binary data, decode it and then return
+  if (binaryData)
+    {
+      Lng32 decodedMaxLen = str_decoded_len(binaryText.length());
+      
+      char * decodedData = new(STMTHEAP) char[decodedMaxLen];
+      Lng32 decodedLen =
+        str_decode(decodedData, decodedMaxLen,
+                   binaryText.data(), binaryText.length());
+
+      outText.append(decodedData, decodedLen);
     }
 
   return 0;


Mime
View raw message