You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by sa...@apache.org on 2017/03/28 15:19:03 UTC

[3/6] incubator-trafodion git commit: Support for insert-select from varchar/char colummns into lob columns. Supposed for insert with parameter.This work is done as part of [TRAFODION-2516]

Support for insert-select from varchar/char colummns into lob columns. Supposed for insert with parameter.This work is done as part of  [TRAFODION-2516]


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

Branch: refs/heads/master
Commit: d3d707ae49c7922ef033d2a9f2428aef5a442d7b
Parents: 2aeb4d1
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Thu Mar 23 04:49:13 2017 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Thu Mar 23 04:49:13 2017 +0000

----------------------------------------------------------------------
 core/sql/exp/ExpLOB.cpp               |  14 ++-
 core/sql/generator/GenPreCode.cpp     |   2 +-
 core/sql/optimizer/BindItemExpr.cpp   |  36 +++++-
 core/sql/optimizer/SynthType.cpp      |  14 ++-
 core/sql/regress/executor/EXPECTED130 | 183 ++++++++++++++++++++++-------
 core/sql/regress/executor/TEST130     |  32 +++++
 6 files changed, 229 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d3d707ae/core/sql/exp/ExpLOB.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOB.cpp b/core/sql/exp/ExpLOB.cpp
index 66da5fc..447ce89 100644
--- a/core/sql/exp/ExpLOB.cpp
+++ b/core/sql/exp/ExpLOB.cpp
@@ -774,7 +774,12 @@ ex_expr::exp_return_type ExpLOBiud::insertDesc(char *op_data[],
   // lob desc update, then remove this.
   Int64 lobLen = 0;
   if(!fromEmpty())
-    lobLen = getOperand(1)->getLength();
+    {
+      lobLen = getOperand(1)->getLength();
+      //If source is a varchar, find the actual length
+      if (fromString() && ((getOperand(1)->getVCIndicatorLength() >0)))       
+        lobLen = getOperand(1)->getLength(op_data[1]- getOperand(1)->getVCIndicatorLength());
+    }
 
   // until SQL_EXEC_LOBcliInterface is changed to allow for unlimited
   // black box sizes, we have to prevent over-sized file names from
@@ -919,7 +924,12 @@ ex_expr::exp_return_type ExpLOBiud::insertData(Lng32 handleLen,
     return ex_expr::EXPR_ERROR;
 
   lobLen = getOperand(1)->getLength();
-  
+  if(fromString())
+    {
+      //If source is a varchar, find the actual length
+      if (getOperand(1)->getVCIndicatorLength() >0)   
+        lobLen = getOperand(1)->getLength(op_data[1]- getOperand(1)->getVCIndicatorLength());  
+    }
   char * lobData = NULL;
   if (fromExternal())
     {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d3d707ae/core/sql/generator/GenPreCode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp
index 381f409..f82bebc 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -5534,7 +5534,7 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
 		{
 		  li = new(generator->wHeap())
 		    LOBinsert(child1Expr, NULL, LOBoper::LOB_);
-
+                  
 		  li->insertedTableObjectUID() = 
 		    getIndexDesc()->getPrimaryTableDesc()->
 		    getNATable()->objectUid().castToInt64();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d3d707ae/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index bd30515..e2df528 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -6071,7 +6071,7 @@ ItemExpr *Assign::bindNode(BindWA *bindWA)
   if (bindWA->errStatus())
       return this;
   child(0) = boundExpr;
-
+ 
 
   if (CmpCommon::getDefault(JDBC_PROCESS) == DF_ON)
   {
@@ -6173,7 +6173,35 @@ ItemExpr *Assign::bindNode(BindWA *bindWA)
     } // QSTUFF
 
   } // isUserSpecified
+  NABuiltInTypeEnum sourceType =  child(1)->castToItemExpr()->getValueId().getType().getTypeQualifier() ;
+  NABuiltInTypeEnum targetType =  child(0)->castToItemExpr()->getValueId().getType().getTypeQualifier() ;
+  if ((sourceType == NA_CHARACTER_TYPE) && (targetType == NA_LOB_TYPE))
+    {
+      ValueId vid1 = child(1)->castToItemExpr()->getValueId();  
+      // Add a stringToLob node
+      ItemExpr *newChild =  new (bindWA->wHeap()) LOBinsert( vid1.getItemExpr(), NULL, LOBoper::STRING_, FALSE);    
+      newChild->bindNode(bindWA);
+      if (bindWA->errStatus())
+	return boundExpr; 
+      setChild(1, newChild);
+    }
+  /* if ((sourceType == NA_UNKNOWN_TYPE) && (targetType = NA_LOB_TYPE))
+    {
+      ValueId vid1 = child(1)->castToItemExpr()->getValueId();
+    
+      SQLVarChar c1(CmpCommon::getDefaultNumeric(MAX_LONG_VARCHAR_DEFAULT_SIZE));
+      vid1.coerceType(c1, NA_CHARACTER_TYPE);
 
+                                                        
+					       
+      // Add a stringToLob node
+      ItemExpr *newChild =  new (bindWA->wHeap()) LOBinsert( vid1.getItemExpr(), NULL, LOBoper::STRING_, FALSE);
+      newChild->bindNode(bindWA);
+      if (bindWA->errStatus())
+	return boundExpr;
+      setChild(1, newChild);
+
+    }*/
   if ((NOT child(0)->getValueId().getType().
        isCompatible(child(1)->getValueId().getType())) &&
       (CmpCommon::getDefault(ALLOW_INCOMPATIBLE_OPERATIONS) == DF_ON) &&
@@ -6191,13 +6219,13 @@ ItemExpr *Assign::bindNode(BindWA *bindWA)
 	return boundExpr;
       setChild(1, newChild);
     }
-
+    
+ 
   // If we assign a numeric type and the source has a larger scale then
   // the target we cast the source to reduce the scale (truncate).
   // We also cast (truncate) if we deal with char and the source is larger
   // than the target.
-  NABuiltInTypeEnum targetType =
-    child(0)->getValueId().getType().getTypeQualifier();
+  targetType =  child(0)->castToItemExpr()->getValueId().getType().getTypeQualifier() ;
   if (targetType == NA_CHARACTER_TYPE) {
     Lng32 sourceLength = ((CharType&)(child(1)->getValueId().getType())).getStrCharLimit();
     Lng32 targetLength = ((CharType&)(child(0)->getValueId().getType())).getStrCharLimit();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d3d707ae/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index 474a537..e3766a4 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1853,6 +1853,7 @@ const NAType *Assign::doSynthesizeType(ValueId & targetId, ValueId & sourceId)
 {
   NABoolean ODBC = (CmpCommon::getDefault(ODBC_PROCESS) == DF_ON);
   NABoolean JDBC = (CmpCommon::getDefault(JDBC_PROCESS) == DF_ON);
+  NABoolean isSourceNullConst = FALSE;
   NABoolean forceSourceParamToBeNullable = 
     (CmpCommon::getDefault(COMP_BOOL_173) == DF_ON);
 
@@ -1866,7 +1867,16 @@ const NAType *Assign::doSynthesizeType(ValueId & targetId, ValueId & sourceId)
 
   NABoolean sourceIsUntypedParam = 
     (sourceId.getType().getTypeQualifier() == NA_UNKNOWN_TYPE);
-
+  if ((sourceId.getItemExpr()->getOperatorType() == ITM_CONSTANT)
+      && (((ConstValue*)sourceId.getItemExpr())->isNull()))
+    isSourceNullConst = TRUE;
+  if (sourceIsUntypedParam && (targetType.getTypeQualifier()  == NA_LOB_TYPE) 
+      && !isSourceNullConst)
+    {     
+      ValueId vid1 = child(1)->castToItemExpr()->getValueId();  
+      SQLVarChar c1(CmpCommon::getDefaultNumeric(MAX_LONG_VARCHAR_DEFAULT_SIZE));
+      vid1.coerceType(c1, NA_CHARACTER_TYPE);
+    }
   // Charset inference.
   const NAType& sourceType = sourceId.getType();
   targetId.coerceType(sourceType);
@@ -6704,7 +6714,7 @@ const NAType *LOBinsert::synthesizeType()
   if (child(0))
     {
       vid1 = child(0)->getValueId();
-      typ1 = &vid1.getType();
+      typ1 = &vid1.getType();     
     }
 
   if ((obj_ == STRING_) ||