You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by an...@apache.org on 2019/02/23 21:18:07 UTC

[trafodion] branch master updated (8d54c2f -> 39d8fb2)

This is an automated email from the ASF dual-hosted git repository.

ansharma pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/trafodion.git.


    from 8d54c2f  Merge PR 1801
     new c63a78e  jira TRAFODION-3157 Add support for BINARY/VARBINARY datatype
     new e8d2c3c  turn off binary support by default except from sqlci/trafci
     new 39d8fb2  PR-1803 TRAFODION-3157 Add support for BINARY/VARBINARY datatype

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/trafodion/jdbc/t4/InterfaceResultSet.java  |  23 +-
 .../org/trafodion/jdbc/t4/InterfaceStatement.java  |  45 +-
 .../trafodion/jdbc/t4/TrafT4CallableStatement.java |   4 +-
 .../java/org/trafodion/jdbc/t4/TrafT4Desc.java     |  16 +-
 .../trafodion/jdbc/t4/TrafT4PreparedStatement.java |  35 +-
 .../org/trafodion/jdbc/t4/TrafT4ResultSet.java     |  24 +-
 .../odbc/src/odbc/nsksrvrcore/sqlinterface.cpp     |  60 +-
 .../main/java/org/trafodion/ci/DatabaseQuery.java  |  65 ++-
 .../src/main/java/org/trafodion/ci/Session.java    |  25 +-
 .../java/org/trafodion/ci/SessionInterface.java    |   1 +
 core/sql/bin/SqlciErrors.txt                       |   4 +-
 core/sql/cli/CliExpExchange.cpp                    |  16 +-
 core/sql/cli/sqlcli.h                              |   9 +
 core/sql/common/BaseTypes.cpp                      |  22 +
 core/sql/common/CharType.cpp                       | 154 +++++-
 core/sql/common/CharType.h                         |  78 ++-
 core/sql/common/ComSSL.h                           |   3 +
 core/sql/common/ComSmallDefs.h                     |   2 +
 core/sql/common/MiscType.cpp                       |   1 +
 core/sql/common/NAType.cpp                         |  20 +-
 core/sql/common/NAType.h                           |   1 +
 core/sql/common/OperTypeEnum.h                     |   6 +-
 core/sql/common/charinfo.cpp                       |   4 +-
 core/sql/common/charinfo.h                         |   3 +-
 core/sql/common/conversionHex.cpp                  |   1 +
 core/sql/common/dfs2rec.h                          |  22 +-
 core/sql/common/sql_charset_strings.h              |   3 +
 core/sql/common/str.cpp                            |  65 ++-
 core/sql/common/str.h                              |   8 +
 core/sql/exp/ExpError.cpp                          | 211 ++++---
 core/sql/exp/ExpError.h                            |   3 +-
 core/sql/exp/ExpErrorEnums.h                       |   1 +
 core/sql/exp/ExpPCodeClauseGen.cpp                 |   2 +-
 core/sql/exp/exp_attrs.cpp                         |  10 +-
 core/sql/exp/exp_clause.cpp                        |  75 +--
 core/sql/exp/exp_clause.h                          |   9 +-
 core/sql/exp/exp_clause_derived.h                  |  17 +-
 core/sql/exp/exp_comp.cpp                          |  18 +-
 core/sql/exp/exp_conv.cpp                          | 232 ++++++--
 core/sql/exp/exp_datetime.cpp                      |   2 +-
 core/sql/exp/exp_expr.h                            |  12 +-
 core/sql/exp/exp_fixup.cpp                         |  65 ++-
 core/sql/exp/exp_function.cpp                      |  53 +-
 core/sql/exp/exp_function.h                        |  35 +-
 core/sql/exp/exp_tuple_desc.cpp                    |  15 +-
 core/sql/generator/GenExpGenerator.cpp             |  14 +-
 core/sql/generator/GenFastTransport.cpp            |  65 ++-
 core/sql/generator/GenItemFunc.cpp                 |  18 +
 core/sql/generator/GenPreCode.cpp                  | 257 ++++-----
 core/sql/generator/GenRelMisc.cpp                  |  14 +
 core/sql/generator/GenRelScan.cpp                  |  12 +-
 core/sql/optimizer/BindItemExpr.cpp                | 115 +++-
 core/sql/optimizer/BindRelExpr.cpp                 |  77 ++-
 core/sql/optimizer/ItemExpr.cpp                    |  23 +-
 core/sql/optimizer/NAColumn.cpp                    |  10 +
 core/sql/optimizer/NATable.cpp                     |  18 +
 core/sql/optimizer/RelExpr.cpp                     |   2 +-
 core/sql/optimizer/RelFastTransport.cpp            |   2 +-
 core/sql/optimizer/RelMisc.h                       |  26 +-
 core/sql/optimizer/SynthType.cpp                   | 260 +++++----
 core/sql/optimizer/ValueDesc.cpp                   |  14 +
 core/sql/parser/ParKeyWords.cpp                    |  10 +-
 core/sql/parser/sqlparser.y                        | 149 +++--
 core/sql/parser/ulexer.cpp                         |   6 +-
 core/sql/regress/charsets/EXPECTED315              |  24 +
 core/sql/regress/charsets/TEST315                  |   3 +
 core/sql/regress/core/EXPECTED038.LINUX            |  10 +-
 core/sql/regress/executor/EXPECTED022.SB           |  16 +-
 core/sql/regress/executor/EXPECTED050              |   4 +-
 core/sql/regress/seabase/EXPECTED002               |   3 +
 core/sql/regress/seabase/EXPECTED004               | 603 +++++++++++++++++++++
 core/sql/regress/seabase/EXPECTED027               |  84 +--
 core/sql/regress/seabase/TEST002                   |   1 +
 core/sql/regress/seabase/TEST003                   |   2 +-
 core/sql/regress/seabase/TEST004                   | 181 +++++++
 core/sql/sqlci/Formatter.cpp                       |  24 +
 core/sql/sqlci/Param.cpp                           |  15 +-
 core/sql/sqlci/SqlCmd.cpp                          |  61 ++-
 core/sql/sqlci/SqlciEnv.cpp                        |   5 +
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp           |   5 +-
 core/sql/sqlcomp/CmpSeabaseDDLutil.cpp             |   4 +
 core/sql/sqlcomp/DefaultConstants.h                |  21 +
 core/sql/sqlcomp/nadefaults.cpp                    |   6 +
 core/sql/ustat/hs_cli.cpp                          |   8 +
 core/sql/ustat/hs_globals.cpp                      |  34 +-
 core/sql/ustat/hs_globals.h                        |   2 +-
 core/sql/ustat/hs_la.cpp                           |   4 +-
 87 files changed, 2987 insertions(+), 705 deletions(-)
 create mode 100644 core/sql/regress/seabase/EXPECTED004
 create mode 100644 core/sql/regress/seabase/TEST004


[trafodion] 03/03: PR-1803 TRAFODION-3157 Add support for BINARY/VARBINARY datatype

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ansharma pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafodion.git

commit 39d8fb21efac3e711c20127760be153bcb8385cb
Merge: 8d54c2f e8d2c3c
Author: Anoop Sharma <an...@esgyn.com>
AuthorDate: Sat Feb 23 21:17:44 2019 +0000

    PR-1803 TRAFODION-3157 Add support for BINARY/VARBINARY datatype

 .../org/trafodion/jdbc/t4/InterfaceResultSet.java  |  23 +-
 .../org/trafodion/jdbc/t4/InterfaceStatement.java  |  45 +-
 .../trafodion/jdbc/t4/TrafT4CallableStatement.java |   4 +-
 .../java/org/trafodion/jdbc/t4/TrafT4Desc.java     |  16 +-
 .../trafodion/jdbc/t4/TrafT4PreparedStatement.java |  35 +-
 .../org/trafodion/jdbc/t4/TrafT4ResultSet.java     |  24 +-
 .../odbc/src/odbc/nsksrvrcore/sqlinterface.cpp     |  60 +-
 .../main/java/org/trafodion/ci/DatabaseQuery.java  |  65 ++-
 .../src/main/java/org/trafodion/ci/Session.java    |  25 +-
 .../java/org/trafodion/ci/SessionInterface.java    |   1 +
 core/sql/bin/SqlciErrors.txt                       |   4 +-
 core/sql/cli/CliExpExchange.cpp                    |  16 +-
 core/sql/cli/sqlcli.h                              |   9 +
 core/sql/common/BaseTypes.cpp                      |  22 +
 core/sql/common/CharType.cpp                       | 154 +++++-
 core/sql/common/CharType.h                         |  78 ++-
 core/sql/common/ComSSL.h                           |   3 +
 core/sql/common/ComSmallDefs.h                     |   2 +
 core/sql/common/MiscType.cpp                       |   1 +
 core/sql/common/NAType.cpp                         |  20 +-
 core/sql/common/NAType.h                           |   1 +
 core/sql/common/OperTypeEnum.h                     |   6 +-
 core/sql/common/charinfo.cpp                       |   4 +-
 core/sql/common/charinfo.h                         |   3 +-
 core/sql/common/conversionHex.cpp                  |   1 +
 core/sql/common/dfs2rec.h                          |  22 +-
 core/sql/common/sql_charset_strings.h              |   3 +
 core/sql/common/str.cpp                            |  65 ++-
 core/sql/common/str.h                              |   8 +
 core/sql/exp/ExpError.cpp                          | 211 ++++---
 core/sql/exp/ExpError.h                            |   3 +-
 core/sql/exp/ExpErrorEnums.h                       |   1 +
 core/sql/exp/ExpPCodeClauseGen.cpp                 |   2 +-
 core/sql/exp/exp_attrs.cpp                         |  10 +-
 core/sql/exp/exp_clause.cpp                        |  75 +--
 core/sql/exp/exp_clause.h                          |   9 +-
 core/sql/exp/exp_clause_derived.h                  |  17 +-
 core/sql/exp/exp_comp.cpp                          |  18 +-
 core/sql/exp/exp_conv.cpp                          | 232 ++++++--
 core/sql/exp/exp_datetime.cpp                      |   2 +-
 core/sql/exp/exp_expr.h                            |  12 +-
 core/sql/exp/exp_fixup.cpp                         |  65 ++-
 core/sql/exp/exp_function.cpp                      |  53 +-
 core/sql/exp/exp_function.h                        |  35 +-
 core/sql/exp/exp_tuple_desc.cpp                    |  15 +-
 core/sql/generator/GenExpGenerator.cpp             |  14 +-
 core/sql/generator/GenFastTransport.cpp            |  65 ++-
 core/sql/generator/GenItemFunc.cpp                 |  18 +
 core/sql/generator/GenPreCode.cpp                  | 257 ++++-----
 core/sql/generator/GenRelMisc.cpp                  |  14 +
 core/sql/generator/GenRelScan.cpp                  |  12 +-
 core/sql/optimizer/BindItemExpr.cpp                | 115 +++-
 core/sql/optimizer/BindRelExpr.cpp                 |  77 ++-
 core/sql/optimizer/ItemExpr.cpp                    |  23 +-
 core/sql/optimizer/NAColumn.cpp                    |  10 +
 core/sql/optimizer/NATable.cpp                     |  18 +
 core/sql/optimizer/RelExpr.cpp                     |   2 +-
 core/sql/optimizer/RelFastTransport.cpp            |   2 +-
 core/sql/optimizer/RelMisc.h                       |  26 +-
 core/sql/optimizer/SynthType.cpp                   | 260 +++++----
 core/sql/optimizer/ValueDesc.cpp                   |  14 +
 core/sql/parser/ParKeyWords.cpp                    |  10 +-
 core/sql/parser/sqlparser.y                        | 149 +++--
 core/sql/parser/ulexer.cpp                         |   6 +-
 core/sql/regress/charsets/EXPECTED315              |  24 +
 core/sql/regress/charsets/TEST315                  |   3 +
 core/sql/regress/core/EXPECTED038.LINUX            |  10 +-
 core/sql/regress/executor/EXPECTED022.SB           |  16 +-
 core/sql/regress/executor/EXPECTED050              |   4 +-
 core/sql/regress/seabase/EXPECTED002               |   3 +
 core/sql/regress/seabase/EXPECTED004               | 603 +++++++++++++++++++++
 core/sql/regress/seabase/EXPECTED027               |  84 +--
 core/sql/regress/seabase/TEST002                   |   1 +
 core/sql/regress/seabase/TEST003                   |   2 +-
 core/sql/regress/seabase/TEST004                   | 181 +++++++
 core/sql/sqlci/Formatter.cpp                       |  24 +
 core/sql/sqlci/Param.cpp                           |  15 +-
 core/sql/sqlci/SqlCmd.cpp                          |  61 ++-
 core/sql/sqlci/SqlciEnv.cpp                        |   5 +
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp           |   5 +-
 core/sql/sqlcomp/CmpSeabaseDDLutil.cpp             |   4 +
 core/sql/sqlcomp/DefaultConstants.h                |  21 +
 core/sql/sqlcomp/nadefaults.cpp                    |   6 +
 core/sql/ustat/hs_cli.cpp                          |   8 +
 core/sql/ustat/hs_globals.cpp                      |  34 +-
 core/sql/ustat/hs_globals.h                        |   2 +-
 core/sql/ustat/hs_la.cpp                           |   4 +-
 87 files changed, 2987 insertions(+), 705 deletions(-)


[trafodion] 01/03: jira TRAFODION-3157 Add support for BINARY/VARBINARY datatype

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ansharma pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafodion.git

commit c63a78e991fe72157c23b1953934bbb2e69ad48a
Author: Anoop Sharma <an...@esgyn.com>
AuthorDate: Thu Feb 21 20:36:47 2019 +0000

    jira TRAFODION-3157 Add support for BINARY/VARBINARY datatype
    
    Spec attached to jira.
    
    new test regress/seabase/TEST004 added.
---
 .../org/trafodion/jdbc/t4/InterfaceResultSet.java  |  23 +-
 .../org/trafodion/jdbc/t4/InterfaceStatement.java  |  45 +-
 .../trafodion/jdbc/t4/TrafT4CallableStatement.java |   4 +-
 .../java/org/trafodion/jdbc/t4/TrafT4Desc.java     |  16 +-
 .../trafodion/jdbc/t4/TrafT4PreparedStatement.java |  35 +-
 .../org/trafodion/jdbc/t4/TrafT4ResultSet.java     |  24 +-
 .../odbc/src/odbc/nsksrvrcore/sqlinterface.cpp     |  60 +-
 .../main/java/org/trafodion/ci/DatabaseQuery.java  |  65 ++-
 .../src/main/java/org/trafodion/ci/Session.java    |  14 +-
 .../java/org/trafodion/ci/SessionInterface.java    |   1 +
 core/sql/bin/SqlciErrors.txt                       |   4 +-
 core/sql/cli/CliExpExchange.cpp                    |  16 +-
 core/sql/cli/sqlcli.h                              |   9 +
 core/sql/common/BaseTypes.cpp                      |  22 +
 core/sql/common/CharType.cpp                       | 154 +++++-
 core/sql/common/CharType.h                         |  78 ++-
 core/sql/common/ComSSL.h                           |   3 +
 core/sql/common/ComSmallDefs.h                     |   2 +
 core/sql/common/MiscType.cpp                       |   1 +
 core/sql/common/NAType.cpp                         |  20 +-
 core/sql/common/NAType.h                           |   1 +
 core/sql/common/OperTypeEnum.h                     |   6 +-
 core/sql/common/charinfo.cpp                       |   4 +-
 core/sql/common/charinfo.h                         |   3 +-
 core/sql/common/conversionHex.cpp                  |   1 +
 core/sql/common/dfs2rec.h                          |  22 +-
 core/sql/common/sql_charset_strings.h              |   3 +
 core/sql/common/str.cpp                            |  65 ++-
 core/sql/common/str.h                              |   8 +
 core/sql/exp/ExpError.cpp                          | 211 ++++---
 core/sql/exp/ExpError.h                            |   3 +-
 core/sql/exp/ExpErrorEnums.h                       |   1 +
 core/sql/exp/ExpPCodeClauseGen.cpp                 |   2 +-
 core/sql/exp/exp_attrs.cpp                         |  10 +-
 core/sql/exp/exp_clause.cpp                        |  75 +--
 core/sql/exp/exp_clause.h                          |   9 +-
 core/sql/exp/exp_clause_derived.h                  |  17 +-
 core/sql/exp/exp_comp.cpp                          |  18 +-
 core/sql/exp/exp_conv.cpp                          | 232 ++++++--
 core/sql/exp/exp_datetime.cpp                      |   2 +-
 core/sql/exp/exp_expr.h                            |  12 +-
 core/sql/exp/exp_fixup.cpp                         |  65 ++-
 core/sql/exp/exp_function.cpp                      |  53 +-
 core/sql/exp/exp_function.h                        |  35 +-
 core/sql/exp/exp_tuple_desc.cpp                    |  15 +-
 core/sql/generator/GenExpGenerator.cpp             |  14 +-
 core/sql/generator/GenFastTransport.cpp            |  65 ++-
 core/sql/generator/GenItemFunc.cpp                 |  18 +
 core/sql/generator/GenPreCode.cpp                  | 257 ++++-----
 core/sql/generator/GenRelMisc.cpp                  |  14 +
 core/sql/generator/GenRelScan.cpp                  |  12 +-
 core/sql/optimizer/BindItemExpr.cpp                | 115 +++-
 core/sql/optimizer/BindRelExpr.cpp                 |  77 ++-
 core/sql/optimizer/ItemExpr.cpp                    |  23 +-
 core/sql/optimizer/NAColumn.cpp                    |  10 +
 core/sql/optimizer/NATable.cpp                     |  18 +
 core/sql/optimizer/RelExpr.cpp                     |   2 +-
 core/sql/optimizer/RelFastTransport.cpp            |   2 +-
 core/sql/optimizer/RelMisc.h                       |  26 +-
 core/sql/optimizer/SynthType.cpp                   | 260 +++++----
 core/sql/optimizer/ValueDesc.cpp                   |  14 +
 core/sql/parser/ParKeyWords.cpp                    |  10 +-
 core/sql/parser/sqlparser.y                        | 149 +++--
 core/sql/parser/ulexer.cpp                         |   6 +-
 core/sql/regress/charsets/EXPECTED315              |  24 +
 core/sql/regress/charsets/TEST315                  |   3 +
 core/sql/regress/core/EXPECTED038.LINUX            |  10 +-
 core/sql/regress/executor/EXPECTED022.SB           |  16 +-
 core/sql/regress/executor/EXPECTED050              |   4 +-
 core/sql/regress/seabase/EXPECTED002               |   3 +
 core/sql/regress/seabase/EXPECTED004               | 603 +++++++++++++++++++++
 core/sql/regress/seabase/EXPECTED027               |  84 +--
 core/sql/regress/seabase/TEST002                   |   1 +
 core/sql/regress/seabase/TEST003                   |   2 +-
 core/sql/regress/seabase/TEST004                   | 181 +++++++
 core/sql/sqlci/Formatter.cpp                       |  24 +
 core/sql/sqlci/Param.cpp                           |  15 +-
 core/sql/sqlci/SqlCmd.cpp                          |  61 ++-
 core/sql/sqlci/SqlciEnv.cpp                        |   5 +
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp           |   5 +-
 core/sql/sqlcomp/CmpSeabaseDDLutil.cpp             |   4 +
 core/sql/sqlcomp/DefaultConstants.h                |  21 +
 core/sql/sqlcomp/nadefaults.cpp                    |   6 +
 core/sql/ustat/hs_cli.cpp                          |   8 +
 core/sql/ustat/hs_globals.cpp                      |  34 +-
 core/sql/ustat/hs_globals.h                        |   2 +-
 core/sql/ustat/hs_la.cpp                           |   4 +-
 87 files changed, 2976 insertions(+), 705 deletions(-)

diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
index 972c81b..63addbb 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
@@ -118,6 +118,12 @@ class InterfaceResultSet {
         /* BOOLEAN TYPE */
         static final int SQLTYPECODE_BOOLEAN = -701;
 
+        /* BINARY TYPE */
+        static final int SQLTYPECODE_BINARY = 60;
+
+        /* VARBINARY TYPE */
+        static final int SQLTYPECODE_VARBINARY = 61;
+
 	/* Date/Time/TimeStamp related constants */
 	static final int SQLDTCODE_DATE = 1;
 	static final int SQLDTCODE_TIME = 2;
@@ -156,10 +162,11 @@ class InterfaceResultSet {
 		case SQLTYPECODE_BITVAR:
                 case SQLTYPECODE_BLOB:
                 case SQLTYPECODE_CLOB:
+                case SQLTYPECODE_VARBINARY:
 			allocLength = bufferLen + 2;
 			break;
 		case SQLTYPECODE_CHAR:
-
+                case SQLTYPECODE_BINARY:
 			// allocLength = SQLOctetLength - 1; // no null at the end
 			allocLength = SQLOctetLength;
 			if (maxRowLen > 0) {
@@ -231,6 +238,16 @@ class InterfaceResultSet {
 			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
 			retObj = tbuffer;
 			break;
+		case SQLTYPECODE_BINARY:
+			tbuffer = new byte[byteLen];
+			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_VARBINARY:
+			tbuffer = new byte[byteLen];
+			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
+			retObj = tbuffer;
+			break;
 		case SQLTYPECODE_INTERVAL:
 			tbuffer = new byte[byteLen];
 			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
@@ -392,6 +409,7 @@ class InterfaceResultSet {
 
 		switch (desc.sqlDataType_) {
 		case SQLTYPECODE_CHAR:
+                case SQLTYPECODE_BINARY:
 			length = desc.sqlOctetLength_;
 			tbuffer = new byte[length];
 			System.arraycopy(values, noNullValue, tbuffer, 0, length);
@@ -402,6 +420,7 @@ class InterfaceResultSet {
 		case SQLTYPECODE_VARCHAR_LONG:
 		case SQLTYPECODE_BLOB:
 		case SQLTYPECODE_CLOB:
+                case SQLTYPECODE_VARBINARY:
 			boolean shortLength = desc.precision_ < Math.pow(2, 15);
 			int dataOffset = noNullValue + ((shortLength) ? 2 : 4);
 
@@ -686,6 +705,8 @@ class InterfaceResultSet {
 					case SQLTYPECODE_VARCHAR:
 					case SQLTYPECODE_BLOB:
 					case SQLTYPECODE_CLOB:
+                                        case SQLTYPECODE_BINARY:
+                                        case SQLTYPECODE_VARBINARY:
 						byteIndex++;
 						break;
 					}
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
index d9d7c2c..de95efb 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
@@ -510,6 +510,35 @@ class InterfaceStatement {
 	            }
 			}
 			break;
+		case InterfaceResultSet.SQLTYPECODE_BINARY:
+		case InterfaceResultSet.SQLTYPECODE_VARBINARY:
+                    System.out.println("here binary datatype");
+			if (paramValue instanceof InputStream) {
+				InputStream is = (InputStream)paramValue;
+				dataLen = 0;
+				try {
+					int bytesRead = is.read(values, noNullValue + dataOffset, maxLength - dataOffset);
+					dataLen = bytesRead;
+				} catch (IOException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				System.arraycopy(Bytes.createIntBytes(dataLen, this.ic_.getByteSwap()), 0, values, noNullValue, dataOffset);
+			}
+			else {
+				tmpBarray = (byte[])paramValue;
+				dataLen = tmpBarray.length;
+				dataOffset = 4;
+	            if (maxLength > dataLen) {
+	                System.arraycopy(Bytes.createIntBytes(dataLen, this.ic_.getByteSwap()), 0, values, noNullValue, dataOffset);
+	                System.arraycopy(tmpBarray, 0, values, (noNullValue + dataOffset), dataLen);
+	            } else {
+	                throw TrafT4Messages.createSQLException(pstmt.connection_.props_, locale, "23",
+	                        "BINARY input data is longer than the length for column: " + paramNumber);
+	            }
+			}
+			break;
+
 		case InterfaceResultSet.SQLTYPECODE_CLOB:
 			String charSet = "";
 
@@ -763,14 +792,14 @@ class InterfaceStatement {
 		case InterfaceResultSet.SQLTYPECODE_BITVAR:
 		case InterfaceResultSet.SQLTYPECODE_BPINT_UNSIGNED:
 		default:
-			if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
-				Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_, locale, pstmt, paramValue,
-						paramNumber);
-				String temp = "Restricted_Datatype_Error";
-				ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "convertObjectToSQL2", temp, p);
-			}
-
-			throw TrafT4Messages.createSQLException(pstmt.connection_.props_, locale, "restricted_data_type", null);
+                    if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+                        Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_, locale, pstmt, paramValue,
+                                                                   paramNumber);
+                        String temp = "Restricted_Ddatatype_Error" + "datatype = " + dataType;
+                        ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatementtt", "convertObjectToSQL222", temp, p);
+                    }
+                    
+                    throw TrafT4Messages.createSQLException(pstmt.connection_.props_, locale, "restricted_data_type", null);
 		}
 		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
 			Object p[] = T4LoggingUtilities
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4CallableStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4CallableStatement.java
index 8b75f91..c4ade07 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4CallableStatement.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4CallableStatement.java
@@ -317,9 +317,7 @@ public class TrafT4CallableStatement extends TrafT4PreparedStatement implements
 			throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "restricted_data_type",
 					null);
 		}
-		// BINARY, VARBINARY, LONGVARBINARY not supported
-		throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "datatype_not_supported",
-				null);
+		return getBytes(parameterIndex);
 	}
 
 	public byte[] getBytes(String parameterName) throws SQLException {
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Desc.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Desc.java
index f4d8fc0..3ccbe08 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Desc.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Desc.java
@@ -61,6 +61,10 @@ class TrafT4Desc {
 			return "java.sql.Clob";
 		case Types.BLOB:
 			return "java.sql.Blob";
+                case Types.BINARY:
+                    return "java.sql.Binary";
+                case Types.VARBINARY:
+                    return "jave.sql.Varbinary";
 		case Types.BIT:
 		default:
 			return null;
@@ -102,6 +106,10 @@ class TrafT4Desc {
 			return "BLOB";
 		case Types.CLOB:
 			return "CLOB";
+                case Types.BINARY:
+                    return "BINARY";
+                case Types.VARBINARY:
+                    return "VARBINARY";
 		case Types.OTHER:
 			if (sqlDataType_ == SQLTYPECODE_INTERVAL) {
 				return "INTERVAL";
@@ -133,6 +141,8 @@ class TrafT4Desc {
 		case Types.LONGVARCHAR:
 		case Types.CLOB:
 		case Types.BLOB:
+                case Types.BINARY:
+                case Types.VARBINARY:
 			break;
 		default:
                         System.out.println("Data type is " + dataType_);
@@ -335,7 +345,7 @@ class TrafT4Desc {
 			}
 			break;
 		case Types.CHAR:
-
+                case Types.BINARY:
 			// sqlOctetLength_ = maxLen+1;
 			sqlOctetLength_ = maxLen;
 			displaySize_ = maxLen;
@@ -345,6 +355,7 @@ class TrafT4Desc {
 		case Types.LONGVARCHAR:
 		case Types.BLOB:
 		case Types.CLOB:
+                case Types.VARBINARY:
                         boolean shortLength = maxLen < Math.pow(2, 15);
                         int dataOffset = ((shortLength) ? 2 : 4);
 			if (sqlDataType_ == SQLTYPECODE_VARCHAR) {
@@ -457,7 +468,8 @@ class TrafT4Desc {
 	public static final int SQLTYPECODE_CLOB = -603;
 	public static final int SQLTYPECODE_SMALLINT = 5;
 	public static final int SQLTYPECODE_INTEGER = 4;
-
+        public static final int SQLTYPECODE_BINARY = 60;
+        public static final int SQLTYPECODE_VARBINARY = 61;
 	// datetime codes taken from NCS - File ....\....\...\Common\DrvrSrvr.h
 	public static final int SQLDTCODE_YEAR = 4;
 	public static final int SQLDTCODE_YEAR_TO_MONTH = 5;
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
index 0016510..e606828 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
@@ -529,10 +529,8 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 		case Types.LONGVARCHAR:
 		case Types.CLOB:
 		case Types.BLOB:
-		case Types.BINARY:  // At this time Database does not have
-			// this column data type
-		case Types.VARBINARY:  // At this time Database does not
-			// have this column data type //#endif-java
+		case Types.BINARY: 
+		case Types.VARBINARY: 
 		case Types.LONGVARBINARY:  // At this time Database does not
 			// have this column data type
 			byte[] buffer = new byte[length];
@@ -632,10 +630,8 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 		case Types.LONGVARCHAR:
 		case Types.BLOB:
 		case Types.CLOB:
-		case Types.BINARY: // At this time Database does not have
-			// this column data type
-		case Types.VARBINARY:  // At this time Database does not
-			// have this column data type
+		case Types.BINARY:
+		case Types.VARBINARY:
 		case Types.LONGVARBINARY:  // At this time Database does not
 			// have this column data type
 			byte[] buffer2 = new byte[length];
@@ -699,11 +695,13 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 		validateSetInvocation(parameterIndex);
 		dataType = inputDesc_[parameterIndex - 1].dataType_;
 		switch (dataType) {
-        case Types.CHAR:
-        case Types.VARCHAR:
-        case Types.LONGVARCHAR:
+                case Types.CHAR:
+                case Types.VARCHAR:
+                case Types.LONGVARCHAR:
 		case Types.BLOB:
 		case Types.CLOB:
+                case Types.BINARY:
+                case Types.VARBINARY:
             addParamValue(parameterIndex, x.getBytes(1, (int) x.length()));
 		    break;
 
@@ -906,11 +904,13 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 		validateSetInvocation(parameterIndex);
 		dataType = inputDesc_[parameterIndex - 1].dataType_;
 		switch (dataType) {
-        case Types.CHAR:
-        case Types.VARCHAR:
-        case Types.LONGVARCHAR:
-        case Types.BLOB:
-        case Types.CLOB:
+                case Types.CHAR:
+                case Types.VARCHAR:
+                case Types.LONGVARCHAR:
+                case Types.BLOB:
+                case Types.CLOB:
+                case Types.BINARY:
+                case Types.VARBINARY:
             addParamValue(parameterIndex, x.getSubString(1, (int) x.length()));
             break;
 		default:
@@ -1449,6 +1449,7 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 		case Types.DATE:
 		case Types.TIME:
 		case Types.TIMESTAMP:
+                    //case Types.VARBINARY:
 		case Types.OTHER: // This type maps to the Database
 			// INTERVAL
 			addParamValue(parameterIndex, x);
@@ -1456,7 +1457,6 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 
 
 		case Types.ARRAY:
-		case Types.BINARY:
 		case Types.BIT:
 		case Types.DATALINK:
 		case Types.JAVA_OBJECT:
@@ -1482,6 +1482,7 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
 		case Types.LONGVARBINARY:
 		case Types.NULL:
 		case Types.REAL:
+		case Types.BINARY:
 		case Types.VARBINARY:
 			setObject(parameterIndex, x, dataType);
 			break;
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
index ac87638..3b006ba 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
@@ -780,14 +780,14 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
 							"invalid_cast_specification", null);
 				}
 			}
-        case Types.BLOB:
-        case Types.CLOB:
-            x = getLocalString(columnIndex);
-            Blob blob = new TrafT4Blob(connection_, (String) x, null);
-            return blob.getBytes(1, (int)blob.length());
+                case Types.BLOB:
+                case Types.CLOB:
+                    x = getLocalString(columnIndex);
+                    Blob blob = new TrafT4Blob(connection_, (String) x, null);
+                    return blob.getBytes(1, (int)blob.length());
 		default:
-			throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "restricted_data_type",
-					null);
+                    throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "restricted_data_type",
+                                                            null);
 		}
 	}
 
@@ -846,12 +846,12 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
 			} else {
 				return null;
 			}
-        case Types.BLOB:
-        case Types.CLOB:
-            Clob clob = getClob(columnIndex);
-            return clob.getCharacterStream(); 
+                case Types.BLOB:
+                case Types.CLOB:
+                    Clob clob = getClob(columnIndex);
+                    return clob.getCharacterStream(); 
 		default:
-			throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "restricted_data_type",
+                    throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(), "restricted_data_type",
 					null);
 		}
 
diff --git a/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp b/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
index e8b07e4..43ff980 100644
--- a/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
@@ -197,6 +197,36 @@ SQLRETURN SRVR::GetODBCValues(Int32 DataType, Int32 DateTimeCode, Int32 &Length,
 			ODBCCharset = SQLCharset;
 			break;
 
+		case SQLTYPECODE_BINARY:
+			ODBCPrecision = Length;
+			ODBCDataType = SQL_BINARY;
+			SignType = FALSE;
+			totalMemLen += Length;
+			if (!bRWRS)
+				totalMemLen += 1;
+			ODBCCharset = SQLCharset;
+			break;
+		case SQLTYPECODE_VARBINARY:
+			ODBCPrecision = Length;
+			ODBCDataType = SQL_VARBINARY;
+			SignType = FALSE;
+			// Varchar indicator length can 2 or 4 bytes depending on length of the column
+			if (Length > SHRT_MAX)	// 32767
+			{
+				totalMemLen = ((totalMemLen + 4 - 1) >> 2) << 2; 
+				totalMemLen += Length + 4;
+			}
+			else
+			{
+				totalMemLen = ((totalMemLen + 2 - 1) >> 1) << 1; 
+				totalMemLen += Length + 2;
+			}
+
+			if (!bRWRS)
+				totalMemLen += 1;
+			ODBCCharset = SQLCharset;
+			break;
+
                 case SQLTYPECODE_TINYINT:
 			ODBCPrecision = 3;
 			ODBCDataType = SQL_TINYINT;
@@ -714,6 +744,15 @@ SQLRETURN SRVR::SetDataPtr(SQLDESC_ID *pDesc, SQLItemDescList_def *SQLDesc, Int3
 			VarPtr = memPtr + memOffSet;
 			memOffSet += SQLItemDesc->maxLen + 3;
 			break;
+		case SQLTYPECODE_BINARY:
+			VarPtr = memPtr + memOffSet;
+			memOffSet += SQLItemDesc->maxLen + 1;
+			break;
+		case SQLTYPECODE_VARBINARY:
+			memOffSet = ((memOffSet + 2 - 1) >> 1) << 1;
+			VarPtr = memPtr + memOffSet;
+			memOffSet += SQLItemDesc->maxLen + 3;
+			break;
                 case SQLTYPECODE_BOOLEAN:
                 case SQLTYPECODE_TINYINT:
                 case SQLTYPECODE_TINYINT_UNSIGNED:
@@ -1016,6 +1055,7 @@ SQLRETURN SRVR::AllocAssignValueBuffer(
 			{
 			case SQLTYPECODE_CHAR:
 			case SQLTYPECODE_VARCHAR:
+                        case SQLTYPECODE_BINARY:
 				VarPtr = memPtr + memOffSet;  
 				memOffSet += SQLItemDesc->maxLen + 1;
 				AllocLength = SQLItemDesc->maxLen + 1;
@@ -1023,6 +1063,7 @@ SQLRETURN SRVR::AllocAssignValueBuffer(
 			case SQLTYPECODE_VARCHAR_WITH_LENGTH:
 			case SQLTYPECODE_BLOB:
 			case SQLTYPECODE_CLOB:
+                        case SQLTYPECODE_VARBINARY:
 				if( SQLItemDesc->maxLen > SHRT_MAX )
 				{
 					memOffSet = ((memOffSet + 4 - 1) >> 2) << 2;
@@ -2507,6 +2548,7 @@ SQLRETURN SRVR::BuildSQLDesc2withRowsets( SQLDESC_ID          *pDesc
 		{
 		case SQLTYPECODE_CHAR:
 		case SQLTYPECODE_VARCHAR:
+                case SQLTYPECODE_BINARY:
 			VarPtr = memPtr + memOffSet;					
 			memOffSet += SqlDescInfo[i].Length + 1;
 			break;
@@ -2514,6 +2556,7 @@ SQLRETURN SRVR::BuildSQLDesc2withRowsets( SQLDESC_ID          *pDesc
 		case SQLTYPECODE_VARCHAR_LONG:
 		case SQLTYPECODE_BLOB:
 		case SQLTYPECODE_CLOB:
+                case SQLTYPECODE_VARBINARY:
 			if( SqlDescInfo[i].Length > SHRT_MAX )
 			{
 				memOffSet = ((memOffSet + 4 - 1) >> 2) << 2;
@@ -3689,15 +3732,17 @@ SQLRETURN SRVR::FETCH(SRVR_STMT_HDL *pSrvrStmt)
 					case SQLTYPECODE_BITVAR:
 					case SQLTYPECODE_BLOB:
 					case SQLTYPECODE_CLOB:
+                                case SQLTYPECODE_VARBINARY:
 						allocLength = (allocLength>(UInt32)maxRowLen+3)?(UInt32)maxRowLen+3:allocLength;
 						srcDataLength = *(USHORT *)pBytes;
 						srcDataLength = (srcDataLength>(UInt32)maxRowLen)?(UInt32)maxRowLen:srcDataLength;
 						*(USHORT *)pBytes=srcDataLength;
 						break;
-					case SQLTYPECODE_CHAR:
-					case SQLTYPECODE_BIT:
-					case SQLTYPECODE_VARCHAR:
-						allocLength = (allocLength>(UInt32)maxRowLen+1)?(UInt32)maxRowLen+1:allocLength;
+                                case SQLTYPECODE_CHAR:
+                                case SQLTYPECODE_BIT:
+                                case SQLTYPECODE_VARCHAR:
+                                case SQLTYPECODE_BINARY:
+                                  allocLength = (allocLength>(UInt32)maxRowLen+1)?(UInt32)maxRowLen+1:allocLength;
 						break;
 				}
 			}
@@ -3816,6 +3861,7 @@ SQLRETURN SRVR::FETCHPERF(SRVR_STMT_HDL *pSrvrStmt,
 					case SQLTYPECODE_BITVAR:
 					case SQLTYPECODE_BLOB:
 					case SQLTYPECODE_CLOB:
+                                        case SQLTYPECODE_VARBINARY:
 						dataLength = *(USHORT *)pBytes;
 						allocLength = dataLength+3;
 						if (maxRowLen != 0)
@@ -3833,6 +3879,7 @@ SQLRETURN SRVR::FETCHPERF(SRVR_STMT_HDL *pSrvrStmt,
 						break;
 					case SQLTYPECODE_CHAR:
 					case SQLTYPECODE_VARCHAR:
+                                        case SQLTYPECODE_BINARY:
 						allocLength = dataLength+1;	
 						if (maxRowLen != 0)
 							allocLength = (allocLength>(UInt32)maxRowLen+1)?(UInt32)maxRowLen+1:allocLength;
@@ -3855,6 +3902,7 @@ SQLRETURN SRVR::FETCHPERF(SRVR_STMT_HDL *pSrvrStmt,
 					case SQLTYPECODE_BITVAR:
 					case SQLTYPECODE_BLOB:
 					case SQLTYPECODE_CLOB:
+                                        case SQLTYPECODE_VARBINARY:
 						*(outputDataValue->_buffer+lsize + 1 + allocLength - 1) = 0;
 						break;
 				}
@@ -6583,6 +6631,7 @@ SQLRETURN SRVR::FETCHCATALOGPERF(SRVR_STMT_HDL *pSrvrStmt,
 					case SQLTYPECODE_BITVAR:
 					case SQLTYPECODE_BLOB:
 					case SQLTYPECODE_CLOB:
+                                        case SQLTYPECODE_VARBINARY:
 						dataLength = *(USHORT *)pBytes;
 
 						allocLength = dataLength + 3;
@@ -6597,6 +6646,7 @@ SQLRETURN SRVR::FETCHCATALOGPERF(SRVR_STMT_HDL *pSrvrStmt,
 					case SQLTYPECODE_CHAR:
 					case SQLTYPECODE_BIT:
 					case SQLTYPECODE_VARCHAR:
+                                        case SQLTYPECODE_BINARY:
 						allocLength = dataLength + 1;
 						if (maxRowLen != 0)
 							allocLength = (allocLength>(UInt32)maxRowLen+1)?(UInt32)maxRowLen+1:allocLength;
@@ -7062,6 +7112,7 @@ SQLRETURN SRVR::SetIndandVarPtr(SQLDESC_ID *pDesc,
 		{
 		case SQLTYPECODE_CHAR:
 		case SQLTYPECODE_VARCHAR:
+                case SQLTYPECODE_BINARY:
 			VarPtr = memPtr + memOffSet;					
 			memOffSet += SqlDescInfo[i].Length;
 			if (!bRWRS)
@@ -7070,6 +7121,7 @@ SQLRETURN SRVR::SetIndandVarPtr(SQLDESC_ID *pDesc,
 		case SQLTYPECODE_VARCHAR_WITH_LENGTH:
 		case SQLTYPECODE_BLOB:
 		case SQLTYPECODE_CLOB:
+                case SQLTYPECODE_VARBINARY:
 			if( SqlDescInfo[i].Length > SHRT_MAX )
 			{
 				memOffSet = ((memOffSet + 4 - 1) >> 2) << 2; 
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/DatabaseQuery.java b/core/conn/trafci/src/main/java/org/trafodion/ci/DatabaseQuery.java
index b6240d3..61b9816 100644
--- a/core/conn/trafci/src/main/java/org/trafodion/ci/DatabaseQuery.java
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/DatabaseQuery.java
@@ -22,6 +22,7 @@
 package org.trafodion.ci;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.sql.ParameterMetaData;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
@@ -448,6 +449,7 @@ public class DatabaseQuery extends QueryWrapper
       List<String> paramList=null;
       String[] errParams=new String[1];
 
+
       keyToken = parser.getNextKeyToken();
       stmtName = parser.getNextPreparedStmtNameToken();
       if (stmtName == null)
@@ -499,6 +501,12 @@ public class DatabaseQuery extends QueryWrapper
          throw uic;
       }
 
+      ParameterMetaData paramMetaData=null;
+      paramMetaData = pStmt.getParameterMetaData();
+      if (paramMetaData == null)
+          {
+              System.out.println("pmd is null");
+          }
       String sqlQueryStr=((TrafT4Statement)pStmt).getSQL();
       List<String> namedParamList=getParamNames(sqlQueryStr);
       
@@ -572,7 +580,14 @@ public class DatabaseQuery extends QueryWrapper
                         pStmt.setNull(index+1,Types.NULL);
                      else
                      {
-                        pStmt.setObject(index+1,new String(value.toString()));
+                int paramType = paramMetaData.getParameterType(i+1);
+                if ((paramType == Types.BINARY) ||
+                    (paramType == Types.VARBINARY))
+                    {
+                        pStmt.setBytes(index+1, value.getBytes());
+                    }
+                else
+                    pStmt.setObject(index+1,new String(value.toString()));
                      }
                   }
                   
@@ -642,6 +657,7 @@ public class DatabaseQuery extends QueryWrapper
          
       }
 
+
    }
 
    private void prepareCallStmt(String stmtName) throws SQLException, IOException
@@ -1091,6 +1107,13 @@ public class DatabaseQuery extends QueryWrapper
             String paramValue=null;
             int namedParamErrors=0;
 
+            ParameterMetaData paramMetaData=null;
+            paramMetaData = ps.getParameterMetaData();
+            if (paramMetaData == null)
+                {
+                    System.out.println("pmd is null");
+                }
+
             int index=0;
             for (int i=0;i < paramList.size(); i++)
             {
@@ -1115,7 +1138,15 @@ public class DatabaseQuery extends QueryWrapper
                         ps.setNull(index+1,Types.NULL);
                      }else
                      {
-                        ps.setObject(index+1,paramValue);
+                       int paramType = paramMetaData.getParameterType(i+1);
+                       if ((paramType == Types.BINARY) ||
+                           (paramType == Types.VARBINARY))
+                           {
+                               ps.setBytes(index+1, paramValue.getBytes());
+                               //ps.setString(index+1, s);
+                           }
+                       else
+                           ps.setObject(index+1,paramValue);
                      }
                   }catch (NumberFormatException nfe)
                   {
@@ -1364,10 +1395,29 @@ public class DatabaseQuery extends QueryWrapper
      
       for (int i=1;i<=numColumns ;i++)
       {
+         ResultSetMetaData rsmd = rs.getMetaData();
          String value=null;
          try
          {
-            value=rs.getString(i);
+             if ((rsmd.getColumnType(i)==Types.BINARY) ||
+                 (rsmd.getColumnType(i)==Types.VARBINARY))
+                 {
+                     // extract binary data from input and convert to hex.
+                     // This avoids displaying unprintable characters.
+                     value = "";
+                     InputStream is = rs.getBinaryStream(i);
+                     int numBytes = is.available();
+                     for(int ii = 0; ii < numBytes; ii++){
+                         int v = is.read();
+                         String thisByte = Integer.toHexString(v).toUpperCase();
+                         // leading zero pad
+                         if (thisByte.length() == 1)
+                             thisByte = "0" + thisByte;
+                         value += thisByte;
+                     }
+                 }
+             else
+                 value=rs.getString(i);
             if (sessObj.getQuery().getQueryId() == SessionDefaults.SHOW_SERVICE)
                return value;
          } catch (SQLException sqlEx)
@@ -1376,7 +1426,6 @@ public class DatabaseQuery extends QueryWrapper
             //Displaying null in this case.
          }
 
-         ResultSetMetaData rsmd = rs.getMetaData();
          if(value != null && rsmd.getColumnType(i)==Types.TIMESTAMP && value.length() < rsmd.getColumnDisplaySize(i))
          {
           	 value = (value.trim()+"000000").substring(0,rsmd.getColumnDisplaySize(i));
@@ -1457,6 +1506,14 @@ public class DatabaseQuery extends QueryWrapper
              }
          }  
          
+
+         if ((rsmd.getColumnType(i)==Types.BINARY) ||
+             (rsmd.getColumnType(i)==Types.VARBINARY))
+             {
+                 // binary value will be displayed in hex.
+                 colNameSize = 2 * rsmd.getColumnDisplaySize(i);
+             }
+         
          if (colNameSize > rsmd.getColumnDisplaySize(i))
             colSize[i-1]=colNameSize;
          else
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java b/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java
index 3e31e5a..194f2fb 100644
--- a/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java
@@ -1547,7 +1547,7 @@ static {
     		this.sessionRole = this.getUserRoleName();
         	if (this.debugOn)
         		System.out.println("Session getUserRoleName::"  + this.sessionRole);
- 		}    			  
+        }    			  
       } 
       catch (NullPointerException npe) 
       {    	 
@@ -1563,6 +1563,18 @@ static {
       }
    }
    
+  protected void setBinaryCQDs()
+    {
+        try
+            {
+                Statement stmt = this.connObj.createStatement();
+                stmt.executeUpdate("CQD TRAF_BINARY_OUTPUT 'ON'");
+            } catch (Exception se)
+            {
+                System.out.println("error:"+se.getMessage());
+            }
+    }
+
    protected String getUserRoleName()
    {
 
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java b/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java
index 86d62f5..50b8d77 100644
--- a/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java
@@ -170,6 +170,7 @@ public class SessionInterface implements SessionDefaults
          sessObj.setConnObj(getConnection());
          sessObj.setStmtObj(getStatement(sessObj.getConnObj()));
          sessObj.setSessionValues();
+         sessObj.setBinaryCQDs();
          this.getDriverVersion();     
       }
             
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index a2a7e17..dd60bb7 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -1548,9 +1548,9 @@ $1~String1 --------------------------------
 8403 22011 99999 BEGINNER MINOR LOGONLY The length argument of function SUBSTRING cannot be less than zero or greater than source string length.
 8404 22027 99999 BEGINNER MINOR LOGONLY The trim character argument of function TRIM must be one character in length.
 8405 22008 99999 BEGINNER MINOR LOGONLY The operand of function CONVERTTIMESTAMP is out of range.
-8406 ZZZZZ 99999 UUUUUUUU UUUUU UUUUUUU --- unused as of 03/30/04 ---
+8406 22001 99999 BEGINNER MINOR LOGONLY An overflow occurred during conversion of source to target datatype. 
 8407 22008 99999 BEGINNER MINOR LOGONLY The operand of function JULIANTIMESTAMP is out of range.
-8408 ZZZZZ 99999 UUUUUUUU UUUUU UUUUUUU --- unused as of 03/30/04 ---
+8408 22001 99999 BEGINNER MINOR LOGONLY An error occurred during the evaluation of a conversion expression. Details:$0~string0
 8409 22019 99999 BEGINNER MINOR LOGONLY The escape character argument of a LIKE predicate must be one character in length.
 8410 22025 99999 BEGINNER MINOR LOGONLY An escape character in a LIKE pattern must be followed by another escape character, an underscore, or a percent character.
 8411 22003 99999 BEGINNER MINOR LOGONLY A numeric overflow occurred during an arithmetic computation or data conversion.$0~string0
diff --git a/core/sql/cli/CliExpExchange.cpp b/core/sql/cli/CliExpExchange.cpp
index bcef82d..c88da10 100644
--- a/core/sql/cli/CliExpExchange.cpp
+++ b/core/sql/cli/CliExpExchange.cpp
@@ -502,8 +502,8 @@ Descriptor::BulkMoveStatus Descriptor::checkBulkMoveStatusV1(
 	   ((NOT DFS2REC::isAnyCharacter(op->getDatatype())) &&
 	    (descItem.scale != op->getScale())) || 
 	   (descItem.length != op->getLength())        ||
-	   ((descItem.datatype >= REC_MIN_BINARY) &&
-	    (descItem.datatype <= REC_MAX_BINARY) &&
+	   ((descItem.datatype >= REC_MIN_BINARY_NUMERIC) &&
+	    (descItem.datatype <= REC_MAX_BINARY_NUMERIC) &&
 	    (((isInputDesc) &&
 	      (descItem.precision > 0)) ||
 	     ((NOT isInputDesc) &&
@@ -605,8 +605,8 @@ Descriptor::BulkMoveStatus Descriptor::checkBulkMoveStatusV2(
 	//   is greater than zero, and less than operand's precision or op's 
 	//   precision is zero.
          ||
-	   ((descItem.datatype >= REC_MIN_BINARY) &&
-            (descItem.datatype <= REC_MAX_BINARY) &&
+	   ((descItem.datatype >= REC_MIN_BINARY_NUMERIC) &&
+            (descItem.datatype <= REC_MAX_BINARY_NUMERIC) &&
 	    (((isInputDesc) &&
 	      (NOT isRWRS) &&
 	      (descItem.precision > 0)) ||
@@ -2919,8 +2919,8 @@ InputOutputExpr::inputSingleRowValue(atp_struct *atp,
 		source = intermediate;
 	      } // sourceType == REC_BYTE_V_ANSI
 	    
-	    if ((sourceType >= REC_MIN_BINARY) &&
-		(sourceType <= REC_MAX_BINARY) &&
+	    if ((sourceType >= REC_MIN_BINARY_NUMERIC) &&
+		(sourceType <= REC_MAX_BINARY_NUMERIC) &&
 		(sourceType == operand->getDatatype()) &&
 		(sourcePrecision > 0) &&
 		(sourcePrecision == operand->getPrecision()))
@@ -4016,8 +4016,8 @@ InputOutputExpr::inputValues(atp_struct *atp,
 	      } // sourceType == REC_BYTE_V_ANSI
 	    
 	    if ((sourcePrecision > 0) &&
-		((sourceType >= REC_MIN_BINARY) &&
-                 (sourceType <= REC_MAX_BINARY) &&
+		((sourceType >= REC_MIN_BINARY_NUMERIC) &&
+                 (sourceType <= REC_MAX_BINARY_NUMERIC) &&
                  (sourceType == operand->getDatatype()) &&
                  (sourcePrecision == operand->getPrecision()) ||
                  (DFS2REC::isAnyCharacter(sourceType) && !suppressCharLimitCheck())))
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index 8f8dd42..656f611 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -237,6 +237,7 @@ enum PARAMETER_MODE {
 #define SQLCHARSETSTRING_BIG5              "BIG5"
 #define SQLCHARSETSTRING_UCS2              SQLCHARSETSTRING_UNICODE
 #define SQLCHARSETSTRING_ISO_MAPPING       "ISO_MAPPING"
+#define SQLCHARSETSTRING_BINARY            "BINARY"
 #endif /* SQLCHARSETSTRING_DEFINED */
 
 /* specifies the supported character sets (for numeric value version of 
@@ -259,6 +260,7 @@ enum SQLCHARSET_CODE {
   SQLCHARSETCODE_MB_KSC5601     = 16,
   SQLCHARSETCODE_GB2312         = 17,
   SQLCHARSETCODE_GBK            = 18,
+  SQLCHARSETCODE_BINARY         = 19,
 
   /* specifies that the user input string is in the same charset that is
      set as the value of the ISO_MAPPING default in the defaults table.
@@ -401,6 +403,7 @@ enum SQLTYPE_CODE {
 
     /* LONG VARCHAR/ODBC CHARACTER VARYING */
     SQLTYPECODE_VARCHAR_LONG  = -1,		/* ## NEGATIVE??? */
+
     /* BLOB TYPE */
     SQLTYPECODE_BLOB  = -602,
     SQLTYPECODE_CLOB  = -603,
@@ -408,6 +411,12 @@ enum SQLTYPE_CODE {
     /* BOOLEAN TYPE */
     SQLTYPECODE_BOOLEAN = -701,
 
+    /* BINARY TYPE */
+    SQLTYPECODE_BINARY = 60,
+
+    /* VARBINARY TYPE */
+    SQLTYPECODE_VARBINARY = 61,
+
     /* no ANSI value 13 */
 
     /* BIT */
diff --git a/core/sql/common/BaseTypes.cpp b/core/sql/common/BaseTypes.cpp
index 91ac01d..222c25c 100644
--- a/core/sql/common/BaseTypes.cpp
+++ b/core/sql/common/BaseTypes.cpp
@@ -633,6 +633,14 @@ short convertTypeToText_basic(char * text,	   // OUTPUT
      str_sprintf(text, "BOOLEAN");
      break;
 
+   case REC_BINARY_STRING:
+     str_sprintf(text, "BINARY(%d)", length);
+     break;
+
+   case REC_VARBINARY_STRING:
+     str_sprintf(text, "VARBINARY(%d)", length);
+     break;
+
     default:
       str_sprintf(text, "**ERROR (unknown type %d)", fs_datatype);
       return -1; // error case
@@ -767,6 +775,14 @@ Lng32 getAnsiTypeFromFSType(Lng32 datatype)
      numeric_value = SQLTYPECODE_BOOLEAN;
      break;
 
+   case REC_BINARY_STRING:
+     numeric_value = SQLTYPECODE_BINARY;
+     break;
+
+   case REC_VARBINARY_STRING:
+     numeric_value = SQLTYPECODE_VARBINARY;
+     break;
+
    case REC_INT_YEAR:
    case REC_INT_MONTH:
    case REC_INT_YEAR_MONTH:
@@ -888,6 +904,12 @@ const char * getAnsiTypeStrFromFSType(Lng32 datatype)
      return COM_BOOLEAN_SDT_LIT;
      break;
 
+   case REC_BINARY_STRING:
+     return COM_CHAR_BINARY_SDT_LIT;
+
+   case REC_VARBINARY_STRING:
+     return COM_CHAR_VARBINARY_SDT_LIT;
+
    case REC_INT_YEAR:
    case REC_INT_MONTH:
    case REC_INT_YEAR_MONTH:
diff --git a/core/sql/common/CharType.cpp b/core/sql/common/CharType.cpp
index cc6c18a..713581b 100644
--- a/core/sql/common/CharType.cpp
+++ b/core/sql/common/CharType.cpp
@@ -165,7 +165,7 @@ NAString CharType::getCharSetName() const
 
 NAString CharType::getCharSetAsPrefix(CharInfo::CharSet cs)
 {
-  return NAString(SQLCHARSET_INTRODUCER_IN_LITERAL) + CharInfo::getCharSetName(cs);
+    return NAString(SQLCHARSET_INTRODUCER_IN_LITERAL) + CharInfo::getCharSetName(cs);
 }
 
 NAString CharType::getCharSetAsPrefix() const
@@ -501,10 +501,19 @@ const NAType* CharType::synthesizeType(NATypeSynthRuleEnum synthRule,
 
   CharLenInfo res_CharLenInfo(res_len_in_Chars,
                               res_nominalSize);
-                              
+      
   if (DFS2REC::isAnyVarChar(op1.getFSDatatype()) OR
-      DFS2REC::isAnyVarChar(op2.getFSDatatype()) OR
-      makeTypeVarchar)
+      DFS2REC::isAnyVarChar(op2.getFSDatatype()))
+    makeTypeVarchar = TRUE;
+  
+  NABoolean makeTypeBinary = FALSE;
+  if (DFS2REC::isBinaryString(op1.getFSDatatype()) OR
+      DFS2REC::isBinaryString(op2.getFSDatatype()))
+    makeTypeBinary = TRUE;
+
+  if (makeTypeBinary)
+    return new(h) SQLBinaryString(h, res_nominalSize, null, makeTypeVarchar);
+  else if (makeTypeVarchar)
     return new(h) SQLVarChar(h, res_CharLenInfo, null, upshift, caseinsensitive,
 			     op1.getCharSet(), co, ce);
   else
@@ -675,14 +684,6 @@ Lng32 CharType::getMaxSingleCharacterValue() const
 
 
   switch (getCharSet()) {
-#ifdef IS_MP
-    case CharInfo::KANJI_MP:
-    case CharInfo::KSC5601_MP:
-      return 0xffff;  // return max NAWchar as KANJI/KSC's code points are not
-                      // checked
-      break;
-#endif
-
     case CharInfo::ISO88591:
       switch (getCollation()) {
 	case CharInfo::DefaultCollation: return UCHAR_MAX;
@@ -700,6 +701,10 @@ Lng32 CharType::getMaxSingleCharacterValue() const
       return UCHAR_MAX;
       break;
 
+    case CharInfo::BINARY:
+      return UCHAR_MAX;
+      break;
+
 #if 0 /* SJIS NOT SUPPORTED YET */
     case CharInfo::SJIS:
       if (getEncodingCharSet() == CharInfo::SJIS)
@@ -803,10 +808,25 @@ NABoolean CharType::createSQLLiteral(const char * buf,
       valPtr += getVarLenHdrSize();
     }
 
+  if (sourceCS == CharInfo::BINARY)
+    *resultLiteral += " X";
+
   *resultLiteral += "'";
 
   switch (sourceCS)
     {
+    case CharInfo::BINARY:
+      {
+        Lng32 hexlen = str_computeHexAsciiLen(valLen);
+        
+        tempBuf = new(h) char[hexlen+1];
+        Lng32 rc = str_convertToHexAscii(valPtr, valLen,
+                                         tempBuf, hexlen+1,
+                                         TRUE /*append null*/);
+        *resultLiteral += tempBuf;
+      }
+      break;
+
     case CharInfo::UTF8:
       *resultLiteral += NAString(valPtr, valLen);
       break;
@@ -1160,6 +1180,7 @@ void CharType::minMaxRepresentableValue(void* bufPtr,
   {
   case CharInfo::ISO88591:
   case CharInfo::SJIS:
+  case CharInfo::BINARY:
     if (isMax)
       minmax_char = (char)getMaxSingleCharacterValue();
     else
@@ -1623,3 +1644,112 @@ const NAType* SQLClob::synthesizeType(NATypeSynthRuleEnum synthRule,
   return NULL;
 }
 
+// ----------------------------------------------------------------------
+// class SQLBinaryString
+// ----------------------------------------------------------------------
+SQLBinaryString::SQLBinaryString(NAMemory *h,
+                                 Lng32 maxLen,
+                                 NABoolean allowSQLnull,
+                                 NABoolean varLenFlag
+		 )
+     : CharType(h, varLenFlag ? LiteralVARCHAR : LiteralCHAR,
+		maxLen, 1,
+		FALSE, allowSQLnull, FALSE, FALSE,
+		varLenFlag, 
+                CharInfo::BINARY,
+                CharInfo::DefaultCollation, CharInfo::COERCIBLE,
+		CharInfo::UnknownCharSet)
+{}
+
+//  encoding of the max char value
+double SQLBinaryString::getMaxValue() const
+{
+  EncodedValue dummyVal(0.0);
+
+  double encodedval = dummyVal.minMaxValue(this, FALSE);
+
+  return encodedval;
+}
+
+//  encoding of the min char value
+double SQLBinaryString::getMinValue() const
+{
+  EncodedValue dummyVal(0.0);
+
+  double encodedval = dummyVal.minMaxValue(this, TRUE);
+
+  return encodedval;
+}
+
+NABoolean SQLBinaryString::isCompatible(const NAType& other, UInt32 * flags) const
+{
+  return NAType::isCompatible(other, flags);
+}
+
+NAString SQLBinaryString::getTypeSQLname(NABoolean terse) const
+{
+  char  lenbuf[30];
+  char* sp = lenbuf;
+
+  NAString rName(isVaryingLen() ? "VARBINARY" : "BINARY");
+
+  sprintf(sp, "(%d) ", getStrCharLimit());
+  rName += sp;
+
+  if (! terse)
+    getTypeSQLnull(rName, terse);
+
+  return rName;
+}
+
+// -----------------------------------------------------------------------
+// Type synthesis for binary operators
+// -----------------------------------------------------------------------
+const NAType* SQLBinaryString::synthesizeType(NATypeSynthRuleEnum synthRule,
+                                            const NAType& operand1,
+                                            const NAType& operand2,
+                                            CollHeap* h,
+                                            UInt32 *flags) const
+{
+  //
+  // If the second operand's type synthesis rules have higher precedence than
+  // this operand's rules, use the second operand's rules.
+  //
+  if (operand2.getSynthesisPrecedence() > getSynthesisPrecedence())
+    return operand2.synthesizeType(synthRule, operand1, operand2, h, flags);
+ 
+  Lng32 res_nominalSize = 0;
+  NABoolean makeTypeVarchar = FALSE;
+
+  switch (synthRule) {
+  case SYNTH_RULE_UNION:
+    res_nominalSize = MAXOF( operand1.getNominalSize(), operand2.getNominalSize());
+    break;
+  case SYNTH_RULE_CONCAT:
+    res_nominalSize = operand1.getNominalSize() + operand2.getNominalSize();
+    break;
+  default:
+    return NULL;
+  }
+
+  NABoolean null = operand1.supportsSQLnull() OR operand2.supportsSQLnull();
+  if (DFS2REC::isAnyVarChar(operand1.getFSDatatype()) OR
+      DFS2REC::isAnyVarChar(operand2.getFSDatatype()))
+    makeTypeVarchar = TRUE;
+  
+  return new(h) SQLBinaryString(h, res_nominalSize, null, makeTypeVarchar);
+} // synthesizeType()
+
+void SQLBinaryString::minRepresentableValue(void* bufPtr, Lng32* bufLen,
+                                            NAString ** stringLiteral,
+                                            CollHeap* h) const
+{
+  minMaxRepresentableValue(bufPtr, bufLen, stringLiteral, FALSE, h);
+}
+
+void SQLBinaryString::maxRepresentableValue(void* bufPtr, Lng32* bufLen,
+                                            NAString ** stringLiteral,
+                                            CollHeap* h) const
+{
+  minMaxRepresentableValue(bufPtr, bufLen, stringLiteral, TRUE, h);
+}
diff --git a/core/sql/common/CharType.h b/core/sql/common/CharType.h
index 61eee56..c953f77 100644
--- a/core/sql/common/CharType.h
+++ b/core/sql/common/CharType.h
@@ -420,7 +420,6 @@ CharInfo::CharSet encodingCharSet_;
 }; // class CharType
 
 
-
 // ***********************************************************************
 //
 //  SQLChar : SQL CHARACTER
@@ -455,9 +454,9 @@ public:
 	   CharInfo::CharSet encoding	= CharInfo::UnknownCharSet
           );
 //copy ctor
-	SQLChar (const SQLChar & sqlChar,
-		NAMemory * heap):CharType(sqlChar,heap)
-	{}
+  SQLChar (const SQLChar & sqlChar,
+           NAMemory * heap):CharType(sqlChar,heap)
+  {}
 short getFSDatatype() const;
 
 // ---------------------------------------------------------------------
@@ -870,5 +869,76 @@ private:
 
 }; // class SQLClob
 
+// ***********************************************************************
+//
+//  SQLBinaryString : SQL BINARY string
+//
+// ***********************************************************************
+class SQLBinaryString : public CharType
+{
+public:
+// ---------------------------------------------------------------------
+// Constructor functions 
+// ---------------------------------------------------------------------
+  SQLBinaryString (NAMemory *h,
+                   Lng32 maxLength, 
+                   NABoolean allowSQLnull	= TRUE,
+                   NABoolean varLenFlag	= FALSE
+                   );
+  SQLBinaryString (const SQLBinaryString & sqlCharBinary,
+                   NAMemory * heap):CharType(sqlCharBinary,heap)
+  {}
+  
+  short getFSDatatype() const
+  { return (isVaryingLen() ? REC_VARBINARY_STRING : REC_BINARY_STRING); }
+
+  virtual NAString getTypeSQLname(NABoolean terse = FALSE) const;
+
+  virtual NAType::SynthesisPrecedence getSynthesisPrecedence() const
+  {
+    return SYNTH_PREC_BINARY;
+  }
+
+  // get the encoding of the max char value
+  double getMaxValue() const;
+  
+  // get the encoding of the min char value
+  double getMinValue() const;
+  
+  virtual double encode (void*) const
+  {return 0;}
+
+  // ---------------------------------------------------------------------
+  // Methods that return the binary form of the minimum and the maximum
+  // representable values.
+  // ---------------------------------------------------------------------
+  virtual void minRepresentableValue(void*, Lng32*, 
+				     NAString** stringLiteral = NULL,
+				     CollHeap* h=0) const;
+  virtual void maxRepresentableValue(void*, Lng32*, 
+				     NAString** stringLiteral = NULL,
+				     CollHeap* h=0) const;
+  
+  virtual NABoolean isCompatible(const NAType& other, UInt32 * flags) const;
+  
+  virtual NABoolean isComparable(const NAType &otherNA,
+				 ItemExpr *parentOp,
+				 Int32 emitErr,
+                                 UInt32 * flags) const;
+
+  const NAType* synthesizeType(NATypeSynthRuleEnum synthRule,
+                               const NAType& operand1,
+                               const NAType& operand2,
+                               CollHeap* h,
+                               UInt32 *flags) const;
+
+  // ---------------------------------------------------------------------
+  // A virtual function to return a copy of the type.
+  // ---------------------------------------------------------------------
+  virtual NAType *newCopy(NAMemory * h=0) const 
+  { return new(h) SQLBinaryString(*this,h); }
+  
+private:
+}; // class SQLBinaryString
 
 #endif /* CHARTYPE_H */
diff --git a/core/sql/common/ComSSL.h b/core/sql/common/ComSSL.h
index 54239be..954c73a 100644
--- a/core/sql/common/ComSSL.h
+++ b/core/sql/common/ComSSL.h
@@ -24,6 +24,7 @@
 #include <openssl/err.h>
 
 #include <string.h>
+#include <stdint.h>
 
 #include "Platform.h"
 /**
@@ -57,4 +58,6 @@ void aes_create_key(const unsigned char * input,
                     Lng32 input_len,
                     unsigned char * key,
                     Int32 aes_mode);
+
 #endif
+
diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h
index b288e82..5b73636 100644
--- a/core/sql/common/ComSmallDefs.h
+++ b/core/sql/common/ComSmallDefs.h
@@ -1674,6 +1674,8 @@ enum ComSQLDataType { COM_UNKNOWN_SDT
 #define COM_BLOB_SDT_LIT                       "BLOB              "
 #define COM_CLOB_SDT_LIT                       "CLOB              "
 #define COM_BOOLEAN_SDT_LIT                    "BOOLEAN           "
+#define COM_CHAR_BINARY_SDT_LIT                     "BINARY            "
+#define COM_CHAR_VARBINARY_SDT_LIT                  "VARBINARY         "
 
 enum ComViewCheckOption { COM_UNKNOWN_CHECK_OPTION
                         , COM_CASCADE_CHECK_OPTION
diff --git a/core/sql/common/MiscType.cpp b/core/sql/common/MiscType.cpp
index 0e00472..ae391e6 100644
--- a/core/sql/common/MiscType.cpp
+++ b/core/sql/common/MiscType.cpp
@@ -509,3 +509,4 @@ NABoolean SQLUnknown::errorsCanOccur(const NAType& target, NABoolean lax) const
 {
   return TRUE;
 }
+
diff --git a/core/sql/common/NAType.cpp b/core/sql/common/NAType.cpp
index ab5b4fa..02c6f62 100644
--- a/core/sql/common/NAType.cpp
+++ b/core/sql/common/NAType.cpp
@@ -634,6 +634,11 @@ Lng32 NAType::getDisplayLength(Lng32 datatype,
       d_len = SQL_BOOLEAN_DISPLAY_SIZE;
       break;
 
+    case REC_BINARY_STRING:
+    case REC_VARBINARY_STRING:
+      d_len = length;
+      break;
+
     default:
       d_len = length;
       break;
@@ -706,7 +711,7 @@ short NAType::getMyTypeAsHiveText(NAString * outputStr/*out*/) const
         SQLVarChar * ct = (SQLVarChar*)this;
         if (ct->wasHiveString())
           *outputStr = "string";
-        else
+        else if (DFS2REC::isCharacterString(fs_datatype))
           {
             char buf[20];
             // Hive doesn't have the "n bytes" notation,
@@ -717,6 +722,8 @@ short NAType::getMyTypeAsHiveText(NAString * outputStr/*out*/) const
             *outputStr += buf;
             *outputStr += ")";
           }
+        else
+          *outputStr = "binary";
       }
       break;
 
@@ -998,6 +1005,17 @@ NAType* NAType::getNATypeForHive(const char* hiveType, NAMemory* heap)
       return nat;
     }
   
+  if ( !strcmp(hiveType, "binary"))
+    {
+      Int32 len = CmpCommon::getDefaultLong(HIVE_MAX_BINARY_LENGTH);
+      NAType * nat = NULL;
+      if (CmpCommon::getDefault(TRAF_BINARY_SUPPORT) == DF_OFF)
+        nat = new (heap) SQLVarChar(heap, len);
+      else
+        nat = new (heap) SQLBinaryString(heap, len, TRUE, TRUE);
+      return nat;
+    }
+
   if ( !strcmp(hiveType, "float"))
     return new (heap) SQLReal(heap, TRUE /* allow NULL*/);
 
diff --git a/core/sql/common/NAType.h b/core/sql/common/NAType.h
index 3fafd94..6957488 100644
--- a/core/sql/common/NAType.h
+++ b/core/sql/common/NAType.h
@@ -457,6 +457,7 @@ public:
   , SYNTH_PREC_FLOAT
   , SYNTH_PREC_INTERVAL		// > Numeric (ANSI 6.15, multiplication)
   , SYNTH_PREC_DATETIME		// > Interval (ANSI 6.14, addition)
+  , SYNTH_PREC_BINARY
   };
 
   virtual NAType::SynthesisPrecedence getSynthesisPrecedence() const
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index fd3776c..5ec7a0c 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -625,7 +625,11 @@ enum OperatorTypeEnum {
                         ITM_MONTHS_BETWEEN     = 2342,
                         ITM_YEARWEEK           = 2343,
                         ITM_YEARWEEKD          = 2344,
-                        ITM_TO_TIMESTAMP          = 2345,
+                        ITM_TO_TIMESTAMP       = 2345,
+                        ITM_TO_BINARY          = 2346,
+                        ITM_ENCODE_BASE64      = 2347,
+                        ITM_DECODE_BASE64      = 2348,
+                        ITM_TO_CHAR            = 2349,
 
                         // misc. functions
                         ITM_NARROW = 2350, // a variant on Cast used for key building
diff --git a/core/sql/common/charinfo.cpp b/core/sql/common/charinfo.cpp
index 547e09c..fc17b70 100644
--- a/core/sql/common/charinfo.cpp
+++ b/core/sql/common/charinfo.cpp
@@ -102,6 +102,7 @@ static const struct mapCS mapCSArray[] = {
   { /*16*/ CharInfo::KSC5601,        SQLCHARSETSTRING_MB_KSC5601, 10, TRUE,    FALSE,  1,    2, "?" },
   { /*17*/ CharInfo::GB2312,         SQLCHARSETSTRING_GB2312,      6, TRUE,    FALSE,  1,    2, "?" },
   { /*18*/ CharInfo::GBK,            SQLCHARSETSTRING_GBK,         3, TRUE,    FALSE,  1,    2, "?" },
+  { /*19*/ CharInfo::BINARY,         SQLCHARSETSTRING_BINARY,      6, TRUE,    TRUE,   1,    1, "?" },
 };
 
 #define SIZEOF_CS  (sizeof(mapCSArray)/sizeof(mapCS))
@@ -193,7 +194,8 @@ NABoolean CharInfo::isCharSetFullySupported(CharSet cs)
 NABoolean CharInfo::isHexFormatSupported(CharSet cs) {
   return ( (cs == CharInfo::ISO88591) || (cs == CharInfo::UNICODE) || 
            (cs == CharInfo::UTF8) ||
-           (is_NCHAR_MP(cs)) 
+           (is_NCHAR_MP(cs)) ||
+           (cs == CharInfo::BINARY)
          );
 }
 
diff --git a/core/sql/common/charinfo.h b/core/sql/common/charinfo.h
index 0864a4e..8495469 100644
--- a/core/sql/common/charinfo.h
+++ b/core/sql/common/charinfo.h
@@ -128,13 +128,14 @@ public:
      KSC5601  = SQLCHARSETCODE_MB_KSC5601, // 16
      GB2312   = SQLCHARSETCODE_GB2312,     // 17
      GBK      = SQLCHARSETCODE_GBK,        // 18
+     BINARY   = 19,                        // 19
      //
      // synonyms
      SQL_TEXT	    = UNICODE,
      UCS2	    = UNICODE,
      DefaultCharSet = ISO88591,
 
-     CHARSET_MAX    = 18,
+     CHARSET_MAX    = 19,
 
      // for internal use only
      ISO_MAPPING_CODE = SQLCHARSETCODE_ISO_MAPPING // 9999
diff --git a/core/sql/common/conversionHex.cpp b/core/sql/common/conversionHex.cpp
index f1d2564..d1896d0 100644
--- a/core/sql/common/conversionHex.cpp
+++ b/core/sql/common/conversionHex.cpp
@@ -206,6 +206,7 @@ hex_conversion_code verifyAndConvertHex(const NAWchar *str, Int32 len, NAWchar q
     case CharInfo::KSC5601_MP:
     case CharInfo::ISO88591:
     case CharInfo::UTF8:
+    case CharInfo::BINARY:
       {
         Int32   StrLength = (Int32)(tmpStr->length());
         result = convHexToChar(tmpStr->data(), StrLength, cs, heap);
diff --git a/core/sql/common/dfs2rec.h b/core/sql/common/dfs2rec.h
index b87c960..7759db3 100644
--- a/core/sql/common/dfs2rec.h
+++ b/core/sql/common/dfs2rec.h
@@ -51,7 +51,7 @@
 // numeric types
 #define REC_MIN_NUMERIC 128
 
-#define REC_MIN_BINARY 130
+#define REC_MIN_BINARY_NUMERIC 130
 #define REC_BIN16_SIGNED 130
 #define REC_BIN16_UNSIGNED 131
 #define REC_BIN32_SIGNED 132
@@ -61,7 +61,7 @@
 #define REC_BIN8_SIGNED 136     // tinyint signed
 #define REC_BIN8_UNSIGNED 137   // tinyint unsigned
 #define REC_BIN64_UNSIGNED 138
-#define REC_MAX_BINARY 138
+#define REC_MAX_BINARY_NUMERIC 138
 
 #define REC_MIN_FLOAT   142
 #define REC_IEEE_FLOAT32 142
@@ -116,6 +116,7 @@
   #define REC_BYTE_F_DOUBLE              2      // MP same name
   #define REC_NCHAR_F_UNICODE            2	// [MXsynonym]
 
+  #define REC_BINARY_STRING              9
   #define REC_MAX_F_CHAR_H              47      // MP same name
 
   #define REC_MIN_V_CHAR_H              64      // MP same name
@@ -124,6 +125,7 @@
   #define REC_BYTE_V_DOUBLE             66      // MP same name
   #define REC_NCHAR_V_UNICODE           66	// [MXsynonym]
 
+  #define REC_VARBINARY_STRING          69
   #define REC_BYTE_V_ASCII_LONG         70      // MX only: ODBC LONG VARCHAR
 
 // These types do not exist in MP, *and* they do not exist as persistent
@@ -160,7 +162,7 @@
 
   #define REC_BOOLEAN                  170
 
-  #define REC_DATETIME                  192
+  #define REC_DATETIME                 192
 
 // The ANSI defines are also in cli/SqlCLI.h (since they are externalized)
 // and must be the same as those defined there.  We don't source that file
@@ -279,7 +281,7 @@ public:
 
   // REC_BYTE_V_ANSI, REC_BYTE_V_ANSI_DOUBLE
   static Int32 isANSIVarChar(Int32 d)
-  { return REC_MIN_V_N_CHAR_H <= d	&& d <= REC_MAX_V_N_CHAR_H; }
+  { return ((REC_MIN_V_N_CHAR_H <= d	&& d <= REC_MAX_V_N_CHAR_H)); }
 
   static Int32 isAnyVarChar(Int32 d)
   { return ((REC_MIN_V_CHAR_H <= d	&& d <= REC_MAX_V_CHAR_H) ||
@@ -330,8 +332,8 @@ public:
   static Int32 isFloat(Int32 d)
   { return REC_MIN_FLOAT <= d         && d <= REC_MAX_FLOAT; }
 
-  static Int32 isBinary(Int32 d)
-  { return (REC_MIN_BINARY <= d) && (d <= REC_MAX_BINARY); }
+  static Int32 isBinaryNumeric(Int32 d)
+  { return (REC_MIN_BINARY_NUMERIC <= d) && (d <= REC_MAX_BINARY_NUMERIC); }
 
   static Int32 isNumeric(Int32 d)
   { return (REC_MIN_NUMERIC <= d) && (d <= REC_MAX_NUMERIC); }
@@ -344,6 +346,14 @@ public:
 
   static Int32 isTinyint(Int32 d)
   {return ((d == REC_BIN8_SIGNED) || (d == REC_BIN8_UNSIGNED)); }
+
+  static Int32 isBinaryString(Int32 d)
+  {return ((d == REC_BINARY_STRING) || (d == REC_VARBINARY_STRING)); }
+
+  static Int32 isCharacterString(Int32 d)
+  { return ((REC_MIN_CHARACTER <= d && d <= REC_MAX_CHARACTER) &&
+            (! isBinaryString(d))); }
+
 };
 
 
diff --git a/core/sql/common/sql_charset_strings.h b/core/sql/common/sql_charset_strings.h
index 8a45228..c2b9799 100644
--- a/core/sql/common/sql_charset_strings.h
+++ b/core/sql/common/sql_charset_strings.h
@@ -65,6 +65,9 @@
 
   #define SQLCHARSETSTRING_UCS2            SQLCHARSETSTRING_UNICODE
   #define SQLCHARSETSTRING_ISO_MAPPING     "ISO_MAPPING"
+
+  #define SQLCHARSETSTRING_BINARY          "BINARY"
+
 #endif // SQLCHARSETSTRING_DEFINED
 
 #define SQLCHARSETSTRING_ISO88592	   "ISO88592"
diff --git a/core/sql/common/str.cpp b/core/sql/common/str.cpp
index b2b4653..4f92556 100644
--- a/core/sql/common/str.cpp
+++ b/core/sql/common/str.cpp
@@ -45,6 +45,11 @@
 
 #include <stdarg.h>
 
+#include <openssl/evp.h>
+#include <openssl/err.h>
+#include <openssl/bio.h>
+#include <openssl/evp.h>
+
 #include "ComResWords.h"
 
 /*
@@ -670,6 +675,58 @@ Lng32 str_decode(void *tgt, Lng32 tgtMaxLen, const char *src, Lng32 srcLen)
   return length;
 }
 
+Lng32 str_encoded_len_base64(Lng32 len)
+{
+  return ((4 * len / 3) + 3) & ~3;
+}
+
+Lng32 str_decoded_len_base64(Lng32 len)
+{
+  return (len * 3) / 4;
+}
+
+Lng32 str_encode_base64(const unsigned char* in, Lng32 in_len,
+                        char *out, Lng32 out_len)
+{
+  Lng32 ret = 0;
+
+  BIO *b64 = BIO_new(BIO_f_base64());
+  BIO *bio = BIO_new(BIO_s_mem());
+  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+  BIO_push(b64, bio);
+
+  ret = BIO_write(b64, in, in_len);
+  BIO_flush(b64);
+  if (ret > 0)
+    {
+      ret = BIO_read(bio, out, out_len);
+    }
+
+  BIO_free(b64);
+  return ret;
+}
+
+Lng32 str_decode_base64(const unsigned char* in, Lng32 in_len,
+                        char *out, Lng32 out_len)
+{
+  Lng32 ret = 0;
+
+  BIO *b64 = BIO_new(BIO_f_base64());
+  BIO *bio = BIO_new(BIO_s_mem());
+  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+  BIO_push(b64, bio);
+
+  ret = BIO_write(bio, in, in_len);
+  BIO_flush(bio);
+  if (ret)
+    {
+      ret = BIO_read(b64, out, out_len);
+    }
+
+  BIO_free(b64);
+  return ret;
+}
+
 // Strips leading and/or trailing blanks. src will contain a NULL after the
 // end of the first non-blank character.The length of the "stripped" string
 // is returned in len.
@@ -1228,10 +1285,10 @@ size_t str_computeHexAsciiLen(size_t srcByteLen)
 // NULL character - i.e. '\0' - is appended to the output string.
 // -----------------------------------------------------------------------
 Int32 str_convertToHexAscii(const char * src,               // in
-                          const size_t srcLength,         // in
-                          char *       result,            // out
-                          const size_t maxResultSize,     // in
-                          NABoolean    addNullAtEnd)      // in - default is TRUE
+                            const size_t srcLength,         // in
+                            char *       result,            // out
+                            const size_t maxResultSize,     // in
+                            NABoolean    addNullAtEnd)      // in - default is TRUE
 {
   const char hexArray[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                              'A', 'B', 'C', 'D', 'E', 'F'};
diff --git a/core/sql/common/str.h b/core/sql/common/str.h
index d6bfab0..8678d9d 100644
--- a/core/sql/common/str.h
+++ b/core/sql/common/str.h
@@ -328,6 +328,14 @@ Lng32 str_encode(char *tgt, Lng32 tgtMaxLen, void *src, Lng32 srcLen);
 Lng32 str_decoded_len(Lng32 srcLen);
 Lng32 str_decode(void *tgt, Lng32 tgtMaxLen, const char *src, Lng32 srcLen);
 
+// Base64 encoding and decoding.
+Lng32 str_encoded_len_base64(Lng32 len);
+Lng32 str_decoded_len_base64(Lng32 len);
+Lng32 str_encode_base64(const unsigned char* in, Lng32 in_len,
+                        char *out, Lng32 out_len);
+Lng32 str_decode_base64(const unsigned char* in, Lng32 in_len,
+                        char *out, Lng32 out_len);
+
 //------------------------------------------------------------------------
 // Strips leading and/or trailing blanks. src will contain a NULL after the
 // end of the first non-blank character.The length of the "stripped" string
diff --git a/core/sql/exp/ExpError.cpp b/core/sql/exp/ExpError.cpp
index c6bf963..40cdade 100644
--- a/core/sql/exp/ExpError.cpp
+++ b/core/sql/exp/ExpError.cpp
@@ -39,6 +39,7 @@
 #include  "str.h"
 #include "ComDiags.h"
 #include "exp_clause_derived.h"
+#include "exp_datetime.h"
 
 // Single allocation of buf is split up to be used for opstrings,
 // formatting.
@@ -58,6 +59,22 @@
 class PCIType;
 extern char * exClauseGetText(OperatorTypeEnum ote);
 extern char * getDatatypeAsString( Int32 Datatype, NABoolean extFormat );
+extern short
+convertTypeToText_basic(char * text,
+                        Lng32 fs_datatype,
+                        Lng32 length,
+                        Lng32 precision,
+                        Lng32 scale,
+                        rec_datetime_field datetimestart,
+                        rec_datetime_field datetimeend,
+                        short datetimefractprec,
+                        short intervalleadingprec,
+                        short upshift,
+			short caseinsensitive,
+                        CharInfo::CharSet charSet,
+                        const char * collation_name,
+                        const char * displaydatatype,
+			short displayCaseSpecific);
 
 ComDiagsArea *ExAddCondition(CollHeap* heap, ComDiagsArea** diagsArea,
 			     Lng32 err, ComCondition** newCond,
@@ -233,78 +250,88 @@ void ExConvertErrorToString(CollHeap* heap,
 {
   ex_expr::exp_return_type retCode = ex_expr::EXPR_OK;
 
-    Int32 vcharLen = 0;
-    Int32 counter;
-    Int32 errorMark    = ComDiagsArea::INVALID_MARK_VALUE;
-    Int32 warningMark  = ComDiagsArea::INVALID_MARK_VALUE;
-    Int32 errorMark1; 
-    Int32 warningMark1;
+  Int32 vcharLen = 0;
+  Int32 counter;
+  Int32 errorMark    = ComDiagsArea::INVALID_MARK_VALUE;
+  Int32 warningMark  = ComDiagsArea::INVALID_MARK_VALUE;
+  Int32 errorMark1; 
+  Int32 warningMark1;
     
-
-    if(*diagsArea){
-      errorMark = (*diagsArea)->getNumber(DgSqlCode::ERROR_);
-      warningMark = (*diagsArea)->getNumber(DgSqlCode::WARNING_);
+  if (DFS2REC::isBinaryString(srcType)) {
+    if(convertToHexAscii(src, srcLength, result, maxResultSize) == 0 ){
+      return;
     }
-           
-    retCode = convDoIt( src,
-			srcLength,             //source length
-			srcType,               //source type
-			0,                     //source precision
-			srcScale,              //source scale
-			result,                //target
-			maxResultSize,         //targetlength
-			REC_BYTE_V_ASCII,      //target type
-			0,                     //target precision
-			SQLCHARSETCODE_UTF8,   //target scale
-			(char*)&vcharLen,      //vcharlength 
-			sizeof(vcharLen),      //vchar length size
-			heap,
-			diagsArea,
-			CONV_UNKNOWN,
-			0,
-			CONV_CONTROL_LOOPING | CONV_ALLOW_INVALID_CODE_VALUE);
+
+    result[0] = '?';
+    result[1] = '\0';
     
-    //Before proceeding, delete any errors and warnings that may have
-    //been introduced by convDoIt from above.
-    if(*diagsArea){
-      errorMark1 = (*diagsArea)->getNumber(DgSqlCode::ERROR_);
-      warningMark1 = (*diagsArea)->getNumber(DgSqlCode::WARNING_);
-      counter = errorMark1 - errorMark;
-      while(counter){
-        (*diagsArea)->deleteError(errorMark1 - counter);
-        counter--;
-      }
-      counter = warningMark1 - warningMark;
-      while(counter){
-        (*diagsArea)->deleteWarning(warningMark1 - counter);
-        counter--;
-      }
-    }
+    return;
+  }
 
-    if (retCode == ex_expr::EXPR_OK ){
-      // need to zero terminate the result buffer to printf error string
-      if (vcharLen < maxResultSize - 1)
-        result[vcharLen] = '\0';
-      else
-        result[maxResultSize - 1] = '\0';
-      return;
+  if(*diagsArea){
+    errorMark = (*diagsArea)->getNumber(DgSqlCode::ERROR_);
+    warningMark = (*diagsArea)->getNumber(DgSqlCode::WARNING_);
+  }
+           
+  retCode = convDoIt( src,
+                      srcLength,             //source length
+                      srcType,               //source type
+                      0,                     //source precision
+                      srcScale,              //source scale
+                      result,                //target
+                      maxResultSize,         //targetlength
+                      REC_BYTE_V_ASCII,      //target type
+                      0,                     //target precision
+                      SQLCHARSETCODE_UTF8,   //target scale
+                      (char*)&vcharLen,      //vcharlength 
+                      sizeof(vcharLen),      //vchar length size
+                      heap,
+                      diagsArea,
+                      CONV_UNKNOWN,
+                      0,
+                      CONV_CONTROL_LOOPING | CONV_ALLOW_INVALID_CODE_VALUE);
+    
+  //Before proceeding, delete any errors and warnings that may have
+  //been introduced by convDoIt from above.
+  if(*diagsArea){
+    errorMark1 = (*diagsArea)->getNumber(DgSqlCode::ERROR_);
+    warningMark1 = (*diagsArea)->getNumber(DgSqlCode::WARNING_);
+    counter = errorMark1 - errorMark;
+    while(counter){
+      (*diagsArea)->deleteError(errorMark1 - counter);
+      counter--;
     }
-
-    //Once we reach this point, all we can do is just dump the source memory.
-    if(convertToHexAscii(src, srcLength, result, maxResultSize) == 0 ){
-      return;
+    counter = warningMark1 - warningMark;
+    while(counter){
+      (*diagsArea)->deleteWarning(warningMark1 - counter);
+      counter--;
     }
+  }
 
-    // Once we reach this point, there is nothing we can do much.
-    // Attempt to display "-E" indicating error, else NULL.
-    if(maxResultSize >=3){
-      result[0] = '-';
-      result[1] = 'E';
-      result[2] = '\0';
-    }
+  if (retCode == ex_expr::EXPR_OK ){
+    // need to zero terminate the result buffer to printf error string
+    if (vcharLen < maxResultSize - 1)
+      result[vcharLen] = '\0';
     else
-      result[0] = '\0';
+      result[maxResultSize - 1] = '\0';
     return;
+  }
+
+  //Once we reach this point, all we can do is just dump the source memory.
+  if(convertToHexAscii(src, srcLength, result, maxResultSize) == 0 ){
+    return;
+  }
+
+  // Once we reach this point, there is nothing we can do much.
+  // Attempt to display "-E" indicating error, else NULL.
+  if(maxResultSize >=3){
+    result[0] = '-';
+    result[1] = 'E';
+    result[2] = '\0';
+  }
+  else
+    result[0] = '\0';
+  return;
 }
 
 //Detailed error support for pcode expression evaluation.
@@ -532,7 +559,8 @@ ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap,
                                     UInt32 flags,
                                     Int32 tgtLength,
                                     Int32 tgtScale,
-                                    Int32 tgtPrecision)
+                                    Int32 tgtPrecision,
+                                    Int32 srcPrecision)
 {
   //if looping situation, no need to proceed further, return back.
   if(flags & CONV_CONTROL_LOOPING)
@@ -574,26 +602,55 @@ ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap,
                          OPVALUE_LEN);
 
   char srcDatatypeDetail[200];
-  if ((DFS2REC::isAnyCharacter(srcType)) &&
-      (srcLength >= 0) &&
-      (srcScale > 0))
+  char tgtDatatypeDetail[200];
+  char srcTypeAsText[1000];
+  char tgtTypeAsText[100];
+  srcTypeAsText[0] = 0;
+  tgtTypeAsText[0] = 0;
+
+  if (srcPrecision != -1)
+    {
+      rec_datetime_field startField;
+      rec_datetime_field endField;
+      ExpDatetime::getDatetimeFields(srcPrecision, startField, endField);
+      convertTypeToText_basic(srcTypeAsText, 
+                              srcType, srcLength, srcPrecision, srcScale,
+                              startField, endField, 0, 0, 0, 0,
+                              (CharInfo::CharSet)srcScale,
+                              NULL, NULL, 0);
+      strcpy(srcDatatypeDetail, getDatatypeAsString(srcType, false));
+    }
+  else if ((DFS2REC::isCharacterString(srcType)) &&
+           (srcLength >= 0) &&
+           (srcScale > 0) &&
+           (srcPrecision == -1))
     str_sprintf(srcDatatypeDetail, "%s,%d BYTES,%s", 
                 getDatatypeAsString(srcType, false), 
-                //                srcLength/CharInfo::bytesPerChar((CharInfo::CharSet)srcScale),
                 srcLength,
                 (srcScale == CharInfo::ISO88591 ? "ISO88591" : "UTF8"));
   else
     strcpy(srcDatatypeDetail, getDatatypeAsString(srcType, false));
-  
-  char tgtDatatypeDetail[200];
-  if ((DFS2REC::isAnyCharacter(tgtType)) &&
-      (tgtLength >= 0) &&
-      (tgtScale > 0))
+
+  if (tgtLength != -1)
+    {
+      rec_datetime_field startField;
+      rec_datetime_field endField;
+      ExpDatetime::getDatetimeFields(tgtPrecision, startField, endField);
+
+      convertTypeToText_basic(tgtTypeAsText, 
+                              tgtType, tgtLength, tgtPrecision, tgtScale,
+                              startField, endField, 0, 0, 0, 0, 
+                              (CharInfo::CharSet)tgtScale,
+                              NULL, NULL, 0);
+      strcpy(tgtDatatypeDetail, getDatatypeAsString(tgtType, false));
+    }
+  else if ((DFS2REC::isCharacterString(tgtType)) &&
+           (tgtLength >= 0) &&
+           (tgtScale > 0))
     str_sprintf(tgtDatatypeDetail, "%s,%d %s,%s", 
                 getDatatypeAsString(tgtType, false), 
                 tgtPrecision ? tgtPrecision : tgtLength,
                 tgtPrecision ? "CHARS" : "BYTES",
-                //                tgtLength/CharInfo::bytesPerChar((CharInfo::CharSet)tgtScale),
                 (tgtScale == CharInfo::ISO88591 ? "ISO88591" : "UTF8"));
   else
     strcpy(tgtDatatypeDetail, getDatatypeAsString(tgtType, false));
@@ -601,10 +658,12 @@ ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap,
   str_sprintf(buf,
               " %s of Source Type:%s(%s) Source Value:%s to Target Type:%s(%s).",
               intermediate? "Intermediate conversion" : "Conversion",
-              getDatatypeAsString(srcType, true),
+              (strlen(srcTypeAsText) == 0 ? getDatatypeAsString(srcType,true) :
+               srcTypeAsText),              
               srcDatatypeDetail,
               opString,
-              getDatatypeAsString(tgtType,true),
+              (strlen(tgtTypeAsText) == 0 ? getDatatypeAsString(tgtType,true) :
+               tgtTypeAsText),
               tgtDatatypeDetail);
   
   **diagsArea << DgSqlCode(-err);
diff --git a/core/sql/exp/ExpError.h b/core/sql/exp/ExpError.h
index 6b6b3a6..3cc1caf 100644
--- a/core/sql/exp/ExpError.h
+++ b/core/sql/exp/ExpError.h
@@ -132,7 +132,8 @@ ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap,
                                     UInt32 flags,
                                     Int32 tgtLength = -1,
                                     Int32 tgtScale = -1,
-                                    Int32 tgtPrecision = 0);
+                                    Int32 tgtPrecision = 0,
+                                    Int32 srcPrecision = -1);
 char *stringToHex(char * out, Int32 outLen, char * in, Int32 inLen);
                                                                 
 #endif /* EXP_ERROR_H */
diff --git a/core/sql/exp/ExpErrorEnums.h b/core/sql/exp/ExpErrorEnums.h
index 2f9c3a2..61550d0 100644
--- a/core/sql/exp/ExpErrorEnums.h
+++ b/core/sql/exp/ExpErrorEnums.h
@@ -137,6 +137,7 @@ enum ExeErrorCode
   EXE_TRIM_ERROR			= 8404,
   EXE_CONVERTTIMESTAMP_ERROR		= 8405,
   EXE_JULIANTIMESTAMP_ERROR		= 8407,
+  EXE_CONVERSION_ERROR                  = 8408,
   EXE_INVALID_ESCAPE_CHARACTER		= 8409,
   EXE_INVALID_ESCAPE_SEQUENCE		= 8410,
   EXE_NUMERIC_OVERFLOW			= 8411,
diff --git a/core/sql/exp/ExpPCodeClauseGen.cpp b/core/sql/exp/ExpPCodeClauseGen.cpp
index 2d07a84..dc31d25 100644
--- a/core/sql/exp/ExpPCodeClauseGen.cpp
+++ b/core/sql/exp/ExpPCodeClauseGen.cpp
@@ -4434,7 +4434,7 @@ ex_function_char_length::pCodeGenerate(Space *space, UInt32 f)
   PCIID branchToEnd = PCode::nullBranch(this, code, attrs);
 
   // Just return length if the string is fixed
-  if (attrs[1]->getDatatype() == REC_BYTE_F_ASCII) {
+  if (DFS2REC::isSQLFixedChar(attrs[1]->getDatatype())) {
     AML aml(PCIT::MBIN32S, PCIT::IBIN32S);
     OL ol(attrs[0]->getAtp(), attrs[0]->getAtpIndex(), attrs[0]->getOffset(),
           (Int32)attrs[1]->getLength());
diff --git a/core/sql/exp/exp_attrs.cpp b/core/sql/exp/exp_attrs.cpp
index f03dad5..567ecbc 100644
--- a/core/sql/exp/exp_attrs.cpp
+++ b/core/sql/exp/exp_attrs.cpp
@@ -251,6 +251,9 @@ switch (datatype)
   case REC_CLOB: return extFormat? (char *)"CLOB":(char *)"REC_CLOB";
   case REC_BOOLEAN: return extFormat ? (char *)"BOOLEAN" : (char *)"REC_BOOLEAN";
 
+  case REC_BINARY_STRING: return extFormat ? (char *)"BINARY" : (char *)"REC_BINARY_STRING";
+  case REC_VARBINARY_STRING: return extFormat ? (char *)"VARBINARY" : (char *)"REC_VARBINARY_STRING";
+
   // When you add new datatype in /common/dfs2rec.h, don't
   // forget add new case here. Otherwise, showplan won't display it.
   default: return extFormat? (char *)"UNKNOWN":(char *)"add datatype in getDatatypeAsString()";
@@ -571,6 +574,7 @@ Int32 Attributes::getFirstCharLength(const char              *buf,
   // treat it as single byte character.
   if( cs == CharInfo::ISO88591 ||
       cs == CharInfo::UCS2 ||
+      cs == CharInfo::BINARY ||
       buf[0] == 0)
   {
       firstCharLenInBuf = 1;
@@ -588,7 +592,7 @@ Int32 Attributes::convertOffsetToChar(const char        *buf,
                                       Int32             offset, 
                                       CharInfo::CharSet cs)
 {
-  if (cs == CharInfo::ISO88591 || cs == CharInfo::UCS2)
+  if (cs == CharInfo::ISO88591 || cs == CharInfo::UCS2 || cs == CharInfo::BINARY)
      return(offset);
 
   Int32 firstCharLenInBuf;
@@ -621,7 +625,7 @@ Int32 Attributes::convertCharToOffset (const char        *buf,
                                        Int32             maxBufLen,
                                        CharInfo::CharSet cs)
 {
-  if (cs == CharInfo::ISO88591 || cs == CharInfo::UCS2)
+  if (cs == CharInfo::ISO88591 || cs == CharInfo::UCS2 || cs == CharInfo::BINARY)
      return((numOfChar <= maxBufLen) ? numOfChar - 1 : maxBufLen);
 
   Int32 firstCharLenInBuf;
@@ -658,7 +662,7 @@ Int32 Attributes::getCharLengthInBuf
 {
   Int32 numberOfCharacterInBuf;
 
-  if (cs == CharInfo::ISO88591 || cs == CharInfo::UCS2)
+  if (cs == CharInfo::ISO88591 || cs == CharInfo::BINARY || cs == CharInfo::UCS2)
   {
     numberOfCharacterInBuf = endOfBuf - buf;
     if(charLengthInBuf != NULL)
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index d8708d0..0d0a03c 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -558,7 +558,11 @@ ex_clause::ex_clause(clause_type type,
         case ITM_AES_DECRYPT:
           setClassID(FUNC_AES_DECRYPT);
           break;
-	default:
+        case ITM_ENCODE_BASE64:
+        case ITM_DECODE_BASE64:
+          setClassID(FUNC_BASE64_ENC_DEC);
+          break;
+ 	default:
 	  GenAssert(0, "ex_clause: Unknown Class ID.");
 	  break;
 	}
@@ -1058,7 +1062,10 @@ char *ex_clause::findVTblPtr(short classID)
     case ex_clause::FUNC_AES_DECRYPT:
       GetVTblPtr(vtblPtr, ExFunctionAESDecrypt);
       break;
-     default:
+    case ex_clause::FUNC_BASE64_ENC_DEC:
+      GetVTblPtr(vtblPtr, ExFunctionBase64EncDec);
+      break;
+    default:
       GetVTblPtr(vtblPtr, ex_clause);
       break;
     }
@@ -1526,6 +1533,9 @@ const char * getOperTypeEnumAsString(Int16 /*OperatorTypeEnum*/ ote)
 
     case ITM_SEQUENCE_VALUE: return "ITM_SEQUENCE_VALUE";
 
+    case ITM_ENCODE_BASE64: return "ITM_ENCODE_BASE64";
+    case ITM_DECODE_BASE64: return "ITM_DECODE_BASE64";
+
     // Note, this list is arranged in the same order as the types
     // appear in common/OperTypeEnum.h, please keep the same order
     // when adding new types
@@ -2099,7 +2109,7 @@ void ex_function_dateformat::displayContents(Space * space, const char * /*displ
 // Function to compare two strings. 
 Int32 charStringCompareWithPad(char* in_s1, Int32 length1, 
                                           char* in_s2, Int32 length2, 
-                                          char space)
+                                          char padChar)
 {
   unsigned char * s1 = (unsigned char *)in_s1;
   unsigned char * s2 = (unsigned char *)in_s2;
@@ -2118,39 +2128,40 @@ Int32 charStringCompareWithPad(char* in_s1, Int32 length1,
      {
        if (length1 > length2)
          {
-   	Int32 j = compare_len;
-   	
-   	while ((j < length1) && (compare_code == 0))
-   	  {
-   	    if (s1[j] < space )
-   	      compare_code = -1;
-   	    else
-   	      if (s1[j] > space )
-   		compare_code = 1;
-   	    j++;
-   	  }
+           Int32 j = compare_len;
+           
+           while ((j < length1) && (compare_code == 0))
+             {
+               if (s1[j] < padChar )
+                 compare_code = -1;
+               else
+                 if (s1[j] > padChar )
+                   compare_code = 1;
+               j++;
+             }
          }
        else
          {
-   	Int32 j = compare_len;
-   	
-   	while ((j < length2) && (compare_code == 0))
-   	  {
-   	    if (s2[j] < space )
-   	      compare_code = 1;
-   	    else
-   	      if (s2[j] > space )
-   		compare_code = -1;
-   	    j++;
-   	  }
+           Int32 j = compare_len;
+           
+           while ((j < length2) && (compare_code == 0))
+             {
+               if (s2[j] < padChar )
+                 compare_code = 1;
+               else
+                 if (s2[j] > padChar )
+                   compare_code = -1;
+               j++;
+             }
          }
-    }
-     //return 0,1,-1 values, not the positive, 0, negative
-     if (compare_code > 0)
-       compare_code = 1;
-     if (compare_code < 0)
-       compare_code = -1;
-    return compare_code;
+     }
+
+   //return 0,1,-1 values, not the positive, 0, negative
+   if (compare_code > 0)
+     compare_code = 1;
+   if (compare_code < 0)
+     compare_code = -1;
+   return compare_code;
 }
 
 Int32 wcharStringCompareWithPad(NAWchar* s1, Int32 length1, 
diff --git a/core/sql/exp/exp_clause.h b/core/sql/exp/exp_clause.h
index 3f785ef..cdb7ef1 100644
--- a/core/sql/exp/exp_clause.h
+++ b/core/sql/exp/exp_clause.h
@@ -209,10 +209,11 @@ public:
     FUNC_JSON_ID             = 128,
     FUNC_AES_ENCRYPT         = 129,
     FUNC_AES_DECRYPT         = 130,
-    FUNC_REVERSE_ID         = 131,
-    FUNC_SLEEP_ID           = 132,
-    FUNC_UNIX_TIMESTAMP_ID = 133,
-    FUNC_SPLIT_PART_ID     = 134
+    FUNC_REVERSE_ID          = 131,
+    FUNC_BASE64_ENC_DEC      = 132,
+    FUNC_SLEEP_ID            = 133,
+    FUNC_UNIX_TIMESTAMP_ID   = 134,
+    FUNC_SPLIT_PART_ID       = 135
   };
 
   // max number of operands (including result) in a clause.
diff --git a/core/sql/exp/exp_clause_derived.h b/core/sql/exp/exp_clause_derived.h
index 17d1f1d..1018d1f 100644
--- a/core/sql/exp/exp_clause_derived.h
+++ b/core/sql/exp/exp_clause_derived.h
@@ -1193,7 +1193,10 @@ enum CompInstruction {
   GE_BIN8S_BIN8S      =189,
   GE_BIN8U_BIN8U      =190,
 
-  COMP_NOT_SUPPORTED  =191
+  // comparison between sql binary/varbinary datatypes
+  BINARY_COMP         =191,
+
+  COMP_NOT_SUPPORTED  =192
 };
 
 class  ex_comp_clause : public ex_clause {
@@ -1706,7 +1709,17 @@ enum ConvInstruction {
   CONV_NUMERIC_BIN8U                    =284,
 
   CONV_BIN8S_BIN8U                     =285,
-  CONV_BIN8U_BIN8S                     =286
+  CONV_BIN8U_BIN8S                     =286,
+
+  CONV_BINARY_TO_BINARY                =287,
+  CONV_BINARY_TO_VARBINARY             =288,
+  CONV_VARBINARY_TO_BINARY             =289,
+  CONV_VARBINARY_TO_VARBINARY          =290,
+
+  CONV_BINARY_TO_OTHER                 =291,
+  CONV_VARBINARY_TO_OTHER              =292,
+  CONV_OTHER_TO_BINARY                 =293,
+  CONV_OTHER_TO_VARBINARY              =294
 };
 
 class  ex_conv_clause : public ex_clause {
diff --git a/core/sql/exp/exp_comp.cpp b/core/sql/exp/exp_comp.cpp
index aec4efc..fd1a704 100644
--- a/core/sql/exp/exp_comp.cpp
+++ b/core/sql/exp/exp_comp.cpp
@@ -1198,7 +1198,23 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] =
 	((ComplexType *)getOperand(1))->comp(getOperType(), getOperand(2), op_data);
       break;
-      
+
+    case BINARY_COMP:
+      {
+        Lng32 length1 = getOperand(1)->getLength(op_data[-MAX_OPERANDS + 1]);
+        Lng32 length2 = getOperand(2)->getLength(op_data[-MAX_OPERANDS + 2]) ;
+        
+        char padChar = 0;
+
+        Int32 compare_code =
+          charStringCompareWithPad( op_data[1], length1, op_data[2], length2, 
+                                    padChar);
+
+        retcode = processResult(compare_code, (Lng32 *)op_data[0], 
+                                heap, diagsArea);
+      }
+      break;
+    
     case COMP_NOT_SUPPORTED:
       {
 	// this comparison operation not supported.
diff --git a/core/sql/exp/exp_conv.cpp b/core/sql/exp/exp_conv.cpp
index f4265b7..42af6a9 100644
--- a/core/sql/exp/exp_conv.cpp
+++ b/core/sql/exp/exp_conv.cpp
@@ -3995,10 +3995,10 @@ ex_expr::exp_return_type checkPrecision(Int64 source,
     // nor an integer and the source is either a float, integer, or bigger
     if ((sourceType >= REC_MIN_NUMERIC) &&
         (sourceType <= REC_MAX_NUMERIC) &&
-        (targetType >= REC_MIN_BINARY) &&
-        (targetType <= REC_MAX_BINARY) &&
-        ((sourceType < REC_MIN_BINARY) ||
-         (sourceType > REC_MAX_BINARY) ||
+        (targetType >= REC_MIN_BINARY_NUMERIC) &&
+        (targetType <= REC_MAX_BINARY_NUMERIC) &&
+        ((sourceType < REC_MIN_BINARY_NUMERIC) ||
+         (sourceType > REC_MAX_BINARY_NUMERIC) ||
          (sourcePrecision == 0) ||
          (sourcePrecision > targetPrecision)))  {
       //
@@ -4088,8 +4088,8 @@ ex_expr::exp_return_type checkPrecision(Int64 source,
 	(sourceType <= REC_MAX_NUMERIC) &&
            (targetType >= REC_MIN_INTERVAL) &&
            (targetType <= REC_MAX_INTERVAL)) &&
-        ((sourceType < REC_MIN_BINARY) || // ??
-         (sourceType > REC_MAX_BINARY) || // ??
+        ((sourceType < REC_MIN_BINARY_NUMERIC) || // ??
+         (sourceType > REC_MAX_BINARY_NUMERIC) || // ??
          (sourcePrecision == 0) || // ??
          (sourcePrecision > ((targetType == REC_INT_SECOND) ?
                        (targetPrecision + targetScale) : targetPrecision))))  {
@@ -4131,8 +4131,8 @@ ex_expr::exp_return_type checkPrecision(Int64 source,
       //
     if ((sourceType >= REC_MIN_INTERVAL) &&
          (sourceType <= REC_MAX_INTERVAL) &&
-        (targetType >= REC_MIN_BINARY) &&
-        (targetType <= REC_MAX_BINARY) &&
+        (targetType >= REC_MIN_BINARY_NUMERIC) &&
+        (targetType <= REC_MAX_BINARY_NUMERIC) &&
          (sourcePrecision > targetPrecision))  {
 
       if ((source < getMinDecValue(targetPrecision, targetType)) ||
@@ -4269,9 +4269,9 @@ ex_expr::exp_return_type convExactToDec(char *target,
 ///////////////////////////////////////////////
 // find the first non blank character
 ///////////////////////////////////////////////
-char * str_find_first_nonblank(char *s, Lng32 len) {
+char * str_find_first_nonpad(char *s, Lng32 len, char padChar) {
   for (Lng32 i = 0; i < len; i++)
-    if (s[i] != ' ') 
+    if (s[i] != padChar) 
       return &s[i];
   return 0;
 };
@@ -4620,7 +4620,7 @@ ex_expr::exp_return_type convCharToChar(
               // check whether the characters from firstUntranslatedChar onwards are all blanks
               remainingScanStringLen = input_length - (firstUntranslatedChar - input_to_scan);
               canIgnoreOverflowChars = 
-                !(str_find_first_nonblank(firstUntranslatedChar, remainingScanStringLen));
+                !(str_find_first_nonpad(firstUntranslatedChar, remainingScanStringLen, ' '));
             }
 
           if (!canIgnoreOverflowChars)
@@ -4690,7 +4690,7 @@ ex_expr::exp_return_type convCharToChar(
               Lng32 remainingSourceStringLen = src2Len - (firstUntranslatedChar - src2);
               // check whether the characters from firstUntranslatedChar onwards are all blanks
               canIgnoreOverflowChars = 
-                !(str_find_first_nonblank(firstUntranslatedChar, remainingSourceStringLen));
+                !(str_find_first_nonpad(firstUntranslatedChar, remainingSourceStringLen, ' '));
             }
 
           if (!canIgnoreOverflowChars)
@@ -4807,8 +4807,8 @@ ex_expr::exp_return_type convCharToChar(
                   Lng32 remainingSourceStringLen = sourceLen - outputDataLen;
                   // check whether the characters from first truncated char onwards are all blanks
                   relevantCharsGotTruncated = 
-                    (str_find_first_nonblank(&(source[outputDataLen]),
-                                             remainingSourceStringLen) != NULL);
+                    (str_find_first_nonpad(&(source[outputDataLen]),
+                                           remainingSourceStringLen, ' ') != NULL);
                 }
               else
                 relevantCharsGotTruncated = TRUE;
@@ -6516,7 +6516,8 @@ convDoIt(char * source,
             {
               ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
                                     source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
+                                    targetType, tempFlags, targetLen, targetScale,
+                                    targetPrecision, sourcePrecision);
               return ex_expr::EXPR_ERROR;
             }
         }
@@ -10226,8 +10227,8 @@ convDoIt(char * source,
 
         if (copyLen < sourceLen) 
           {
-            char * first_nonblank = str_find_first_nonblank(
-                 &source[copyLen], sourceLen - copyLen);
+            char * first_nonblank = str_find_first_nonpad(
+                 &source[copyLen], sourceLen - copyLen, ' ');
             
             if (first_nonblank)  // if truncated portion isn't all blanks
               {
@@ -10910,8 +10911,8 @@ convDoIt(char * source,
               str_cpy_all(target, source, copyLen);
               if (copyLen < sourceLen) 
                 {
-                  char * first_nonblank = str_find_first_nonblank(
-                       &source[copyLen], sourceLen - copyLen);
+                  char * first_nonblank = str_find_first_nonpad(
+                       &source[copyLen], sourceLen - copyLen, ' ');
                   
                   if (first_nonblank)  // if truncated portion isn't all blanks
                     {
@@ -11034,7 +11035,7 @@ convDoIt(char * source,
           // put null character at the end
           target[targetLen] = 0;
           if ((targetLen < sourceLen) &&
-              str_find_first_nonblank(&source[targetLen], sourceLen - targetLen))
+              str_find_first_nonpad(&source[targetLen], sourceLen - targetLen, ' '))
             ExRaiseSqlWarning(heap, diagsArea, EXE_STRING_OVERFLOW);
         }
       }
@@ -11114,7 +11115,7 @@ convDoIt(char * source,
           else {
             target[targetLen] = 0;
           }
-          if (str_find_first_nonblank(&source[targetLen], actSourceLen - targetLen))
+          if (str_find_first_nonpad(&source[targetLen], actSourceLen - targetLen, ' '))
             ExRaiseSqlWarning(heap, diagsArea, EXE_STRING_OVERFLOW);
         }
       }
@@ -11304,6 +11305,157 @@ convDoIt(char * source,
     }
     break;
 
+  case CONV_BINARY_TO_BINARY:
+  case CONV_VARBINARY_TO_BINARY:
+    {
+      Lng32 copyLen = ((targetLen >= sourceLen) ? sourceLen : targetLen);
+      str_cpy_all(target, source, copyLen);
+      
+      if (targetLen > copyLen) 
+        {
+          /* zero pad target */
+          str_pad(&target[copyLen], targetLen - copyLen, '\0');
+        }
+      else if (copyLen < sourceLen) 
+        {
+          char * first_nonzero = str_find_first_nonpad(
+               &source[copyLen], sourceLen - copyLen, '\0');
+          if (first_nonzero)
+            {
+              if (dataConversionErrorFlag) // want conversion flag instead of warning?
+                *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN;
+              else
+                // no - raise a warning
+                ExRaiseDetailSqlError(heap, diagsArea, (ExeErrorCode)(-EXE_CONVERSION_ERROR),
+                                      source, sourceLen, sourceType, sourceScale,
+                                      targetType, 0, targetLen, targetScale, 
+                                      targetPrecision, sourcePrecision);
+            }
+        }
+    }
+    break;
+
+  case CONV_BINARY_TO_VARBINARY:
+  case CONV_VARBINARY_TO_VARBINARY:
+    {
+      Lng32 copyLen = ((targetLen >= sourceLen) ? sourceLen : targetLen);
+      str_cpy_all(target, source, copyLen);
+      setVCLength(varCharLen, varCharLenSize, copyLen);
+
+      if (copyLen < sourceLen) 
+        {
+          char * first_nonzero = str_find_first_nonpad(
+               &source[copyLen], sourceLen - copyLen, '\0');
+          if (first_nonzero)
+            {
+              if (dataConversionErrorFlag)
+                *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN;
+              else
+                // no - raise a warning
+                ExRaiseDetailSqlError(heap, diagsArea, (ExeErrorCode)(-EXE_CONVERSION_ERROR),
+                                      source, sourceLen, sourceType, sourceScale,
+                                      targetType, 0, targetLen, targetScale, 
+                                      targetPrecision, sourcePrecision);
+            }
+        }
+    }
+    break;
+
+  case CONV_OTHER_TO_BINARY:
+    {
+      Lng32 copyLen = ((targetLen >= sourceLen) ? sourceLen : targetLen);
+      str_cpy_all(target, source, copyLen);
+      
+      if (targetLen > copyLen) 
+        {
+          /* zero pad target */
+          str_pad(&target[copyLen], targetLen - copyLen, '\0');
+        }
+      else if (copyLen < sourceLen) 
+        {
+          if (dataConversionErrorFlag)
+            *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN;
+          else
+            {
+              ExRaiseDetailSqlError(heap, diagsArea, EXE_CONVERSION_ERROR,
+                                    source, sourceLen, sourceType, sourceScale,
+                                    targetType, 0, targetLen, targetScale, 
+                                    targetPrecision, sourcePrecision);
+              return ex_expr::EXPR_ERROR;
+            }
+        }
+    }
+    break;
+
+  case CONV_OTHER_TO_VARBINARY:
+    {
+      Lng32 copyLen = ((targetLen >= sourceLen) ? sourceLen : targetLen);
+      str_cpy_all(target, source, copyLen);
+      setVCLength(varCharLen, varCharLenSize, copyLen);
+
+      if (copyLen < sourceLen)
+        {
+          if (dataConversionErrorFlag)
+            *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN;
+          else
+            {
+              ExRaiseDetailSqlError(heap, diagsArea, EXE_CONVERSION_ERROR,
+                                    source, sourceLen, sourceType, sourceScale,
+                                    targetType, 0, targetLen, targetScale, 
+                                    targetPrecision, sourcePrecision);
+              return ex_expr::EXPR_ERROR;
+            }
+        }
+    }
+    break;
+
+  case CONV_BINARY_TO_OTHER:
+  case CONV_VARBINARY_TO_OTHER:
+    {
+      Lng32 copyLen = ((targetLen >= sourceLen) ? sourceLen : targetLen);
+      str_cpy_all(target, source, copyLen);
+
+      if (varCharLen && (varCharLenSize > 0))
+        setVCLength(varCharLen, varCharLenSize, copyLen);
+
+      // if source len is > target len, return error. There is no truncation.
+      if (sourceLen > targetLen)
+        {
+          if (dataConversionErrorFlag)
+            *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN;
+          else
+            {
+              ExRaiseDetailSqlError(heap, diagsArea, EXE_CONVERSION_ERROR,
+                                    source, sourceLen, sourceType, sourceScale,
+                                    targetType, 0, targetLen, targetScale, 
+                                    targetPrecision, sourcePrecision);
+              return ex_expr::EXPR_ERROR;
+            }
+        }
+      // if target len > source len and target datatype is string, blankpad.
+      // Otherwise return error.
+      else if (targetLen > sourceLen)
+        {
+          if (DFS2REC::isCharacterString(targetType))
+            {
+              char padChar = 0;
+              if (DFS2REC::isCharacterString(targetType))
+                padChar = ' ';
+              
+              str_pad(target+sourceLen, targetLen-sourceLen, padChar);
+            }
+          else
+            {
+              ExRaiseDetailSqlError(heap, diagsArea, EXE_CONVERSION_ERROR,
+                                    source, sourceLen, sourceType, sourceScale,
+                                    targetType, 0, targetLen, targetScale, 
+                                    targetPrecision, sourcePrecision);
+              return ex_expr::EXPR_ERROR;
+            }
+        }
+    }
+    break;
+
   case CONV_NOT_SUPPORTED:
   default:
     {
@@ -11318,8 +11470,7 @@ convDoIt(char * source,
                           targetScale);
     
     // this conversion is not supported.
-    //      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_NOT_SUPPORTED);
-      return ex_expr::EXPR_ERROR;
+    return ex_expr::EXPR_ERROR;
     }
   break;
 
@@ -11406,7 +11557,6 @@ ex_expr::exp_return_type ex_conv_clause::eval(char *op_data[],
     else
       warningMark = 0;
 
-
   switch (getInstruction()) {
 
 
@@ -11461,7 +11611,7 @@ ex_expr::exp_return_type ex_conv_clause::eval(char *op_data[],
 	source = (char*)ptrVal;
       }
 
-    retcode =  convDoIt(source, //op_data[1],
+    retcode =  convDoIt(source,
 			src->getLength(op_data[-MAX_OPERANDS + 1]),
 			src->getDatatype(),
 			src->getPrecision(),
@@ -11508,15 +11658,13 @@ ex_expr::exp_return_type ex_conv_clause::eval(char *op_data[],
   };
   }; // switch
 
-// If this conv clause came from either an update or an insert, and if
-// the data types are char types and the target size is smaller than source
-// size, the checkTruncError flag should be set.
-// In this section, if the flag is set, and a warning is returned as the
-// result of the conversion, an error should be issued instead of a warning.
-// This is according to ANSI SQL92
-// If this is for SPECIAL1_MODE, then neither warnings nor errors should be
-// returned for truncations of char types on inserts and updates.
-
+  // If this conv clause came from either an update or an insert, and if
+  // the data types are char types and the target size is smaller than source
+  // size, the checkTruncError flag should be set.
+  // In this section, if the flag is set, and a warning is returned as the
+  // result of the conversion, an error should be issued instead of a warning.
+  // This is according to ANSI SQL92
+  
   if (getCheckTruncationFlag() && *diagsArea) {
     Int32 warningMark2 = (*diagsArea)->getNumber(DgSqlCode::WARNING_);
     Int32 counter = warningMark2 - warningMark;
@@ -11533,14 +11681,24 @@ ex_expr::exp_return_type ex_conv_clause::eval(char *op_data[],
                               0,
                               tgt->getLength(),
                               tgt->getScale(),
-                              tgt->getPrecision());
+                              tgt->getPrecision(),
+                              src->getPrecision());
         retcode = ex_expr::EXPR_ERROR;
       }
       else if (((*diagsArea)->getWarningEntry(warningMark2 - counter + 1))->
                 getSQLCODE() == EXE_NUMERIC_OVERFLOW) {
              (*diagsArea)->deleteWarning(warningMark2-counter);
              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                   this, op_data);
+                                   op_data[1],
+                                   src->getLength(op_data[-MAX_OPERANDS + 1]),
+                                   src->getDatatype(),
+                                   src->getScale(),
+                                   tgt->getDatatype(),
+                                   0,
+                                   tgt->getLength(),
+                                   tgt->getScale(),
+                                   tgt->getPrecision(),
+                                   src->getPrecision());
              retcode = ex_expr::EXPR_ERROR;
            }
       counter--;
@@ -11915,7 +12073,7 @@ ex_expr::exp_return_type swapBytes(Attributes *attr,
   rec_datetime_field endField; 
   ExpDatetime *dtAttr;
 
-  if (dataType >= REC_MIN_BINARY && dataType <= REC_MAX_BINARY)
+  if (dataType >= REC_MIN_BINARY_NUMERIC && dataType <= REC_MAX_BINARY_NUMERIC)
   {
      swapBytes(ptr, storageLength);
   }
diff --git a/core/sql/exp/exp_datetime.cpp b/core/sql/exp/exp_datetime.cpp
index 926cde2..96836e4 100644
--- a/core/sql/exp/exp_datetime.cpp
+++ b/core/sql/exp/exp_datetime.cpp
@@ -1282,7 +1282,7 @@ short ExpDatetime::subDatetimeDatetime(Attributes *datetimeOpType,
         return -1;
       }
     }
-  else if ((DFS2REC::isBinary(intervalOpType->getDatatype())) &&
+  else if ((DFS2REC::isBinaryNumeric(intervalOpType->getDatatype())) &&
            (datetimeEndField == REC_DATE_DAY))
     {
       // special modeSpecial4 case.
diff --git a/core/sql/exp/exp_expr.h b/core/sql/exp/exp_expr.h
index 6bbd6b0..016ae1c 100644
--- a/core/sql/exp/exp_expr.h
+++ b/core/sql/exp/exp_expr.h
@@ -1166,8 +1166,10 @@ public:
   {
     if ((((source >= REC_MIN_NUMERIC) && (source <= REC_MAX_NUMERIC)) &&
 	 ((target >= REC_MIN_NUMERIC) && (target <= REC_MAX_NUMERIC))) ||
-	(((source >= REC_MIN_CHARACTER) && (source <= REC_MAX_CHARACTER)) &&
-	 ((target >= REC_MIN_CHARACTER) && (target <= REC_MAX_CHARACTER))) ||
+        ((DFS2REC::isCharacterString(source)) && 
+         (DFS2REC::isCharacterString(target))) ||
+        ((DFS2REC::isBinaryString(source)) && 
+         (DFS2REC::isBinaryString(target))) ||
 	((source == REC_DATETIME) && (target == REC_DATETIME)) ||
 	(((source >= REC_MIN_INTERVAL) && (source <= REC_MAX_INTERVAL)) &&
 	 ((target >= REC_MIN_INTERVAL) && (target <= REC_MAX_INTERVAL))) ||
@@ -1182,9 +1184,9 @@ public:
   static NABoolean implicitConversionSupported(short source, short target)
   {
     if ((((source >= REC_MIN_CHARACTER) && (source <= REC_MAX_CHARACTER)) &&
-	 ((target == REC_DATETIME) || ((target >= REC_MIN_BINARY) && (target <= REC_MAX_BINARY)))) ||
+	 ((target == REC_DATETIME) || ((target >= REC_MIN_BINARY_NUMERIC) && (target <= REC_MAX_BINARY_NUMERIC)))) ||
 	(((target >= REC_MIN_CHARACTER) && (target <= REC_MAX_CHARACTER)) &&
-	 ((source == REC_DATETIME) || ((source >= REC_MIN_BINARY) && (source <= REC_MAX_BINARY)))))
+	 ((source == REC_DATETIME) || ((source >= REC_MIN_BINARY_NUMERIC) && (source <= REC_MAX_BINARY_NUMERIC)))))
       return TRUE;
     else
       return FALSE;
@@ -1192,7 +1194,7 @@ public:
 
   NABoolean isExactNumeric(short type)
   {
-    if ((type >= REC_MIN_BINARY) && (type <= REC_MAX_BINARY) ||
+    if ((type >= REC_MIN_BINARY_NUMERIC) && (type <= REC_MAX_BINARY_NUMERIC) ||
 	(type >= REC_MIN_DECIMAL) && (type <= REC_MAX_DECIMAL))
       return TRUE;
     else
diff --git a/core/sql/exp/exp_fixup.cpp b/core/sql/exp/exp_fixup.cpp
index c2cb36c..a59aec3 100644
--- a/core/sql/exp/exp_fixup.cpp
+++ b/core/sql/exp/exp_fixup.cpp
@@ -73,7 +73,7 @@ static void getCaseDatatypes(short attr_type1, Lng32 attr_len1, short &type_op1,
   //
   if ((type_op1 >= REC_MIN_INTERVAL) && (type_op1 <= REC_MAX_INTERVAL))
     {
-    if ( ((type_op2 >= REC_MIN_BINARY) && (type_op2 <= REC_MAX_BINARY)) ||
+    if ( ((type_op2 >= REC_MIN_BINARY_NUMERIC) && (type_op2 <= REC_MAX_BINARY_NUMERIC)) ||
          ((type_op2 >= REC_MIN_DECIMAL) && (type_op2 <= REC_MAX_DECIMAL)) ||
          (type_op2 == REC_DATETIME) ||
          ((type_op2 >= REC_MIN_INTERVAL) && (type_op2 <= REC_MAX_INTERVAL) &&
@@ -124,7 +124,7 @@ static void getCaseDatatypes(short attr_type1, Lng32 attr_len1, short &type_op1,
 
   if ((type_op2 >= REC_MIN_INTERVAL) && (type_op2 <= REC_MAX_INTERVAL)) 
     {
-    if ( ((type_op1 >= REC_MIN_BINARY) && (type_op1 <= REC_MAX_BINARY)) ||
+    if ( ((type_op1 >= REC_MIN_BINARY_NUMERIC) && (type_op1 <= REC_MAX_BINARY_NUMERIC)) ||
          ((type_op1 >= REC_MIN_DECIMAL) && (type_op1 <= REC_MAX_DECIMAL)) ||
          (type_op1 == REC_DATETIME) )
       {
@@ -564,8 +564,8 @@ const ArithInstruction ex_arith_clause::computeCaseIndex(OperatorTypeEnum op,
       // for binary numeric and interval datatypes, arith done only if scales
       // are the same and operation is addition or subtraction
       if (((op == ITM_PLUS) || (op == ITM_MINUS)) &&
-	  (((result->getDatatype() >= REC_MIN_BINARY) &&
-	    (result->getDatatype() <= REC_MAX_BINARY)) ||
+	  (((result->getDatatype() >= REC_MIN_BINARY_NUMERIC) &&
+	    (result->getDatatype() <= REC_MAX_BINARY_NUMERIC)) ||
 	   ((result->getDatatype() >= REC_MIN_INTERVAL) &&
 	    (result->getDatatype() <= REC_MAX_INTERVAL))))
 	{
@@ -698,6 +698,8 @@ const ex_comp_clause::CompInstrStruct ex_comp_clause::compInstrInfo[] =
     {ITM_ANY_COMP, REC_UNKNOWN,     REC_UNKNOWN,        instrAndText(ASCII_COMP)},
     {ITM_ANY_COMP, REC_UNKNOWN,     REC_UNKNOWN,        instrAndText(COMP_COMPLEX)},
 
+    {ITM_ANY_COMP, REC_UNKNOWN,     REC_UNKNOWN,        instrAndText(BINARY_COMP)},
+
     {ITM_EQUAL, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    instrAndText(EQ_BIN8S_BIN8S)},
     {ITM_EQUAL, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  instrAndText(EQ_BIN8U_BIN8U)},
 
@@ -1166,8 +1168,8 @@ const CompInstruction ex_comp_clause::computeCaseIndex(OperatorTypeEnum op,
       
       // for all numeric, datetime and interval datatypes, comparison done
       // only if scale is the same
-      if (((attr1->getDatatype() >= REC_MIN_BINARY) &&
-	   (attr1->getDatatype() <= REC_MAX_BINARY)) ||
+      if (((attr1->getDatatype() >= REC_MIN_BINARY_NUMERIC) &&
+	   (attr1->getDatatype() <= REC_MAX_BINARY_NUMERIC)) ||
 	  ((attr1->getDatatype() >= REC_DECIMAL_UNSIGNED) &&
 	   (attr1->getDatatype() <= REC_DECIMAL_LSE)) ||
 	  (attr1->getDatatype() == REC_DATETIME) ||
@@ -1187,6 +1189,17 @@ const CompInstruction ex_comp_clause::computeCaseIndex(OperatorTypeEnum op,
 	    }
 	} // numeric, datetime or interval types
     } // comparison supported 
+  else
+    {
+      if (((attr1->getDatatype() == REC_BINARY_STRING) ||
+           (attr1->getDatatype() == REC_VARBINARY_STRING)) &&
+          ((attr2->getDatatype() == REC_BINARY_STRING) ||
+           (attr2->getDatatype() == REC_VARBINARY_STRING)))
+        {
+          instruction = BINARY_COMP;
+          setInstrArrayIndex(findIndexIntoInstrArray(instruction));
+        }
+    }
 
   if (instruction == COMP_NOT_SUPPORTED)
     setInstrArrayIndex(-1);
@@ -1726,6 +1739,18 @@ const ex_conv_clause::ConvInstrStruct ex_conv_clause::convInstrInfo[] = {
   {REC_BOOLEAN,       REC_BYTE_F_ASCII,      instrAndText(CONV_BOOL_ASCII)},
   {REC_BOOLEAN,       REC_BYTE_V_ASCII,      instrAndText(CONV_BOOL_ASCII)},
 
+  {REC_BINARY_STRING, REC_BINARY_STRING,     instrAndText(CONV_BINARY_TO_BINARY)},
+  {REC_BINARY_STRING, REC_VARBINARY_STRING,  instrAndText(CONV_BINARY_TO_VARBINARY)},
+  {REC_BINARY_STRING, REC_UNKNOWN,           instrAndText(CONV_BINARY_TO_OTHER)},
+
+  {REC_VARBINARY_STRING,REC_BINARY_STRING,   instrAndText(CONV_VARBINARY_TO_BINARY)},
+  {REC_VARBINARY_STRING,REC_VARBINARY_STRING,instrAndText(CONV_VARBINARY_TO_VARBINARY)},
+  {REC_VARBINARY_STRING,REC_UNKNOWN,         instrAndText(CONV_VARBINARY_TO_OTHER)},
+
+  {REC_UNKNOWN,       REC_BINARY_STRING,     instrAndText(CONV_OTHER_TO_BINARY)},
+  {REC_UNKNOWN,       REC_VARBINARY_STRING,  instrAndText(CONV_OTHER_TO_VARBINARY)},
+
+
 };
 
 Lng32 ex_conv_clause::findIndexIntoInstrArray(ConvInstruction ci)
@@ -1894,8 +1919,32 @@ ConvInstruction ex_conv_clause::findInstruction(short sourceType, Lng32 sourceLe
   // See handling of dataConversionErrorFlag in exp_conv.cpp.
   if (instruction == CONV_NOT_SUPPORTED)
     {
-      if ((DFS2REC::isNumeric(sourceType)) &&
-          (DFS2REC::isTinyint(targetType)))
+      if (targetType == REC_BINARY_STRING)
+        {
+          instruction = CONV_OTHER_TO_BINARY;
+          
+          setInstrArrayIndex(findIndexIntoInstrArray(instruction));
+        }
+      else if (targetType == REC_VARBINARY_STRING)
+        {
+          instruction = CONV_OTHER_TO_VARBINARY;
+          
+          setInstrArrayIndex(findIndexIntoInstrArray(instruction));
+        }
+      else if (sourceType == REC_BINARY_STRING)
+        {
+          instruction = CONV_BINARY_TO_OTHER;
+          
+          setInstrArrayIndex(findIndexIntoInstrArray(instruction));
+        }
+      else if (sourceType == REC_VARBINARY_STRING)
+        {
+          instruction = CONV_VARBINARY_TO_OTHER;
+          
+          setInstrArrayIndex(findIndexIntoInstrArray(instruction));
+        }
+      else if ((DFS2REC::isNumeric(sourceType)) &&
+               (DFS2REC::isTinyint(targetType)))
         {
           if (targetType == REC_BIN8_SIGNED)
             {
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index b04995d..22b8690 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -228,6 +228,7 @@ ExFunctionInetNtoa::ExFunctionInetNtoa(){};
 ExFunctionSoundex::ExFunctionSoundex(){};
 ExFunctionAESEncrypt::ExFunctionAESEncrypt(){};
 ExFunctionAESDecrypt::ExFunctionAESDecrypt(){};
+ExFunctionBase64EncDec::ExFunctionBase64EncDec(){};
 
 ExFunctionAscii::ExFunctionAscii(OperatorTypeEnum oper_type,
 				 Attributes ** attr, Space * space)
@@ -309,6 +310,16 @@ ExFunctionAESDecrypt::ExFunctionAESDecrypt(OperatorTypeEnum oper_type,
 {
 };
 
+ExFunctionBase64EncDec::ExFunctionBase64EncDec(OperatorTypeEnum oper_type,
+                                               Attributes ** attr, 
+                                               Space * space, 
+                                               NABoolean isEncode)
+     : ex_function_clause(oper_type, 2, attr, space), 
+      isEncode_(isEncode)
+{
+};
+
+
 ExFunctionConvertHex::ExFunctionConvertHex(OperatorTypeEnum oper_type,
 					   Attributes ** attr, Space * space)
      : ex_function_clause(oper_type, 2, attr, space)
@@ -5059,9 +5070,8 @@ ex_expr::exp_return_type ex_function_hivehash::eval(char *op_data[],
     // operand is a null value. All null values hash to the same hash value. 
     hashValue = 0; // hive semantics: hash(NULL) = 0
   } else
-  if ( (DFS2REC::isSQLVarChar(srcOp->getDatatype()) || 
-        DFS2REC::isANSIVarChar(srcOp->getDatatype())) && 
-       getOperand(1)->getVCIndicatorLength() > 0 ) 
+  if ( (DFS2REC::isAnyVarChar(srcOp->getDatatype())) &&
+      getOperand(1)->getVCIndicatorLength() > 0 )
   {
       length = srcOp->getLength(op_data[-MAX_OPERANDS + 1]);
       hashValue = ex_function_hivehash::hashForCharType(op_data[1],length);
@@ -5070,7 +5080,7 @@ ex_expr::exp_return_type ex_function_hivehash::eval(char *op_data[],
       length = srcOp->getLength();
       hashValue = ex_function_hivehash::hashForCharType(op_data[1],length);
   } else
-  if ( DFS2REC::isBinary(srcOp->getDatatype()) ) {
+  if ( DFS2REC::isBinaryNumeric(srcOp->getDatatype()) ) {
       hashValue = *(ULng32*)(op_data[1]);
   } // TBD: other SQ types
 
@@ -9051,3 +9061,38 @@ aes_decrypt_error:
 
   return ex_expr::EXPR_ERROR;
 }
+
+ex_expr::exp_return_type ExFunctionBase64EncDec::eval(char * op_data[],
+                                                      CollHeap *heap,
+                                                      ComDiagsArea **diagsArea)
+{
+  Attributes *tgt = getOperand(0);
+
+  Lng32 source_len = getOperand(1)->getLength(op_data[-MAX_OPERANDS + 1]);
+  unsigned char * source = (unsigned char *)op_data[1];
+
+  char * result = op_data[0];
+
+  Int32 retLen = -1;
+  if (isEncode_)
+    {
+
+      retLen = str_encode_base64(source, source_len, result, tgt->getLength());
+    }
+  else
+    {
+      retLen = str_decode_base64(source, source_len, result, tgt->getLength());
+    }
+
+  if (retLen < 0)
+    {
+      ExRaiseSqlError(heap, diagsArea, EXE_OPENSSL_ERROR);
+      *(*diagsArea) << DgString0("AES_DECRYPT FUNCTION");
+      
+      return ex_expr::EXPR_ERROR;
+    }
+
+  tgt->setVarLength(retLen, op_data[-MAX_OPERANDS]);
+
+  return ex_expr::EXPR_OK;
+}
diff --git a/core/sql/exp/exp_function.h b/core/sql/exp/exp_function.h
index c67cf84..6b63236 100644
--- a/core/sql/exp/exp_function.h
+++ b/core/sql/exp/exp_function.h
@@ -1095,7 +1095,40 @@ private:
   Int32 args_num;
 };
 
-class  ExFunctionTokenStr : public ex_function_clause {
+class ExFunctionBase64EncDec : public ex_function_clause {
+public:
+  ExFunctionBase64EncDec(OperatorTypeEnum oper_type,
+                                    Attributes ** attr,
+                                    Space * space,
+                                    NABoolean isEncode);
+  ExFunctionBase64EncDec();
+
+  ex_expr::exp_return_type eval(char *op_datap[], CollHeap*,
+                                           ComDiagsArea** = 0);
+  //  long pack(void *);
+
+  // ---------------------------------------------------------------------
+  // Redefinition of methods inherited from NAVersionedObject.
+  // ---------------------------------------------------------------------
+  virtual unsigned char getClassVersionID()
+  {
+    return 1;
+  }
+
+  virtual void populateImageVersionIDArray()
+  {
+    setImageVersionID(2,getClassVersionID());
+    ex_function_clause::populateImageVersionIDArray();
+  }
+
+  virtual short getClassSize() { return (short)sizeof(*this); }
+
+  // ---------------------------------------------------------------------
+private:
+  NABoolean isEncode_; // TRUE, encode. FALSE, decode
+};
+
+class ExFunctionTokenStr : public ex_function_clause {
 public:
   ExFunctionTokenStr(OperatorTypeEnum oper_type,
 				Attributes ** attr,
diff --git a/core/sql/exp/exp_tuple_desc.cpp b/core/sql/exp/exp_tuple_desc.cpp
index 2f6ac8c..de086b2 100644
--- a/core/sql/exp/exp_tuple_desc.cpp
+++ b/core/sql/exp/exp_tuple_desc.cpp
@@ -368,10 +368,9 @@ Int16 ExpTupleDesc::computeOffsets(UInt32 num_attrs,        /* IN  */
             if (attrs[i]->getVCIndicatorLength() > 0)
               attrs[i]->setVCIndicatorLength(VC_ACTUAL_LENGTH); 
 	    
-            // all fields except char/varchar fields may need alignment
+            // all fields except char/varchar/binary fields may need alignment
             // at runtime.
-            if ((attrs[i]->getDatatype() < REC_MIN_CHARACTER) ||
-                (attrs[i]->getDatatype() > REC_MAX_CHARACTER))
+            if (NOT DFS2REC::isAnyCharacter(attrs[i]->getDatatype()))
               attrs[i]->needDataAlignment();
 	    
             if (varchar_seen)
@@ -444,10 +443,9 @@ Int16 ExpTupleDesc::computeOffsets(UInt32 num_attrs,        /* IN  */
             if (attrs[i]->getVCIndicatorLength() > 0)
               attrs[i]->setVCIndicatorLength( VC_ACTUAL_LENGTH ); 
 	    
-            // all fields except char/varchar fields may need alignment
+            // all fields except char/varchar/binary fields may need alignment
             // at runtime.
-            if ((attrs[i]->getDatatype() < REC_MIN_CHARACTER) ||
-                (attrs[i]->getDatatype() > REC_MAX_CHARACTER))
+            if (NOT DFS2REC::isAnyCharacter(attrs[i]->getDatatype()))
               attrs[i]->needDataAlignment();
 	    
             if (attrs[i]->getNullFlag())
@@ -649,10 +647,9 @@ Int16 ExpTupleDesc::computeOffsets(UInt32 num_attrs,        /* IN  */
             nullableCnt++;
           }
 
-          // all fields except char/varchar fields may need to be aligned
+          // all fields except char/varchar/binary fields may need to be aligned
           // at runtime
-          if ((attrs[i]->getDatatype() < REC_MIN_CHARACTER) ||
-              (attrs[i]->getDatatype() > REC_MAX_CHARACTER))
+          if (NOT DFS2REC::isAnyCharacter(attrs[i]->getDatatype()))
             attrs[i]->needDataAlignment();
 
           // Handle variable length fields. Some varchars (aggregates)
diff --git a/core/sql/generator/GenExpGenerator.cpp b/core/sql/generator/GenExpGenerator.cpp
index fc7d39e..00ca154 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -3277,8 +3277,9 @@ ItemExpr * ExpGenerator::generateKeyCast(const ValueId vid,
 	    // whose length is equal to the max length of varchar.
 	    // Remove the UPSHIFT attr from the target. We don't want
 	    // to upshift data for key lookup.
+
 	    if ((keycol->getValueId().getType().getVarLenHdrSize() > 0) ||
-		(char_t.isUpshifted()))
+                (char_t.isUpshifted()))
 	      {
 		if (!CollationInfo::isSystemCollation(char_t.getCollation()))
 		{
@@ -3295,7 +3296,7 @@ ItemExpr * ExpGenerator::generateKeyCast(const ValueId vid,
                                  char_t.getCoercibility()
                                  );
                     }
-                  else
+                  else if (DFS2REC::isCharacterString(keycol->getValueId().getType().getFSDatatype()))
                     {
                       targetType = new(wHeap())
                         SQLChar(wHeap(), CharLenInfo(char_t.getStrCharLimit(), char_t.getDataStorageSize()),
@@ -3308,6 +3309,15 @@ ItemExpr * ExpGenerator::generateKeyCast(const ValueId vid,
                                 char_t.getCoercibility()
                                 );
                     }
+                  else if (DFS2REC::isBinaryString(keycol->getValueId().getType().getFSDatatype()))                  
+                    {
+                      targetType = new(wHeap())
+                        SQLBinaryString(wHeap(),
+                                        keycol->getValueId().getType().getNominalSize(),
+                                        keycol->getValueId().getType().supportsSQLnull(),
+                                        FALSE
+                                        );                
+                    }
 		}
 	      }
 	  }
diff --git a/core/sql/generator/GenFastTransport.cpp b/core/sql/generator/GenFastTransport.cpp
index f069412..1c21082 100644
--- a/core/sql/generator/GenFastTransport.cpp
+++ b/core/sql/generator/GenFastTransport.cpp
@@ -116,9 +116,9 @@ static ItemExpr *CreateCastExpr(ItemExpr &source, const NAType &target,
 }
 
 int CreateAllCharsExpr(const NAType &formalType,
-                               ItemExpr &actualValue,
-                               CmpContext *cmpContext,
-                               ItemExpr *&newExpr)
+                       ItemExpr &actualValue,
+                       CmpContext *cmpContext,
+                       ItemExpr *&newExpr)
 {
   int result = 0;
   NAMemory *h = cmpContext->statementHeap();
@@ -127,7 +127,7 @@ int CreateAllCharsExpr(const NAType &formalType,
   Lng32 maxLength = GetDisplayLength(formalType);
   maxLength = MAXOF(maxLength, 1);
 
-  if (formalType.getTypeQualifier() != NA_CHARACTER_TYPE )
+  if (NOT DFS2REC::isCharacterString(formalType.getFSDatatype()))
   {
     typ = new (h) SQLVarChar(h, maxLength);
   }
@@ -145,8 +145,6 @@ int CreateAllCharsExpr(const NAType &formalType,
   }
 
   newExpr = CreateCastExpr(actualValue, *typ, cmpContext);
-
-
   if (newExpr == NULL)
   {
     result = -1;
@@ -309,11 +307,10 @@ static short ft_codegen(Generator *generator,
   //    if 1, do error check and return error.
   //    if 2, do error check and ignore row, if error
   //    if 3, insert null if an error occurs
-  Lng32 hiveInsertErrMode = 0;
+  Lng32 hiveInsertErrMode = CmpCommon::getDefaultNumeric(HIVE_INSERT_ERROR_MODE);
   if ((fastExtract) && (fastExtract->isHiveInsert()) &&
       (fastExtract->getHiveTableDesc()) &&
-      (fastExtract->getHiveTableDesc()->getNATable()) &&
-      ((hiveInsertErrMode = CmpCommon::getDefaultNumeric(HIVE_INSERT_ERROR_MODE)) > 0))
+      (fastExtract->getHiveTableDesc()->getNATable()))
     {
       hiveNATable = fastExtract->getHiveTableDesc()->getNATable();
       hiveNAColArray = &hiveNATable->getNAColumnArray();
@@ -336,19 +333,24 @@ static short ft_codegen(Generator *generator,
 
     // Hive insert converts child data into string format and inserts
     // it into target table.
-    // If child type can into an error during conversion, then
+    // If child type can run into an error during conversion, then
     // add a Cast to convert from child type to target type before
     // converting to string format to be inserted.
     if (hiveNAColArray)
       {
+        ItemExpr *newExpr = NULL;
         const NAColumn *hiveNACol = (*hiveNAColArray)[i];
         const NAType *hiveNAType = hiveNACol->getType();
-        // if tgt type was a hive 'string', do not return a conversion err
-        if ((lmExpr->getValueId().getType().errorsCanOccur(*hiveNAType)) &&
-            (NOT ((DFS2REC::isSQLVarChar(hiveNAType->getFSDatatype())) &&
-                  (((SQLVarChar*)hiveNAType)->wasHiveString()))))
+        const NAType &lmExprType = lmExpr->getValueId().getType();
+        // if tgt type was a hive 'string' of hive 'binary', 
+        // do not return a conversion err
+        if ((hiveInsertErrMode > 0) &&
+            (lmExprType.errorsCanOccur(*hiveNAType)) &&
+            (NOT (((DFS2REC::isSQLVarChar(hiveNAType->getFSDatatype())) &&
+                   (((SQLVarChar*)hiveNAType)->wasHiveString())) ||
+                  (DFS2REC::isBinaryString(hiveNAType->getFSDatatype())))))
           {
-            ItemExpr *newExpr = 
+            newExpr = 
               new(generator->wHeap()) Cast(lmExpr, hiveNAType);
             newExpr = newExpr->bindNode(generator->getBindWA());
             if (!newExpr || generator->getBindWA()->errStatus())
@@ -362,6 +364,39 @@ static short ft_codegen(Generator *generator,
             lmExpr = newExpr;
             formalType = (NAType*)hiveNAType;
           }
+
+        // if targettype is binary datatype, then encode_base64 before
+        // inserting it.
+        if (DFS2REC::isBinaryString(hiveNAType->getFSDatatype()))
+          {
+            // convert value to string format before encoding.
+            if (formalType->getTypeQualifier() != NA_CHARACTER_TYPE)
+              {
+                Lng32 maxLength = GetDisplayLength(*formalType);
+                maxLength = MAXOF(maxLength, 1);
+
+                NAType * typ = new(generator->wHeap()) SQLVarChar(HEAP, 
+                                                                  maxLength);
+                newExpr = 
+                  new(generator->wHeap()) Cast(lmExpr, typ);
+                newExpr = newExpr->bindNode(generator->getBindWA());
+                if (!newExpr || generator->getBindWA()->errStatus())
+                  {
+                    GenExit();
+                  }
+                lmExpr = newExpr;
+              }
+
+            newExpr = new(generator->wHeap()) BuiltinFunction
+              (ITM_ENCODE_BASE64,
+               generator->wHeap(), 1, lmExpr);
+            newExpr = newExpr->bindNode(generator->getBindWA());
+            if (!newExpr || generator->getBindWA()->errStatus())
+              {
+                GenExit();
+              }
+            lmExpr = newExpr;
+          }
       }
 
     res = CreateAllCharsExpr(*formalType, // [IN] Child output type
diff --git a/core/sql/generator/GenItemFunc.cpp b/core/sql/generator/GenItemFunc.cpp
index ac6d21c..6d54d7c 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -109,6 +109,7 @@ short BuiltinFunction::codeGen(Generator * generator)
         {
           case CharInfo::ISO88591:
           case CharInfo::UTF8:
+          case CharInfo::BINARY:
           // case CharInfo::SJIS:  // Uncomment this if we ever support SJIS
            function_clause =
                new(generator->getSpace()) ex_like_clause_char(getOperatorType()
@@ -349,6 +350,7 @@ short BuiltinFunction::codeGen(Generator * generator)
         {
           case CharInfo::ISO88591:
           case CharInfo::UTF8:
+          case CharInfo::BINARY:
           // case CharInfo::SJIS:  // Uncomment this if we ever support SJIS
 	   function_clause = new(generator->getSpace()) 
 		ex_function_substring(getOperatorType(), 
@@ -409,6 +411,7 @@ short BuiltinFunction::codeGen(Generator * generator)
         {
           case CharInfo::ISO88591:
           case CharInfo::UTF8:
+          case CharInfo::BINARY:
           // case CharInfo::SJIS: // Uncomment this if we ever support SJIS
 	    function_clause = new(generator->getSpace()) 
 		ex_function_char_length(ITM_CHAR_LENGTH, attr, space);
@@ -443,6 +446,7 @@ short BuiltinFunction::codeGen(Generator * generator)
         {
           case CharInfo::ISO88591:
           case CharInfo::UTF8:
+          case CharInfo::BINARY:
           // case CharInfo::SJIS: // Uncomment this if we ever support SJIS
 	   function_clause = new(generator->getSpace()) 
              ex_function_position(ITM_POSITION, attr, space,
@@ -715,12 +719,25 @@ short BuiltinFunction::codeGen(Generator * generator)
       break;
     }
 
+    case ITM_ENCODE_BASE64:
+    case ITM_DECODE_BASE64:
+      {
+        function_clause =
+          new(generator->getSpace()) ExFunctionBase64EncDec
+          (getOperatorType(),
+           attr,
+           space,
+           (getOperatorType() == ITM_ENCODE_BASE64 ? TRUE : FALSE));
+      }
+      break;
+
     case ITM_SPLIT_PART:
     {
       function_clause = 
             new (generator->getSpace()) ex_function_split_part(getOperatorType(), attr, space);
       break;
     }
+
     default:
       break;
     }
@@ -1982,6 +1999,7 @@ short Trim::codeGen(Generator * generator)
   {
     case CharInfo::ISO88591:
     case CharInfo::UTF8:
+    case CharInfo::BINARY:
     // case CharInfo::SJIS: // Uncomment this if we ever support SJIS
       function_clause = new(generator->getSpace()) 
 		ex_function_trim_char(ITM_TRIM,
diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp
index d6619f9..ec8e005 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -8444,16 +8444,15 @@ ItemExpr * BiRelat::preCodeGen(Generator * generator)
 
       CMPASSERT(coll1==coll2);
 
-	  if (CollationInfo::isSystemCollation(coll1))
-	  {
-	    setCollationEncodeComp(TRUE);
-
-	    {
+      if (CollationInfo::isSystemCollation(coll1))
+        {
+          setCollationEncodeComp(TRUE);
+          {
 
-	      ItemExpr * newIe1 = child(0);
-	      ItemExpr * newIe2 = child(1);
+            ItemExpr * newIe1 = child(0);
+            ItemExpr * newIe2 = child(1);
 	      
-	      if (! (cType1 == cType2)) 
+            if (! (cType1 == cType2)) 
 	      {
 
 		NAType *resultType ;
@@ -8461,144 +8460,146 @@ ItemExpr * BiRelat::preCodeGen(Generator * generator)
 		Lng32 Prec= MAXOF(cType1.getStrCharLimit(), cType2.getStrCharLimit());
         	     
 		if (len != cType1.getMaxLenInBytesOrNAWChars()) 
-		{
-		  if (DFS2REC::isAnyVarChar(cType1.getFSDatatype()))
-		  {
-		    resultType = new (generator->wHeap())
-		      SQLVarChar(generator->wHeap(), CharLenInfo(Prec, len),
-				  cType1.supportsSQLnull(), 
-				  cType1.isUpshifted(),
-				  cType1.isCaseinsensitive(),
-				  cType1.getCharSet(),
-				  cType1.getCollation(),
-				  cType1.getCoercibility()
-				 );
-		  }
-		  else
-		  {
-		    resultType = new (generator->wHeap())
-		      SQLChar(generator->wHeap(), CharLenInfo(Prec, len),
-				  cType1.supportsSQLnull(), 
-				  cType1.isUpshifted(),
-				  cType1.isCaseinsensitive(),
-				  FALSE,
-				  cType1.getCharSet(),
-				  cType1.getCollation(),
-				  cType1.getCoercibility()
-				 );
-		  }
-
-		  newIe1 = new(generator->wHeap()) Cast(newIe1,resultType);
-		}
+                  {
+                    if (DFS2REC::isAnyVarChar(cType1.getFSDatatype()))
+                      {
+                        resultType = new (generator->wHeap())
+                          SQLVarChar( generator->wHeap(),
+                                      CharLenInfo(Prec, len),
+                                      cType1.supportsSQLnull(), 
+                                      cType1.isUpshifted(),
+                                      cType1.isCaseinsensitive(),
+                                      cType1.getCharSet(),
+                                      cType1.getCollation(),
+                                      cType1.getCoercibility()
+                                      );
+                      }
+                    else
+                      {
+                        resultType = new (generator->wHeap())
+                          SQLChar( generator->wHeap(),
+                                   CharLenInfo(Prec, len),
+                                   cType1.supportsSQLnull(), 
+                                   cType1.isUpshifted(),
+                                   cType1.isCaseinsensitive(),
+                                   FALSE,
+                                   cType1.getCharSet(),
+                                   cType1.getCollation(),
+                                   cType1.getCoercibility()
+                                   );
+                      }
+
+                    newIe1 = new(generator->wHeap()) Cast(newIe1,resultType);
+                  }
 
 		if (len != cType2.getMaxLenInBytesOrNAWChars()) 
-		{
-		  if (DFS2REC::isAnyVarChar(cType2.getFSDatatype()))
-		  {
-		    resultType = new (generator->wHeap())
-		      SQLVarChar(generator->wHeap(), CharLenInfo(Prec, len),
-				  cType2.supportsSQLnull(), 
-				  cType2.isUpshifted(),
-				  cType2.isCaseinsensitive(),
-				  cType2.getCharSet(),
-				  cType2.getCollation(),
-				  cType2.getCoercibility()
-				 );
-		  }
-		  else
-		  {
-		    resultType = new (generator->wHeap())
-		      SQLChar(generator->wHeap(), CharLenInfo(Prec, len),
-				  cType2.supportsSQLnull(), 
-				  cType2.isUpshifted(),
-				  cType2.isCaseinsensitive(),
-				  FALSE,
-				  cType2.getCharSet(),
-				  cType2.getCollation(),
-				  cType2.getCoercibility()
-				 );
-		  }
-
-		  newIe2 = new(generator->wHeap()) Cast(newIe2,resultType);
-		}
+                  {
+                    if (DFS2REC::isAnyVarChar(cType2.getFSDatatype()))
+                      {
+                        resultType = new (generator->wHeap())
+                          SQLVarChar( generator->wHeap(),
+                                      CharLenInfo(Prec, len),
+                                      cType2.supportsSQLnull(), 
+                                      cType2.isUpshifted(),
+                                      cType2.isCaseinsensitive(),
+                                      cType2.getCharSet(),
+                                      cType2.getCollation(),
+                                      cType2.getCoercibility()
+                                      );
+                      }
+                    else
+                      {
+                        resultType = new (generator->wHeap())
+                          SQLChar( generator->wHeap(),
+                                   CharLenInfo(Prec, len),
+                                   cType2.supportsSQLnull(), 
+                                   cType2.isUpshifted(),
+                                   cType2.isCaseinsensitive(),
+                                   FALSE,
+                                   cType2.getCharSet(),
+                                   cType2.getCollation(),
+                                   cType2.getCoercibility()
+                                   );
+                      }
+
+                    newIe2 = new(generator->wHeap()) Cast(newIe2,resultType);
+                  }
 	      }
 
-	      ItemExpr * newEncode;
+            ItemExpr * newEncode;
 	      
-	      newEncode = 
-		    new(generator->wHeap()) 
-		    CompEncode(newIe1,FALSE, -1, CollationInfo::Compare);
-
-	      newEncode->bindNode(generator->getBindWA());
-	      newEncode = newEncode->preCodeGen(generator);
-	      if (!newEncode)
-		return NULL;
-	      setChild(0, newEncode);
-
-
-	      newEncode = 
-		    new(generator->wHeap()) 
-		    CompEncode(newIe2, FALSE, -1,CollationInfo::Compare);
-
-	      newEncode->bindNode(generator->getBindWA());
-	      newEncode = newEncode->preCodeGen(generator);
-	      if (!newEncode)
-		return NULL;
-	      setChild(1, newEncode);
-	    }
+            newEncode = 
+              new(generator->wHeap()) 
+              CompEncode(newIe1,FALSE, -1, CollationInfo::Compare);
 
-	  }
-	  else
-	  {
-	     // update both operands if case insensitive comparions
-	     // are to be done.
+            newEncode->bindNode(generator->getBindWA());
+            newEncode = newEncode->preCodeGen(generator);
+            if (!newEncode)
+              return NULL;
+            setChild(0, newEncode);
 
-	    NABoolean doCIcomp =
-	      ((cType1.isCaseinsensitive()) && (cType2.isCaseinsensitive()));
+            newEncode = 
+              new(generator->wHeap()) 
+              CompEncode(newIe2, FALSE, -1,CollationInfo::Compare);
 
-	    ItemExpr * newChild = NULL;
-	    if ((doCIcomp) &&
-		(NOT cType1.isUpshifted()))
-	      {
-		newChild = child(0);
+            newEncode->bindNode(generator->getBindWA());
+            newEncode = newEncode->preCodeGen(generator);
+            if (!newEncode)
+              return NULL;
+            setChild(1, newEncode);
+          }
 
-		// Add UPPER except if it is NULL constant value.
-		if (newChild->getOperatorType() != ITM_CONSTANT || !((ConstValue *)newChild)->isNull())
-		    newChild = new (generator->wHeap()) Upper(newChild);
+        }
+      else
+        {
+          // update both operands if case insensitive comparions
+          // are to be done.
 
-		newChild = newChild->bindNode(generator->getBindWA());
-		if (! newChild || generator->getBindWA()->errStatus())
-		  return NULL;
+          NABoolean doCIcomp =
+            ((cType1.isCaseinsensitive()) && (cType2.isCaseinsensitive()));
 
-		newChild = newChild->preCodeGen(generator);
-		if (! newChild)
-		  return NULL;
+          ItemExpr * newChild = NULL;
+          if ((doCIcomp) &&
+              (NOT cType1.isUpshifted()))
+            {
+              newChild = child(0);
 
-		setChild(0, newChild);
-	      }
+              // Add UPPER except if it is NULL constant value.
+              if (newChild->getOperatorType() != ITM_CONSTANT || !((ConstValue *)newChild)->isNull())
+                newChild = new (generator->wHeap()) Upper(newChild);
 
-	    if ((doCIcomp) &&
-		(NOT cType2.isUpshifted()))
-	      {
-		newChild = child(1);
+              newChild = newChild->bindNode(generator->getBindWA());
+              if (! newChild || generator->getBindWA()->errStatus())
+                return NULL;
 
-		// Add UPPER except if it is NULL constant value.
-		if (newChild->getOperatorType() != ITM_CONSTANT || !((ConstValue *)newChild)->isNull())
-		    newChild = new (generator->wHeap()) Upper(newChild);
+              newChild = newChild->preCodeGen(generator);
+              if (! newChild)
+                return NULL;
 
-		newChild = newChild->bindNode(generator->getBindWA());
-		if (! newChild || generator->getBindWA()->errStatus())
-		  return NULL;
+              setChild(0, newChild);
+            }
 
-		newChild = newChild->preCodeGen(generator);
-		if (! newChild)
-		  return NULL;
+          if ((doCIcomp) &&
+              (NOT cType2.isUpshifted()))
+            {
+              newChild = child(1);
 
-		setChild(1, newChild);
-	      }
-	    }
-	  }
+              // Add UPPER except if it is NULL constant value.
+              if (newChild->getOperatorType() != ITM_CONSTANT || !((ConstValue *)newChild)->isNull())
+                newChild = new (generator->wHeap()) Upper(newChild);
 
+              newChild = newChild->bindNode(generator->getBindWA());
+              if (! newChild || generator->getBindWA()->errStatus())
+                return NULL;
+
+              newChild = newChild->preCodeGen(generator);
+              if (! newChild)
+                return NULL;
+
+              setChild(1, newChild);
+            }
+        }
+    }
 
   // following is for simple types.
   const NAType &type1B =
diff --git a/core/sql/generator/GenRelMisc.cpp b/core/sql/generator/GenRelMisc.cpp
index ca2e4f3..dfc7400 100644
--- a/core/sql/generator/GenRelMisc.cpp
+++ b/core/sql/generator/GenRelMisc.cpp
@@ -3996,6 +3996,20 @@ short TupleList::codeGen(Generator * generator)
 	  ItemExpr * childNode = (ItemExpr *) tupleTree[j];
           if (castTo)
           {
+            const NAType &srcType = childNode->getValueId().getType();
+            const NAType &tgtType = castNode->getValueId().getType();
+
+            if ((hiveTextInsert()) &&
+                (DFS2REC::isBinaryString(tgtType.getFSDatatype())) &&
+                (NOT DFS2REC::isAnyCharacter(srcType.getFSDatatype())))
+              {
+                childNode = new(bindWA->wHeap()) 
+                  ZZZBinderFunction(ITM_TO_CHAR, childNode);
+                childNode = childNode->bindNode(bindWA);
+                if (bindWA->errStatus())
+                  return -1;            
+              }
+
 	    // When we have ins/upd target cols which are
 	    // MP NCHAR in MX-NSK-Rel1 (i.e., SINGLE-byte),
 	    // and the source was from a Tuple/TupleList,
diff --git a/core/sql/generator/GenRelScan.cpp b/core/sql/generator/GenRelScan.cpp
index 2af324b..d4ecec5 100644
--- a/core/sql/generator/GenRelScan.cpp
+++ b/core/sql/generator/GenRelScan.cpp
@@ -255,6 +255,7 @@ int HbaseAccess::createAsciiColAndCastExpr(Generator * generator,
     }
 
   asciiValue = new (h) NATypeToItem(asciiType->newCopy(h));
+
   castValue = new(h) Cast(asciiValue, newGivenType);
   ((Cast*)castValue)->setSrcIsVarcharPtr(TRUE);
 
@@ -264,6 +265,9 @@ int HbaseAccess::createAsciiColAndCastExpr(Generator * generator,
   if (newGivenType->getTypeQualifier() == NA_INTERVAL_TYPE)
     ((Cast*)castValue)->setAllowSignInInterval(TRUE);
 
+  if (DFS2REC::isBinaryString(givenType.getFSDatatype()))
+    castValue = new(h) BuiltinFunction(ITM_DECODE_BASE64, h, 1, castValue);
+
   if (castValue && asciiValue)
     result = 1;
 
@@ -739,7 +743,7 @@ R4 is an aligned format row, tupp index 2 in work_cri_desc.
 Each column is of type as defined in hive metadata.
 Columns that are present only in the output expression (i.e. are not
 present in selection predicate) are placed in this tupp.
-This tupp is populated by project_convert_expr, which is called 
+This tupp is populated by move_cols_convert_expr, which is called 
 only if the row returns TRUE for the selection predicate. The goal is 
 to not convert columns for rows that do not pass the selection predicate.
 
@@ -814,7 +818,7 @@ short FileScan::codeGenForHive(Generator * generator)
   ex_expr *executor_expr = 0;
   ex_expr *proj_expr = 0;
   ex_expr *convert_expr = 0;
-  ex_expr *project_convert_expr = 0;
+  ex_expr *move_cols_convert_expr = 0;
 
   // set flag to enable pcode for indirect varchar
   NABoolean vcflag = exp_gen->handleIndirectVC();
@@ -1006,7 +1010,7 @@ short FileScan::codeGenForHive(Generator * generator)
       projectOnlyTuppIndex,                 // [IN] target tupp index
       hdfsRowFormat,                        // [IN] target tuple format
       projectOnlyColsRecLength,             // [OUT] target tuple length
-      &project_convert_expr,                // [OUT] move expression
+      &move_cols_convert_expr,                // [OUT] move expression
       &tuple_desc,                     // [optional OUT] target tuple desc
       ExpTupleDesc::LONG_FORMAT,       // [optional IN] target desc format
       NULL,
@@ -1331,7 +1335,7 @@ if (hTabStats->isOrcFile())
 		   executor_expr,
 		   proj_expr,
 		   convert_expr,
-                   project_convert_expr,
+                   move_cols_convert_expr,
 		   hdfsVals.entries(),      // size of convertSkipList
 		   convertSkipList,
 		   hdfsHostName, 
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index 7c07652..9ed8078 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -665,10 +665,12 @@ void ItemExpr::bindChildren(BindWA *bindWA)
   Int32 savedCurrChildNo = currChildNo();
   for (Int32 i = 0; i < getArity(); i++, currChildNo()++) {
    
-    ItemExpr *boundExpr = child(i)->bindNode(bindWA);
-    if (bindWA->errStatus()) return;
-    child(i) = boundExpr;
-      
+    if (child(i) != NULL) {
+      ItemExpr *boundExpr = child(i)->bindNode(bindWA);
+      if (bindWA->errStatus()) 
+        return;
+      child(i) = boundExpr;
+    }
       
   }
   currChildNo() = savedCurrChildNo;
@@ -2226,6 +2228,13 @@ static ItemExpr * ItemExpr_handleIncompatibleComparison(
     return NULL;  // error
   }
 
+  // binary types can be compared with all other datatypes
+  if ((DFS2REC::isBinaryString(type1.getFSDatatype())) ||
+      (DFS2REC::isBinaryString(type2.getFSDatatype())))
+    {
+      return thisPtr;
+    }
+ 
   // Check if we are to allow certain incompatible comparisons
   if (CmpCommon::getDefault(ALLOW_INCOMPATIBLE_OPERATIONS) == DF_ON)
   {
@@ -3424,6 +3433,8 @@ ItemExpr *BuiltinFunction::bindNode(BindWA *bindWA)
 
     case ITM_AES_ENCRYPT:
     case ITM_AES_DECRYPT:
+    case ITM_ENCODE_BASE64:
+    case ITM_DECODE_BASE64:
       break;
     default:
       {
@@ -4416,6 +4427,28 @@ ItemExpr *Trim::bindNode(BindWA *bindWA)
   if (bindWA->errStatus()) 
     return this;
 
+  // child0 is trim operand.
+  // child1 is expression to be trimmed.
+  // if trim operand is null, set it based on trim expression.
+  // if trim expr is binary string, trim operand becomes '\0'.
+  // Otherwise it becomes ' '
+  if (child(0) == NULL)
+    {
+      const NAType &type1 = 
+        child(1)->castToItemExpr()->getValueId().getType();
+       
+      ItemExpr * trimOper = NULL;
+      if (DFS2REC::isBinaryString(type1.getFSDatatype()))
+        trimOper = new (PARSERHEAP()) SystemLiteral(NAString('\0'), CharInfo::ISO88591);
+      else
+        trimOper = new (PARSERHEAP()) SystemLiteral(" ", WIDE_(" "));
+
+      trimOper = trimOper->bindNode(bindWA);
+      if (bindWA->errStatus())
+        return this;
+      setChild(0, trimOper);
+    }
+
   if (CmpCommon::getDefault(ALLOW_INCOMPATIBLE_OPERATIONS) == DF_ON)
     {
       // if argument is numeric, convert it to string.
@@ -5790,10 +5823,10 @@ ItemExpr *BiArith::bindNode(BindWA *bindWA)
       ((CmpCommon::getDefault(ALLOW_INCOMPATIBLE_OPERATIONS) == DF_ON) &&
        (((naType0->getTypeQualifier() == NA_INTERVAL_TYPE) &&
          (naType1->getTypeQualifier() == NA_INTERVAL_TYPE)) ||
-        ((naType0->getTypeQualifier() == NA_CHARACTER_TYPE) &&
+        ((DFS2REC::isCharacterString(naType0->getFSDatatype())) &&
          (naType1->getTypeQualifier() == NA_NUMERIC_TYPE)) ||
         ((naType0->getTypeQualifier() == NA_NUMERIC_TYPE) &&
-         (naType1->getTypeQualifier() == NA_CHARACTER_TYPE)) ||
+         (DFS2REC::isCharacterString(naType1->getFSDatatype()))) ||
         ((naType0->getTypeQualifier() == NA_DATETIME_TYPE) &&
          (naType1->getTypeQualifier() == NA_DATETIME_TYPE)))))
     {
@@ -6489,6 +6522,10 @@ ItemExpr *Cast::bindNode(BindWA *bindWA)
       ((CharType *)getType())->isUpshifted())
     boundExpr = applyUpperToSource(bindWA, boundExpr, 0);
 
+  // currently const folding is not being done if cast to BINARY datatype
+  if (DFS2REC::isBinaryString(getType()->getFSDatatype()))
+    setConstFoldingDisabled(TRUE);
+
 // COMMENTED OUT -- causing problems in Generator key-building --	     ##
 // FIX LATER -- for now, just catch this problem at run-time instead of compile,
 // via Executor error 8421 ...
@@ -7307,8 +7344,7 @@ ItemExpr *Case::bindNode(BindWA *bindWA)
             {
               // do nothing
             }
-          else if (thenClause->getValueId().getType().getTypeQualifier() 
-                   == NA_CHARACTER_TYPE)
+          else if (DFS2REC::isCharacterString(thenClause->getValueId().getType().getFSDatatype()))
             {
               if (thenClause->getValueId().getType().getNominalSize() > dLen)
                 dLen = thenClause->getValueId().getType().getNominalSize();
@@ -9344,7 +9380,7 @@ ItemExpr *QuantifiedComp::bindNode(BindWA *bindWA)
 
       if (type1.getTypeQualifier() != type2.getTypeQualifier())
 	{
-	  if ((type1.getTypeQualifier() == NA_CHARACTER_TYPE) &&
+	  if ((DFS2REC::isCharacterString(type1.getFSDatatype())) &&
 	      (type2.getTypeQualifier() == NA_NUMERIC_TYPE))
 	    {
 	      // only supporting char lhs at this time. Add more later.
@@ -10344,7 +10380,7 @@ ItemExpr *ValueIdUnion::bindNode(BindWA *bindWA)
       Int32 otherChildIndex = -1;
       Int32 convType = -1;
       if ((type1.getTypeQualifier() == NA_NUMERIC_TYPE) &&
-	  (type2.getTypeQualifier() == NA_CHARACTER_TYPE))
+	  (DFS2REC::isCharacterString(type2.getFSDatatype())))
 	{
 	  // convert leftSource(NUMERIC) to char type
 	  srcChildIndex = 0;
@@ -12379,6 +12415,64 @@ ItemExpr *ZZZBinderFunction::bindNode(BindWA *bindWA)
       }
       break;
 
+    case ITM_TO_BINARY:
+      {
+	ItemExpr *child0 = child(0)->castToItemExpr()->bindNode(bindWA); 
+	if (bindWA->errStatus()) 
+	  return this;
+
+        Lng32 binLen = 0;
+        if (child(1) != NULL)
+          {
+            ItemExpr *child1 = child(1)->castToItemExpr()->bindNode(bindWA);
+            if (bindWA->errStatus()) 
+              return this;
+
+            // parser has already validated that child1 is an unsigned const.
+            NABoolean negate;
+            ConstValue * cv = child1->castToConstValue(negate);
+            binLen = (Lng32)cv->getExactNumericValue();
+          }
+
+        const NAType &type0 = child0->getValueId().getType();
+        if (binLen == 0)
+          binLen = type0.getNominalSize();
+        SQLBinaryString *bin = 
+          new(bindWA->wHeap()) SQLBinaryString(bindWA->wHeap(),
+                                               binLen, type0.supportsSQLnull(),
+                                               type0.isVaryingLen());
+
+        Cast *cast = new(bindWA->wHeap()) Cast(child0, bin);
+        parseTree = cast;
+      }
+      break;
+
+    case ITM_TO_CHAR:
+      {
+	ItemExpr *child0 = child(0)->castToItemExpr()->bindNode(bindWA); 
+	if (bindWA->errStatus()) 
+	  return this;
+        
+        ItemExpr* ie = NULL;
+        const NAType &type0 = child0->getValueId().getType();
+        if (type0.getTypeQualifier() == NA_DATETIME_TYPE)
+          {
+            ie = new(bindWA->wHeap()) DateFormat
+              (child0, "UNSPECIFIED", DateFormat::FORMAT_TO_CHAR);
+          }
+        else
+          {
+            Lng32 len = type0.getDisplayLength();
+            SQLVarChar *vc = new(bindWA->wHeap()) SQLVarChar
+              (bindWA->wHeap(), len, type0.supportsSQLnull());
+            
+            ie = new(bindWA->wHeap()) Cast(child0, vc);
+          }
+        
+        parseTree = ie;
+      }
+      break;
+
     ////////////////////////////////////////////////////////////////////////
     // OVERLAY ( src_str PLACING replace_str FROM start_pos [ FOR length ]
     // is equivalent to:
@@ -12486,7 +12580,6 @@ ItemExpr *ZZZBinderFunction::bindNode(BindWA *bindWA)
       }
       break;
       
-      
     default:
       {
 	bindWA->setErrStatus();
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index 43afef6..6432377 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -1092,6 +1092,24 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
         naType = (NAType*)&cast->getValueId().getType();
       }
     
+    if ((DFS2REC::isBinaryString(naType->getFSDatatype())) &&
+        (CmpCommon::getDefault(TRAF_BINARY_OUTPUT) == DF_OFF) &&
+        (NOT bindWA->inCTAS()) &&
+        (NOT bindWA->inViewDefinition()))
+      {
+        ItemExpr * cast = NULL;
+        cast = new (bindWA->wHeap()) 
+          ConvertHex(ITM_CONVERTTOHEX, col->getValueId().getItemExpr());
+
+        cast = cast->bindNode(bindWA);
+        if (bindWA->errStatus()) 
+          return;
+        col->setValueId(cast->getValueId());
+        compExpr[i] = cast->getValueId();
+        
+        naType = (NAType*)&cast->getValueId().getType();
+      }
+    
     // if OFF, return tinyint as smallint.
     // This is needed until all callers/drivers have full support to
     // handle IO of tinyint datatypes.
@@ -8721,18 +8739,22 @@ RelExpr *TupleList::bindNode(BindWA *bindWA)
     }
 
     // Genesis 10-980611-7153
-    if (castTo && prevTupleNumEntries != castToList().entries()) break;
+    if (castTo && prevTupleNumEntries != castToList().entries()) 
+      break;
 
     for (CollIndex j = 0; j < prevTupleNumEntries; j++) {
       // If any unknown type in the tuple, coerce it to the target type.
       // Also do same MP-NCHAR magic as above.
+      ValueId srcVID = vidList[j];
       if (castTo) {
         ValueId src = vidList[j];
         src.coerceType(castToList()[j].getType());
 
+        ItemExpr *srcIE = src.getItemExpr();
+        ItemExpr *tgtIE = castToList()[j].getItemExpr();
+        
         // tmpAssign MUST BE ON HEAP -- see note above!
-        Assign *tmpAssign = new(bindWA->wHeap())
-          Assign(castToList()[j].getItemExpr(), src.getItemExpr());
+        Assign *tmpAssign = new(bindWA->wHeap()) Assign(tgtIE, srcIE);
         tmpAssign = (Assign *)tmpAssign->bindNode(bindWA);
         if (bindWA->errStatus()) 
           return this;
@@ -9815,17 +9837,6 @@ RelExpr *Insert::bindNode(BindWA *bindWA)
       return this;
     }
      
-    // if my child is a TupleList, then all tuples are to be converted/cast
-    // to the corresponding target type of the tgtColList.
-    // Pass on the tgtColList to TupleList so it can generate the Cast nodes
-    // with the target types during the TupleList::bindNode.
-    if (child(0)->getOperatorType() == REL_TUPLE_LIST) {
-      ValueIdList tgtColList;
-      getTableDesc()->getUserColumnList(tgtColList);
-      TupleList *tl = (TupleList *)child(0)->castToRelExpr();
-      tl->castToList() = tgtColList;
-    }
- 
     RelExpr *feResult = FastExtract::makeFastExtractTree(
          getTableDesc(),
          child(0).getPtr(),
@@ -17643,7 +17654,6 @@ RelExpr * FastExtract::bindNode(BindWA *bindWA)
     return this;
   }
 
-
   // check validity of target location
   if (getTargetType() == FILE)
   {
@@ -17677,7 +17687,6 @@ RelExpr * FastExtract::bindNode(BindWA *bindWA)
     }
   }
 
-
   if (getDelimiter().length() == 0)
   {
     delimiter_ = ActiveSchemaDB()->getDefaults().getValue(TRAF_UNLOAD_DEF_DELIMITER);
@@ -17686,18 +17695,21 @@ RelExpr * FastExtract::bindNode(BindWA *bindWA)
   // if inserting into a hive table and an explicit null string was
   // not specified in the unload command, and the target table has a user
   // specified null format string, then use it.
+  const HHDFSTableStats* hTabStats = NULL;
   if ((isHiveInsert()) &&
       (hiveTableDesc_ && hiveTableDesc_->getNATable() && 
-       hiveTableDesc_->getNATable()->getClusteringIndex()) &&
-      (NOT nullStringSpec_))
+       hiveTableDesc_->getNATable()->getClusteringIndex()))
     {
-      const HHDFSTableStats* hTabStats = 
+      hTabStats = 
         hiveTableDesc_->getNATable()->getClusteringIndex()->getHHDFSTableStats();
-
-      if (hTabStats->getNullFormat())
+      
+      if (NOT nullStringSpec_)
         {
-          nullString_ = hTabStats->getNullFormat();
-          nullStringSpec_ = TRUE;
+          if (hTabStats->getNullFormat())
+            {
+              nullString_ = hTabStats->getNullFormat();
+              nullStringSpec_ = TRUE;
+            }
         }
     }
 
@@ -17713,11 +17725,28 @@ RelExpr * FastExtract::bindNode(BindWA *bindWA)
     recordSeparator_ = ActiveSchemaDB()->getDefaults().getValue(TRAF_UNLOAD_DEF_RECORD_SEPARATOR);
   }
 
-
   if (!isHiveInsert())
   {
     bindWA->setIsFastExtract();
   }
+
+  ValueIdList tgtColList;
+  TupleList *tl = NULL;
+  if ((isHiveInsert() && hTabStats && hTabStats->isTextFile()) &&
+      (child(0) && child(0)->getOperatorType() == REL_TUPLE_LIST))
+  {
+    // if my child is a TupleList, then all tuples are to be converted/cast
+    // to the corresponding target type of the tgtColList.
+    // Pass on the tgtColList to TupleList so it can generate the Cast nodes
+    // with the target types during the TupleList::bindNode.
+    hiveTableDesc_->getUserColumnList(tgtColList);
+    tl = (TupleList *)child(0)->castToRelExpr();
+    tl->castToList() = tgtColList;
+
+    tl->setCastTo(TRUE);
+    tl->setHiveTextInsert(TRUE);
+  }
+
   // Bind the child nodes.
   bindChildren(bindWA);
   if (bindWA->errStatus())
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index 988e8d8..8e00abe 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -7768,9 +7768,15 @@ const NAString BuiltinFunction::getText() const
     case ITM_AGGR_GROUPING_FUNC:
       return "aggr_grouping";
 
-    case ITM_TO_TIMESTAMP:
-      return "to_timestamp";
+    case ITM_ENCODE_BASE64:
+      return "encode_base64";
+
+    case ITM_DECODE_BASE64:
+      return "decode_base64";
 
+    case ITM_TO_TIMESTAMP:
+       return "to_timestamp";
+ 
     case ITM_SPLIT_PART:
       return "split_part";
 
@@ -10084,10 +10090,15 @@ void ConstValue::initCharConstValue
                                       );
       }
       else
-      type_ = new (outHeap)
-		SQLChar(outHeap, num_of_chars, FALSE, FALSE, FALSE, FALSE,
-			charSet, collation, coercibility);
-
+      {
+        if (charSet == CharInfo::BINARY)
+          type_ = new (outHeap)
+            SQLBinaryString(outHeap, strval.length(), FALSE, FALSE);
+        else
+          type_ = new (outHeap)
+            SQLChar(outHeap, num_of_chars, FALSE, FALSE, FALSE, FALSE,
+                    charSet, collation, coercibility);
+      }
 
       storageSize_ = strval.length();
       value_ = (void *)( new (outHeap)
diff --git a/core/sql/optimizer/NAColumn.cpp b/core/sql/optimizer/NAColumn.cpp
index 322a3a4..ce09c94 100644
--- a/core/sql/optimizer/NAColumn.cpp
+++ b/core/sql/optimizer/NAColumn.cpp
@@ -541,6 +541,16 @@ NABoolean NAColumn::createNAType(TrafColumnsDesc *column_desc	/*IN*/,
       type = new (heap) SQLBooleanNative(heap, column_desc->isNullable());
       break;
 
+    case REC_BINARY_STRING :
+      type = new (heap) SQLBinaryString(heap, column_desc->length,
+                                        column_desc->isNullable(), FALSE);
+      break;
+      
+    case REC_VARBINARY_STRING :
+      type = new (heap) SQLBinaryString(heap, column_desc->length,
+                                        column_desc->isNullable(), TRUE);
+      break;
+
     default:
       {
 	// 4031 Column %s is an unknown data type, %d.
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index 23e4354..86917ee 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -3216,6 +3216,24 @@ NABoolean createNAType(TrafColumnsDesc *column_desc	/*IN*/,
       }
       break;
 
+    case REC_BINARY_STRING:
+      {
+        Lng32 sizeInChars = charCount ;
+        type = new (heap)
+          SQLBinaryString(heap,
+                          column_desc->length, column_desc->isNullable(), FALSE);
+      }
+      break;
+
+    case REC_VARBINARY_STRING:
+      {
+        Lng32 sizeInChars = charCount ;
+        type = new (heap)
+          SQLBinaryString(heap,
+                          column_desc->length, column_desc->isNullable(), TRUE);
+      }
+      break;
+
     default:
       {
 	// 4031 Column %s is an unknown data type, %d.
diff --git a/core/sql/optimizer/RelExpr.cpp b/core/sql/optimizer/RelExpr.cpp
index 7308bba..e01d630 100644
--- a/core/sql/optimizer/RelExpr.cpp
+++ b/core/sql/optimizer/RelExpr.cpp
@@ -11627,7 +11627,7 @@ const NAString Tuple::getText() const
 TupleList::TupleList(const TupleList & other) : Tuple(other)
 {
   castToList_ = other.castToList_;
-  createdForInList_ = other.createdForInList_;
+  flags_ = other.flags_;
 }
 
 RelExpr * TupleList::copyTopNode(RelExpr *derivedNode, CollHeap* outHeap)
diff --git a/core/sql/optimizer/RelFastTransport.cpp b/core/sql/optimizer/RelFastTransport.cpp
index 7365632..e195dec 100644
--- a/core/sql/optimizer/RelFastTransport.cpp
+++ b/core/sql/optimizer/RelFastTransport.cpp
@@ -119,7 +119,7 @@ RelExpr *FastExtract::makeFastExtractTree(
   }
 
   const NABoolean isSequenceFile = hTabStats->isSequenceFile();
-    
+  
   FastExtract * unloadRelExpr =
     new (bindWA->wHeap()) FastExtract(
          child,
diff --git a/core/sql/optimizer/RelMisc.h b/core/sql/optimizer/RelMisc.h
index a54ad38..ece8c72 100644
--- a/core/sql/optimizer/RelMisc.h
+++ b/core/sql/optimizer/RelMisc.h
@@ -952,15 +952,14 @@ public:
   // constructor
   TupleList(ItemExpr *tupleListExpr,
 	CollHeap *oHeap = CmpCommon::statementHeap())
-    : Tuple(REL_TUPLE_LIST,tupleListExpr, oHeap), numberOfTuples_(-1), createdForInList_(FALSE)
+    : Tuple(REL_TUPLE_LIST,tupleListExpr, oHeap), numberOfTuples_(-1), 
+      flags_(0)
   {}
 
   TupleList(const TupleList & other);
 
   ValueIdList & castToList() { return castToList_; }
   Lng32 numTuples() const { return numberOfTuples_; }
-  NABoolean createdForInList() const { return createdForInList_; }
-  void setCreatedForInList (NABoolean flag) { createdForInList_ = flag; }
 
   // a virtual function for performing name binding within the query tree
   RelExpr * bindNode(BindWA *bindWAPtr);
@@ -1004,7 +1003,25 @@ public:
   // set vidlist = ith tuple of this tuplelist and return TRUE
   RelExpr* getTuple(BindWA *bindWA, ValueIdList& vidList, CollIndex i);
 
+  NABoolean createdForInList() { return (flags_ & CREATED_FOR_IN_LIST) != 0; }
+  void setCreatedForInList(NABoolean v)
+  { (v ? flags_ |= CREATED_FOR_IN_LIST : flags_ &= ~CREATED_FOR_IN_LIST); }
+
+  NABoolean hiveTextInsert() { return (flags_ & HIVE_TEXT_INSERT) != 0; }
+  void setHiveTextInsert(NABoolean v)
+  { (v ? flags_ |= HIVE_TEXT_INSERT : flags_ &= ~HIVE_TEXT_INSERT); }
+
+  NABoolean castTo() { return (flags_ & CAST_TO) != 0; }
+  void setCastTo(NABoolean v)
+  { (v ? flags_ |= CAST_TO : flags_ &= ~CAST_TO); }
+
 private:
+  enum Flags
+    {
+      CREATED_FOR_IN_LIST   = 0x0001,
+      HIVE_TEXT_INSERT      = 0x0002,
+      CAST_TO               = 0x0004
+    };
 
   // set needsFixup to TRUE iff tuplelist needs INFER_CHARSET fixup
   RelExpr* needsCharSetFixup(BindWA *bindWA,
@@ -1034,7 +1051,8 @@ private:
   // converted before returning. Used (currently) if this list will be
   // inserted into a table.
   ValueIdList castToList_;
-  NABoolean createdForInList_;
+
+  Int32 flags_;
 }; // class TupleList
 
 // -----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index d2f4006..f4b4ef4 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -423,6 +423,17 @@ NABoolean CharType::isComparable(const NAType &otherNA,
   return cmpOK;
 }
 
+NABoolean SQLBinaryString::isComparable(const NAType &otherNA,
+                                      ItemExpr *parentOp,
+                                      Int32 emitErr,
+                                      UInt32 * flags) const
+{
+  if (NOT NAType::isComparable(otherNA, parentOp, emitErr, flags))
+    return FALSE;
+
+  return TRUE;
+}
+
 // -----------------------------------------------------------------------
 // additional, miscellaneous helper functions
 // -----------------------------------------------------------------------
@@ -550,7 +561,17 @@ static NABoolean synthItemExprLists(ItemExprList &exprList1,
       }
     }
 
+    // binary datatypes can only be compared with binary datatypes
+    if (((DFS2REC::isBinaryString(operand1->getFSDatatype())) &&
+         (NOT DFS2REC::isBinaryString(operand2->getFSDatatype()))) ||
+        ((DFS2REC::isBinaryString(operand2->getFSDatatype())) &&
+         (NOT DFS2REC::isBinaryString(operand1->getFSDatatype()))))
+      {
+        emitDyadicTypeSQLnameMsg(-4041, *operand1, *operand2);
 
+        return FALSE;
+      }
+            
     allowsUnknown = allowsUnknown OR
                     operand1->supportsSQLnullLogical() OR
                     operand2->supportsSQLnullLogical();
@@ -1436,6 +1457,36 @@ const NAType *BuiltinFunction::synthesizeType()
       }
       break;
 
+    case ITM_ENCODE_BASE64:
+      {
+        const NAType &typ1 = child(0)->getValueId().getType();
+
+        Int32 source_len = typ1.getNominalSize();
+
+        Int32 maxLength = str_encoded_len_base64(source_len);
+
+        retType = new HEAP SQLVarChar(HEAP, maxLength, TRUE);
+      }
+      break;
+
+    case ITM_DECODE_BASE64:
+      {
+        const NAType &typ1 = child(0)->getValueId().getType();
+
+        if (typ1.getTypeQualifier() != NA_CHARACTER_TYPE)
+        {
+          *CmpCommon::diags() << DgSqlCode(-4043) << DgString0(getTextUpper());
+          return NULL;
+        }
+
+        Int32 source_len = typ1.getNominalSize();
+
+        Int32 maxLength = str_decoded_len_base64(source_len);
+
+        retType = new HEAP SQLVarChar(HEAP, maxLength, TRUE);
+      }
+      break;
+
     default:
       {
 	retType = (NAType *)ItemExpr::synthesizeType();
@@ -2648,11 +2699,12 @@ const NAType *Cast::synthesizeType()
 
   const NAType &src = vid.getType();
   const NAType &tgt = (typeChanged)? *result: *getType();
+
   NABuiltInTypeEnum srcQual = src.getTypeQualifier();
   NABuiltInTypeEnum tgtQual = tgt.getTypeQualifier();
 
-  if ((src.getTypeQualifier() == NA_CHARACTER_TYPE) &&
-      (tgt.getTypeQualifier() == NA_CHARACTER_TYPE))
+  if ((DFS2REC::isCharacterString(src.getFSDatatype())) &&
+      (DFS2REC::isCharacterString(tgt.getFSDatatype())))
     {
       const CharType &cSrc = (CharType&)src;
       CharType &cTgt       = (CharType&)tgt;
@@ -2671,6 +2723,7 @@ const NAType *Cast::synthesizeType()
            ((CharType*)result)->setCharSet(cSrc.getCharSet());
          }
     }
+
   const NAType &res = (typeChanged)? *result: *getType();
   //
   // The NULL constant can be cast to any type.
@@ -2729,7 +2782,11 @@ const NAType *Cast::synthesizeType()
   // In other words, a) use isCompatible(), not isComparable(),
   // and b) just pass the tgt's collation/coercibility along!
   //
-  if ((srcQual == NA_LOB_TYPE) && (tgtQual != NA_LOB_TYPE))
+  if (DFS2REC::isBinaryString(tgt.getFSDatatype()))
+    legal = TRUE;
+  else if (DFS2REC::isBinaryString(src.getFSDatatype()))
+    legal = TRUE;
+  else if ((srcQual == NA_LOB_TYPE) && (tgtQual != NA_LOB_TYPE))
     legal = FALSE;
   else if (charsetChanged && src.isCompatible(res))
     legal = TRUE;
@@ -3358,40 +3415,6 @@ const NAType *Function::synthesizeType()
   // Function derives directly from ItemExpr, so safe to do this
   const NAType *result = ItemExpr::synthesizeType();
 
-if (0)
-{
-  if (result->getTypeQualifier() == NA_CHARACTER_TYPE) {
-    Int32 n = getNumCHARACTERArgs(this);
-    if (n > 1) {
-#ifndef NDEBUG
-//      if (NCHAR_DEBUG > 0)
-	{
-          NAString unparsed(CmpCommon::statementHeap());
-	  unparse(unparsed, DEFAULT_PHASE, USER_FORMAT_DELUXE);
-	  cerr << "## FUNCTION " << (Int32)getOperatorType()
-	       << " (" << n << " char-type args)\t"
-	       << unparsed
-	       << "\t *might* not be computing its result collation/coercibility properly and/or pushing co/co back down to its children..." << endl;
-
-	  // Also emit a warning so you can catch this in regression results
-	  unparsed.prepend("## FUNCTION, co/co issue: ");
-	  *CmpCommon::diags() << DgSqlCode(+1110) << DgString0(unparsed);
-	}
-#endif
-}
-
-//	  WE DO *NOT* SYNTHESIZE A RESULT CoAndCo here
-//	  nor push it back down to children via propagateCoAndCoToChildren,
-//	  because that might not be the right thing.
-//	  If the above CERR msg appears and you see a problem,
-//	  you should add a synthesizeType method for that particular
-//	  Function-derived class.
-//    CharType *ct = (CharType *)result;
-//    propagateCoAndCoToChildren(this,
-//				 ct->getCollation(), ct->getCoercibility());
-    }
-  }
-
   return result;
 }
 
@@ -4100,16 +4123,25 @@ const NAType *Repeat::synthesizeType()
       size_in_chars = size_in_bytes / CharInfo::minBytesPerChar(ctyp1.getCharSet());
     }
 
-  NAType *result =
-    new (HEAP) SQLVarChar(HEAP, CharLenInfo((Lng32)size_in_chars, (Lng32)size_in_bytes),
-			  (typ1.supportsSQLnullLogical() ||
-			   typ2.supportsSQLnullLogical()),
-			  ctyp1.isUpshifted(),
-			  ctyp1.isCaseinsensitive(),
-			  ctyp1.getCharSet(),
-			  ctyp1.getCollation(),
-			  ctyp1.getCoercibility());
-
+  NAType *result = NULL;
+  if (DFS2REC::isCharacterString(typ1.getFSDatatype()))
+    result = new (HEAP) SQLVarChar(
+         HEAP,
+         CharLenInfo((Lng32)size_in_chars, (Lng32)size_in_bytes),
+         (typ1.supportsSQLnullLogical() ||
+          typ2.supportsSQLnullLogical()),
+         ctyp1.isUpshifted(),
+         ctyp1.isCaseinsensitive(),
+         ctyp1.getCharSet(),
+         ctyp1.getCollation(),
+         ctyp1.getCoercibility());
+  else
+    result = new HEAP SQLBinaryString(
+         HEAP,
+         size_in_bytes,
+         (typ1.supportsSQLnullLogical() ||
+          typ2.supportsSQLnullLogical()),
+         TRUE);
   return result;
 }
 
@@ -4249,16 +4281,25 @@ const NAType *Replace::synthesizeType()
  
   CharLenInfo CLInfo( size_in_chars, size_in_bytes );
 
-  NAType *result =
-    new (HEAP) SQLVarChar(HEAP, CLInfo,
-			  (typ1->supportsSQLnullLogical() ||
-			   typ2->supportsSQLnullLogical() ||
-			   typ3->supportsSQLnullLogical()),
-			  ctyp1->isUpshifted(),
-			  ctyp1->isCaseinsensitive(),
-			  ctyp1->getCharSet(),
-			  ctyp1->getCollation(),
-			  ctyp1->getCoercibility());
+  NAType *result = NULL;
+  if (DFS2REC::isCharacterString(typ1->getFSDatatype()))
+    result =
+      new (HEAP) SQLVarChar(HEAP, CLInfo,
+                            (typ1->supportsSQLnullLogical() ||
+                             typ2->supportsSQLnullLogical() ||
+                             typ3->supportsSQLnullLogical()),
+                            ctyp1->isUpshifted(),
+                            ctyp1->isCaseinsensitive(),
+                            ctyp1->getCharSet(),
+                            ctyp1->getCollation(),
+                            ctyp1->getCoercibility());
+  else
+    result = new HEAP SQLBinaryString(
+         HEAP, size_in_bytes,
+         (typ1->supportsSQLnullLogical() ||
+          typ2->supportsSQLnullLogical() ||
+          typ3->supportsSQLnullLogical()),
+         TRUE);
 
   return result;
 }
@@ -4826,7 +4867,7 @@ const NAType *Lower::synthesizeType()
   // Check that the operands are compatible.
   //
   const NAType& operand = vid.getType();
-  if (operand.getTypeQualifier() != NA_CHARACTER_TYPE) {
+  if (NOT DFS2REC::isCharacterString(operand.getFSDatatype())) {
     // 4043 The operand of a LOWER function must be character.
     *CmpCommon::diags() << DgSqlCode(-4043) << DgString0(getTextForError());
     return NULL;
@@ -4881,7 +4922,7 @@ const NAType *Upper::synthesizeType()
   //
   const NAType& operand = vid.getType();
 
-  if (operand.getTypeQualifier() != NA_CHARACTER_TYPE) {
+  if (NOT DFS2REC::isCharacterString(operand.getFSDatatype())) {
     // 4043 The operand of an UPPER function must be character.
     *CmpCommon::diags() << DgSqlCode(-4043) << DgString0(getTextForError());
     return NULL;
@@ -5163,11 +5204,6 @@ const NAType *Substring::synthesizeType()
   }
 
   CharInfo::CharSet op1_cs = operand1->getCharSet();
-  /*
-    ((operand1->getFSDatatype() == REC_CLOB) ?
-     ((SQLClob*)operand1)->getCharSet() :
-     ((CharType *)operand1)->getCharSet());
-  */
 
   const CharType *charOperand = (CharType *) operand1;
   Lng32 maxLength_bytes = charOperand->getDataStorageSize();
@@ -5227,36 +5263,6 @@ const NAType *Substring::synthesizeType()
     }	  	// constant length op
   }	  	// length operand specified
 
-/*
-  length64 = length;
-
-  if ((NOT DFS2REC::isAnyVarChar(operand1->getFSDatatype())) &&
-      (pos > 0) &&
-      (length64 > 0) &&
-      ((pos + length64 - 1) <= maxLength))
-    resultIsFixedChar = TRUE;
-*/
-
- // 12/22/97: the substring inherits the charset, collation and
- // coercibility from the source string.
-
-/*  if (resultIsFixedChar)
-    return new HEAP
-      SQLChar(maxLength,
-	      operand1->supportsSQLnull() OR
-	      operand2->supportsSQLnull() OR
-	      ((operand3 != NULL) AND operand3->supportsSQLnull())
-	      ,charOperand->isUpshifted()
-	      ,charOperand->isCaseinsensitive()
-	      ,FALSE
-	      ,charOperand->getCharSet()
-	      ,charOperand->getCollation()
-	      ,charOperand->getCoercibility()
-	      );
-  else
-*/
-
-
   if (operand1->getFSDatatype() == REC_CLOB)
     {
       return new HEAP
@@ -5265,24 +5271,29 @@ const NAType *Substring::synthesizeType()
 		operand2->supportsSQLnull() OR
 		((operand3 != NULL) AND operand3->supportsSQLnull()));
     }
+  else if (DFS2REC::isCharacterString(operand1->getFSDatatype()))
+    {
+      return new HEAP
+        SQLVarChar(HEAP, CharLenInfo(maxLength_chars, maxLength_bytes), // OLD: maxLength
+                   operand1->supportsSQLnull() OR
+                   operand2->supportsSQLnull() OR
+                   ((operand3 != NULL) AND operand3->supportsSQLnull())
+                   ,charOperand->isUpshifted()
+                   ,charOperand->isCaseinsensitive()
+                   ,operand1->getCharSet()
+                   ,charOperand->getCollation()
+                   ,charOperand->getCoercibility()
+                   );
+    }
   else
     {
-    
-
       return new HEAP
-	SQLVarChar(HEAP, CharLenInfo(maxLength_chars, maxLength_bytes), // OLD: maxLength
-		   operand1->supportsSQLnull() OR
-		   operand2->supportsSQLnull() OR
-		   ((operand3 != NULL) AND operand3->supportsSQLnull())
-		   ,charOperand->isUpshifted()
-		   ,charOperand->isCaseinsensitive()
-		   ,operand1->getCharSet()
-		   ,charOperand->getCollation()
-		   ,charOperand->getCoercibility()
-		   );
-      
+	SQLBinaryString(HEAP, maxLength_bytes,
+                      operand1->supportsSQLnull() OR
+                      operand2->supportsSQLnull() OR
+                      ((operand3 != NULL) AND operand3->supportsSQLnull()),
+                      TRUE);
     }
-  
 }
 
 // -----------------------------------------------------------------------
@@ -5373,15 +5384,25 @@ const NAType *Trim::synthesizeType()
   //
   Int32 size = trimSource->getDataStorageSize();
 
-  return new HEAP
-    SQLVarChar(HEAP, CharLenInfo(trimSource->getStrCharLimit(), size )
-	      ,trimChar->supportsSQLnull() OR trimSource->supportsSQLnull()
-	      ,trimSource->isUpshifted()
-	      ,trimSource->isCaseinsensitive()
-              ,trimSource->getCharSet()
-	      ,trimSource->getCollation()
-	      ,trimSource->getCoercibility()
-	      );
+  if (DFS2REC::isBinaryString(vid2.getType().getFSDatatype()))
+    {
+      return new HEAP
+	SQLBinaryString(HEAP, size,
+                        trimChar->supportsSQLnull() OR trimSource->supportsSQLnull(),
+                        TRUE);
+    }
+  else
+    {
+      return new HEAP
+        SQLVarChar(HEAP, CharLenInfo(trimSource->getStrCharLimit(), size )
+                   ,trimChar->supportsSQLnull() OR trimSource->supportsSQLnull()
+                   ,trimSource->isUpshifted()
+                   ,trimSource->isCaseinsensitive()
+                   ,trimSource->getCharSet()
+                   ,trimSource->getCollation()
+                   ,trimSource->getCoercibility()
+                   );
+    }
 }
 
 // -----------------------------------------------------------------------
@@ -5438,8 +5459,8 @@ const NAType *Translate::synthesizeType()
   //
 
   const NAType& operand = vid.getType();
-  if (operand.getTypeQualifier() != NA_CHARACTER_TYPE) {
-    // 4043 The operand of an UPPER function must be character.
+  if (NOT DFS2REC::isCharacterString(operand.getFSDatatype())) {
+    // 4043 The operand of TRANSLATE function must be character.
     *CmpCommon::diags() << DgSqlCode(-4043) << DgString0(getTextUpper());
     return NULL;
   }
@@ -5627,6 +5648,7 @@ const NAType *Translate::synthesizeType()
 const NAType *ValueIdUnion::synthesizeType()
 {
   const NAType *result = NULL;
+
   CollIndex i = 0;
 
   // if this is the case of insert values list tuples, then
diff --git a/core/sql/optimizer/ValueDesc.cpp b/core/sql/optimizer/ValueDesc.cpp
index 0e12ffb..2d46bcb 100644
--- a/core/sql/optimizer/ValueDesc.cpp
+++ b/core/sql/optimizer/ValueDesc.cpp
@@ -417,6 +417,20 @@ void ValueId::coerceType(const NAType& desiredType,
                SQLVarChar(STMTHEAP, SQL_BOOLEAN_DISPLAY_SIZE, 
                           desiredType.supportsSQLnull());
            }
+	 else if ((DFS2REC::isBinaryString(desiredType.getFSDatatype())) &&
+                  (CmpCommon::getDefault(TRAF_BINARY_INPUT) == DF_OFF))
+	   {
+             if (desiredType.getFSDatatype() == REC_BINARY_STRING)
+               newType = new (STMTHEAP) 
+                 SQLChar(STMTHEAP,
+                         desiredType.getNominalSize(), 
+                         desiredType.supportsSQLnull());
+             else
+               newType = new (STMTHEAP) 
+                 SQLVarChar(STMTHEAP,
+                            desiredType.getNominalSize(), 
+                            desiredType.supportsSQLnull());               
+	   } // Binary String
 	 else if (DFS2REC::isBigNum(desiredType.getFSDatatype()))
 	   {
 	     // If bignum IO is not enabled or
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index 3dc4d6d..ca1c5bb 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -364,6 +364,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("DECADE",             TOK_DECADE,      NONRESTOKEN_),
   ParKeyWord("DECODE",             TOK_DECODE,      NONRESTOKEN_),
   ParKeyWord("DECLARE",            TOK_DECLARE,     ANS_|RESWORD_),
+  ParKeyWord("DECODE_BASE64",      TOK_DECODE_BASE64,  NONRESTOKEN_),
   ParKeyWord("DEFAULT",            TOK_DEFAULT,     SECOND_|ANS_|RESWORD_),
   ParKeyWord("DEFAULTS",           TOK_DEFAULTS,    NONRESTOKEN_),
   ParKeyWord("DEFERRABLE",         IDENTIFIER,      ANS_|RESWORD_),
@@ -426,6 +427,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("ELSE",               TOK_ELSE,        ANS_|RESWORD_|NONRESTOKEN_),
   ParKeyWord("ELSEIF",             TOK_ELSEIF,      POTANS_|RESWORD_),
   ParKeyWord("ENABLE",             TOK_ENABLE,      NONRESTOKEN_),
+  ParKeyWord("ENCODE_BASE64",      TOK_ENCODE_BASE64,  NONRESTOKEN_),
   ParKeyWord("ENCODE_KEY",         TOK_ENCODE_KEY,  NONRESTOKEN_),
   ParKeyWord("END",                TOK_END,         ANS_|RESWORD_|NONRESTOKEN_),
   ParKeyWord("END-EXEC",           IDENTIFIER,      ANS_|RESWORD_),
@@ -494,6 +496,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("FREE",               TOK_FREE,        COMPAQ_|RESWORD_),
   ParKeyWord("FREESPACE",          TOK_FREESPACE,   NONRESTOKEN_),  
   ParKeyWord("FROM",               TOK_FROM,        ANS_|RESWORD_),
+  ParKeyWord("FROM_HEX",           TOK_FROM_HEX,    NONRESTOKEN_),
   ParKeyWord("FULL",               TOK_FULL,        ANS_|RESWORD_),
   ParKeyWord("FUNCTION",           TOK_FUNCTION,    COMPAQ_|RESWORD_),
   ParKeyWord("FUNCTIONS",          TOK_FUNCTIONS,   NONRESTOKEN_),
@@ -845,8 +848,8 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("PICTURE",            TOK_PICTURE,     FIRST_),
   ParKeyWord("PIPELINE",           TOK_PIPELINE,    FLAGSNONE_),
   ParKeyWord("PID",                TOK_PID,         NONRESTOKEN_),
-  ParKeyWord("PIVOT_GROUP",                TOK_PIVOT_GROUP,         NONRESTOKEN_),
-  ParKeyWord("PIVOT",                TOK_PIVOT,         NONRESTOKEN_),
+  ParKeyWord("PIVOT_GROUP",        TOK_PIVOT_GROUP, NONRESTOKEN_),
+  ParKeyWord("PIVOT",              TOK_PIVOT,       NONRESTOKEN_),
   ParKeyWord("PLACING",            TOK_PLACING,     NONRESTOKEN_),
   ParKeyWord("POOL",               TOK_POOL,        NONRESTOKEN_),
   ParKeyWord("POPULATE",           TOK_POPULATE,    NONRESTOKEN_),
@@ -1155,8 +1158,10 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("TINYINT",            TOK_TINYINT,     NONRESTOKEN_),
   ParKeyWord("TITLE",              TOK_TITLE,       NONRESTOKEN_),
   ParKeyWord("TO",                 TOK_TO,          ANS_|RESWORD_),
+  ParKeyWord("TO_BINARY",          TOK_TO_BINARY,   NONRESTOKEN_),
   ParKeyWord("TO_CHAR",            TOK_TO_CHAR,     NONRESTOKEN_),
   ParKeyWord("TO_DATE",            TOK_TO_DATE,     NONRESTOKEN_),
+  ParKeyWord("TO_HEX",             TOK_TO_HEX,      NONRESTOKEN_),
   ParKeyWord("TO_NUMBER",          TOK_TO_NUMBER,   NONRESTOKEN_),
   ParKeyWord("TO_TIME",            TOK_TO_TIME,   NONRESTOKEN_),
   ParKeyWord("TO_TIMESTAMP",       TOK_TO_TIMESTAMP,   NONRESTOKEN_),
@@ -1191,6 +1196,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("UNBOUNDED",          TOK_UNBOUNDED,   NONRESTOKEN_),
   ParKeyWord("UNCOMMITTED",        TOK_UNCOMMITTED, NONRESTOKEN_),
   ParKeyWord("UNDER",              IDENTIFIER,      POTANS_|RESWORD_),
+  ParKeyWord("UNHEX",              TOK_UNHEX,       NONRESTOKEN_),
   ParKeyWord("UNION",              TOK_UNION,       FIRST_|ANS_|RESWORD_),
   ParKeyWord("UNIQUE",             TOK_UNIQUE,      ANS_|RESWORD_),
   ParKeyWord("UNIQUE_ID",             TOK_UNIQUE_ID,      NONRESTOKEN_),
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index af518b8..1d5ca35 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -634,6 +634,8 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_ENABLE             
 %token <tokval> TOK_END
 %token <tokval> TOK_ENCODE_KEY          /* Tandem extension */
+%token <tokval> TOK_ENCODE_BASE64
+%token <tokval> TOK_DECODE_BASE64
 %token <tokval> TOK_ENFORCED
 %token <tokval> TOK_ENFORCERS
 %token <tokval> TOK_ENTERPRISE
@@ -694,6 +696,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_FOUND
 %token <tokval> TOK_FRACTION            /* Tandem extension non-reserved word */
 %token <tokval> TOK_FROM
+%token <tokval> TOK_FROM_HEX
 %token <tokval> TOK_FULL
 %token <tokval> TOK_GENERAL             /* ANSI SQL potential-reserved word */
 %token <tokval> TOK_GENERATE
@@ -718,6 +721,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_SERIALIZED
 %token <tokval> TOK_HEX                 /* HP Neo extension non-reserved word */
 %token <tokval> TOK_HEXADECIMAL         /* HP Neo extension non-reserved word */
+%token <tokval> TOK_UNHEX
 %token <tokval> TOK_HIGH_VALUE          /* Tandem extension non-reserved word */
 // QSTUFF
 %token <tokval> TOK_HOLD                /* standard holdable cursor */
@@ -1124,8 +1128,10 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_TINYINT
 %token <tokval> TOK_TITLE
 %token <tokval> TOK_TO
+%token <tokval> TOK_TO_BINARY
 %token <tokval> TOK_TO_CHAR
 %token <tokval> TOK_TO_DATE
+%token <tokval> TOK_TO_HEX
 %token <tokval> TOK_TO_NUMBER
 %token <tokval> TOK_TO_TIME
 %token <tokval> TOK_TO_TIMESTAMP
@@ -3056,7 +3062,6 @@ numeric_literal :       numeric_literal_exact
                   SqlParser_CurrentParser->collectItem4HQC($$);
 		}
 
-/* type item */
 character_literal_sbyte : sbyte_string_literal character_literal_notcasespecific_option
                 {
 //
@@ -3475,12 +3480,9 @@ character_string_literal: sbyte_string_literal
   }
        | std_char_string_literal /* i.e., no charset prefix */
 
-/* type stringval */
 sbyte_string_literal : TOK_SBYTE_LITERAL
-       | sbyte_string_literal TOK_SBYTE_LITERAL
+                      | sbyte_string_literal TOK_SBYTE_LITERAL
            {
-             // sbyte_string_literal ::= sbyte_string_literal TOK_SBYTE_LITERAL
-
              // Mismatch example: The user specifies _iso88591'abc' _utf8'def'
              if (charsetMismatchError(&$1, &$2)) YYERROR;
 
@@ -8756,7 +8758,7 @@ datetime_value_function : TOK_CURDATE '(' ')'
               }
 
 /* type item */
-datetime_misc_function_used_as_default:      TOK_TO_CHAR '(' value_expression ',' character_string_literal ')'
+datetime_misc_function_used_as_default: TOK_TO_CHAR '(' value_expression ',' character_string_literal ')'
                                {
                                  NAString * ves= unicodeToChar
                                    (ToTokvalPlusYYText(&$3)->yytext,
@@ -8778,7 +8780,6 @@ datetime_misc_function_used_as_default:      TOK_TO_CHAR '(' value_expression ',
                                    DateFormat($3, *$5, DateFormat::FORMAT_TO_CHAR);
                                  ((DateFormat *)$$)->setOriginalString(fullstr);
                                }
-
 /* type item */
 datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')'
 				{
@@ -8894,11 +8895,21 @@ datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')'
 
                                 $$ = new (PARSERHEAP()) Cast ($3, dt);
                                 }
+    | TOK_TO_BINARY '(' value_expression ',' unsigned_integer ')'
+                               {
+                                 ConstValue * cv = new (PARSERHEAP()) ConstValue($5);
+                                 $$ = new (PARSERHEAP()) 
+				   ZZZBinderFunction(ITM_TO_BINARY, $3, cv);
+			       }
+    | TOK_TO_BINARY '(' value_expression ')'
+                               {
+                                 $$ = new (PARSERHEAP()) 
+				   ZZZBinderFunction(ITM_TO_BINARY, $3);
+			       }
     | TOK_TO_CHAR '(' value_expression ')'
                                {
-                                 $$ = new (PARSERHEAP()) DateFormat
-                                   ($3, "UNSPECIFIED", DateFormat::FORMAT_TO_CHAR);
-
+                                 $$ = new (PARSERHEAP()) 
+                                   ZZZBinderFunction(ITM_TO_CHAR, $3);
 			       }
     | TOK_TO_DATE '(' value_expression ',' character_string_literal ')'
                                {
@@ -9006,6 +9017,15 @@ string_function :
            $$ = new (PARSERHEAP()) ConvertHex(ITM_CONVERTFROMHEX, $3);
         } 
 
+     | TOK_UNHEX '('   value_expression   ')'
+        {
+           $$ = new (PARSERHEAP()) ConvertHex(ITM_CONVERTFROMHEX, $3);
+        } 
+     | TOK_FROM_HEX '('   value_expression   ')'
+        {
+           $$ = new (PARSERHEAP()) ConvertHex(ITM_CONVERTFROMHEX, $3);
+        } 
+
      | TOK_CONVERTTOHEX   '('   value_expression   ')'
         {
           if ( (SqlParser_DEFAULT_CHARSET == CharInfo::ISO88591) ||
@@ -9018,6 +9038,14 @@ string_function :
               $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_CONVERTTOHX, $3);
           }
         }
+     | TOK_TO_HEX   '('   value_expression   ')'
+        {
+          $$ = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, $3);
+        }
+     | TOK_HEX   '('   value_expression   ')'
+        {
+          $$ = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, $3);
+        }
      | TOK_CONVERTTOHX_INTN  '('   value_expression   ')'
         {
            $$ = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, $3);
@@ -9086,8 +9114,10 @@ string_function :
      /* ODBC extension: map LTRIM(str) to TRIM(LEADING FROM str) */
      | TOK_LTRIM '(' value_expression ')'
 	     { 
-		$$ = new (PARSERHEAP()) Trim((Int32)Trim::LEADING,
-			    new (PARSERHEAP()) SystemLiteral(" ", WIDE_(" ")), $3); 
+		$$ = new (PARSERHEAP()) Trim
+                  ((Int32)Trim::LEADING,
+                   NULL, 
+                   $3); 
 	     }
 
      | TOK_OCTET_LENGTH '(' value_expression ')'
@@ -9151,8 +9181,10 @@ string_function :
      /* ODBC extension: RTRIM(str) is the same as TRIM(TRAILING FROM str) */
      | TOK_RTRIM '(' value_expression ')'
 	{ 
-            $$ = new (PARSERHEAP()) Trim((Int32)Trim::TRAILING,
-	              new (PARSERHEAP()) SystemLiteral(" ", WIDE_(" ")), $3); 
+            $$ = new (PARSERHEAP()) Trim
+              ((Int32)Trim::TRAILING,
+               NULL, 
+               $3); 
         }
 
      | TOK_RTRIM '(' value_expression ',' value_expression ')'
@@ -9303,6 +9335,7 @@ string_function :
 		    $$ = 
 		      new (PARSERHEAP()) ZZZBinderFunction(ITM_OVERLAY, $3, $5, $7, $9);
                   }
+
      | TOK_OVERLAY '(' value_expression TOK_PLACING value_expression TOK_FROM value_expression ')'
                   {
 		    $$ = 
@@ -9320,7 +9353,6 @@ string_function :
         }
 
 
-
 /* type item */
 builtin_function_user : TOK_USER
 				{
@@ -9579,7 +9611,7 @@ cache_option : TOK_CACHE NUMERIC_LITERAL_EXACT_NO_SCALE
 datatype_option : int_type
      {
        NumericType * type = (NumericType*)$1;
-       if (NOT DFS2REC::isBinary(type->getFSDatatype()))
+       if (NOT DFS2REC::isBinaryNumeric(type->getFSDatatype()))
          YYERROR;
 
         // CACHE Option
@@ -10341,6 +10373,18 @@ misc_function :
                $$ = new (PARSERHEAP()) BuiltinFunction(ITM_AES_DECRYPT, CmpCommon::statementHeap(),
                                                        2, $3, $5);
              }
+       | TOK_ENCODE_BASE64 '(' value_expression ')'
+             {
+               $$ = new (PARSERHEAP()) BuiltinFunction(ITM_ENCODE_BASE64, 
+                                                       CmpCommon::statementHeap(),
+                                                       1, $3);
+             }
+       | TOK_DECODE_BASE64 '(' value_expression ')'
+             {
+               $$ = new (PARSERHEAP()) BuiltinFunction(ITM_DECODE_BASE64, 
+                                                       CmpCommon::statementHeap(),
+                                                       1, $3);
+             }
 
 hbase_column_create_list : '(' hbase_column_create_value ')'
                                    {
@@ -10681,20 +10725,24 @@ optional_sort_direction:  empty
 /* type item */
 trim_operands : value_expression
         { 
-            $$ = new (PARSERHEAP()) Trim(Trim::BOTH,
-                 new (PARSERHEAP()) SystemLiteral(" ", WIDE_(" ")), $1); 
+            $$ = new (PARSERHEAP()) Trim
+              (Trim::BOTH,
+               NULL,
+               $1); 
         }
      | TOK_FROM value_expression
         { 
-          $$ = new (PARSERHEAP()) Trim(
-               Trim::BOTH,
-               new (PARSERHEAP()) ConstValue(" ", WIDE_(" ")), $2); 
+          $$ = new (PARSERHEAP()) Trim
+            (Trim::BOTH,
+             NULL,
+             $2); 
         }
      | trim_spec TOK_FROM value_expression
         { 
-          $$ = new (PARSERHEAP()) Trim(
-               $1,
-               new (PARSERHEAP()) ConstValue(" ", WIDE_(" ")), $3); 
+          $$ = new (PARSERHEAP()) Trim
+            ($1,
+             NULL,
+             $3); 
         }
      | value_expression TOK_FROM value_expression
         { $$ = new (PARSERHEAP()) Trim(Trim::BOTH, $1, $3); }
@@ -10706,9 +10754,6 @@ trim_spec : TOK_LEADING     {  $$ = (Int32) Trim::LEADING;  }
         | TOK_TRAILING      {  $$ = (Int32) Trim::TRAILING; }
         | TOK_BOTH          {  $$ = (Int32) Trim::BOTH;     }
 
-
-
-
 /* type stringval */
 date_format : TOK_DEFAULT   
     {  
@@ -11680,17 +11725,50 @@ string_type : tok_char_or_character_or_byte new_optional_left_charlen_right char
             $3.collation_, $3.coercibility_);
          if (checkError3179($$)) YYERROR;
        }
+     | TOK_BINARY 
+       {
+         if (CmpCommon::getDefault(TRAF_BINARY_SUPPORT) == DF_OFF)
+           $$ = new (PARSERHEAP()) SQLChar(PARSERHEAP(),
+                                           DEFAULT_STRING_SIZE, TRUE, FALSE, FALSE);
+         else
+           $$ = new (PARSERHEAP()) SQLBinaryString(PARSERHEAP(),
+                                                   DEFAULT_STRING_SIZE, TRUE, FALSE);
+         if (checkError3179($$)) 
+           YYERROR;
+       }
      | TOK_BINARY left_unsigned_right
        {
          // odbc SQL_BINARY is BINARY(n). Binary data of fixed length n.
-         $$ = new (PARSERHEAP()) SQLChar(PARSERHEAP(), $2, TRUE, FALSE, FALSE);
+         if (CmpCommon::getDefault(TRAF_BINARY_SUPPORT) == DF_OFF)
+           $$ = new (PARSERHEAP()) SQLChar(PARSERHEAP(), $2, TRUE, FALSE, FALSE);
+         else
+           $$ = new (PARSERHEAP()) SQLBinaryString(PARSERHEAP(), $2, TRUE, FALSE);
+         if (checkError3179($$)) YYERROR;
+       }
+     | TOK_VARBINARY
+       {
+         if (CmpCommon::getDefault(TRAF_BINARY_SUPPORT) == DF_OFF)
+           $$ = new (PARSERHEAP()) SQLVarChar(PARSERHEAP(), DEFAULT_STRING_SIZE);
+         else
+           {
+             $$ = new (PARSERHEAP()) SQLBinaryString(PARSERHEAP(), DEFAULT_STRING_SIZE, TRUE, TRUE);
+           }
          if (checkError3179($$)) YYERROR;
        }
      | TOK_VARBINARY left_unsigned_right
        {
-         // odbc SQL_VARBINARY is VARBINARY(n). Variable length binary data 
-         // of maximum length n. The maximum length is set by the user.
-         $$ = new (PARSERHEAP()) SQLVarChar(PARSERHEAP(), $2);
+         if (CmpCommon::getDefault(TRAF_BINARY_SUPPORT) == DF_OFF)
+           $$ = new (PARSERHEAP()) SQLVarChar(PARSERHEAP(), $2);
+         else
+           $$ = new (PARSERHEAP()) SQLBinaryString(PARSERHEAP(), $2, TRUE, TRUE);
+         if (checkError3179($$)) YYERROR;
+       }
+     | TOK_BINARY TOK_VARYING left_unsigned_right
+       {
+         if (CmpCommon::getDefault(TRAF_BINARY_SUPPORT) == DF_OFF)
+           $$ = new (PARSERHEAP()) SQLVarChar(PARSERHEAP(), $3);
+         else
+           $$ = new (PARSERHEAP()) SQLBinaryString(PARSERHEAP(), $3, TRUE, TRUE);
          if (checkError3179($$)) YYERROR;
        }
      | TOK_LONG TOK_VARBINARY
@@ -34025,7 +34103,6 @@ nonreserved_word :      TOK_ABORT
 		      | TOK_HEADER
                       | TOK_HEADING
                       | TOK_HEADINGS
-                      | TOK_HEX
                       | TOK_HEXADECIMAL
                       | TOK_HORIZONTAL
                       | TOK_HIGH_VALUE
@@ -34490,17 +34567,21 @@ nonreserved_func_word:  TOK_ABS
                       | TOK_DIFF1
                       | TOK_DIFF2
                       | TOK_ENCODE_KEY
+                      | TOK_ENCODE_BASE64
+                      | TOK_DECODE_BASE64
                       | TOK_EXP
                       | TOK_EXTEND
                       | TOK_FIRSTDAYOFYEAR
                       | TOK_FLOOR
                       | TOK_FN
+                      | TOK_FROM_HEX
                       | TOK_GREATEST
                       | TOK_GROUPING_ID
                       | TOK_HASHPARTFUNC
                       | TOK_HASH2PARTFUNC
                       | TOK_HBASE_TIMESTAMP
                       | TOK_HBASE_VERSION
+                      | TOK_HEX
                       | TOK_HIVE
                       | TOK_HIVEMD
                       | TOK_INET_ATON
@@ -34587,8 +34668,10 @@ nonreserved_func_word:  TOK_ABS
                       | TOK_TANH
                       | TOK_THIS
                       | TOK_TOKENSTR
+                      | TOK_TO_BINARY
                       | TOK_TO_CHAR
                       | TOK_TO_DATE
+                      | TOK_TO_HEX
                       | TOK_TO_NUMBER
                       | TOK_TO_TIME
                       | TOK_TO_TIMESTAMP
@@ -34651,7 +34734,7 @@ nonreserved_func_word:  TOK_ABS
                       | TOK_EXTERNALTOSTRING
                       | TOK_EMPTY_CLOB
                       | TOK_EMPTY_BLOB
-                      
+                      | TOK_UNHEX
 
 nonreserved_datatype  : TOK_ANSIVARCHAR
                       | TOK_BIGINT
diff --git a/core/sql/parser/ulexer.cpp b/core/sql/parser/ulexer.cpp
index 3021814..f2414dd 100644
--- a/core/sql/parser/ulexer.cpp
+++ b/core/sql/parser/ulexer.cpp
@@ -436,7 +436,8 @@ static NAString *removeConsecutiveQuotes(const NAWchar *s,
   if (literalPrefixCS != CharInfo::UnknownCharSet) // the TOK_SBYTE_LITERAL case
   {
     targetCS = literalPrefixCS;
-    PARSERASSERT(targetCS == CharInfo::ISO88591 || targetCS == CharInfo::UTF8);
+    PARSERASSERT(targetCS == CharInfo::ISO88591 || targetCS == CharInfo::UTF8
+                 || targetCS == CharInfo::BINARY);
     //
     // Note that an _ISO88591'string-literal' may contain Western European characters
     // (i.e., 0 <= code_points < 255).
@@ -1095,6 +1096,8 @@ Int32 yyULexer::yylex(YYSTYPE *lvalp)
               cs = CharInfo::getCharSetEnum(csName);
               if (CharInfo::isCharSetFullySupported(cs))
                 {
+                  if (cs == CharInfo::BINARY)
+                    isHexStringLiteral = TRUE;
                   return constructStringLiteralWithCharSet(isHexStringLiteral, cs, lvalp, quote);
                 } 
               else if (cs != CharInfo::UnknownCharSet)
@@ -2834,6 +2837,7 @@ Int32 yyULexer::yylex(YYSTYPE *lvalp)
 	  if ( cc == L'\'' ){
 	      return constructStringLiteralWithCharSet(TRUE, 
 						       SqlParser_DEFAULT_CHARSET,
+                                                       //CharInfo::BINARY,
 						       lvalp,
 						       L'\'');
 	  }
diff --git a/core/sql/regress/charsets/EXPECTED315 b/core/sql/regress/charsets/EXPECTED315
index 7f5a8e0..ce8c570 100644
--- a/core/sql/regress/charsets/EXPECTED315
+++ b/core/sql/regress/charsets/EXPECTED315
@@ -1327,6 +1327,30 @@ C3B6C3B6E0A0A0
 abxyg           
 
 --- 1 row(s) selected.
+>>select stuff ('abcdefg', 1, 0, 'xy') from dual;
+
+(EXPR)          
+----------------
+
+xyabcdefg       
+
+--- 1 row(s) selected.
+>>select unhex(hex((overlay(to_binary('abcdefg') placing to_binary('wx') from 2 for 3)))) from dual;
+
+(EXPR)          
+----------------
+
+awxefg          
+
+--- 1 row(s) selected.
+>>select unhex(hex((overlay(to_binary('abcdefg') placing 'wx' from 2 for 3)))) from dual;
+
+(EXPR)          
+----------------
+
+awxefg          
+
+--- 1 row(s) selected.
 >>
 >>-- OVERLAY error cases
 >>select overlay('w1234567xyz' placing 'abcde' from 1.2 for 4)  from dual;
diff --git a/core/sql/regress/charsets/TEST315 b/core/sql/regress/charsets/TEST315
index 15342e7..5719fcf 100644
--- a/core/sql/regress/charsets/TEST315
+++ b/core/sql/regress/charsets/TEST315
@@ -325,6 +325,9 @@ select overlay(cast(NULL as char(10)) placing 'abcde' from 30 for 6)  from dual;
 select converttohex(overlay (uf8 placing uf8v from 4 for 2)) from cs315t4;
 select converttohex(overlay(_utf8 x'C3B6C3BAC3BBE0A0A0' placing _UTF8 x'C3B6'  from  2 for 2)) from dual;
 select stuff ('abcdefg', 3, 4, 'xy') from dual;
+select stuff ('abcdefg', 1, 0, 'xy') from dual;
+select unhex(hex((overlay(to_binary('abcdefg') placing to_binary('wx') from 2 for 3)))) from dual;
+select unhex(hex((overlay(to_binary('abcdefg') placing 'wx' from 2 for 3)))) from dual;
 
 -- OVERLAY error cases
 select overlay('w1234567xyz' placing 'abcde' from 1.2 for 4)  from dual;
diff --git a/core/sql/regress/core/EXPECTED038.LINUX b/core/sql/regress/core/EXPECTED038.LINUX
index 49cb975..5051a2d 100644
--- a/core/sql/regress/core/EXPECTED038.LINUX
+++ b/core/sql/regress/core/EXPECTED038.LINUX
@@ -692,8 +692,8 @@ EMPNUM       EMPNAME               DEPTNUM      DEPTNUM      DEPTNAME
 -----------  --------------------  -----------  -----------  --------------------  --------------------  -----------  -----------  ------------
 
         100  RAO                          6500         6500  QA                    DENNIS                          ?            ?             ?
-        100  GANESAN                      6400         6400  DEV                   YOW                           101         6400     10000.000
         100  BHAVE                        6400         6400  DEV                   YOW                           101         6400     10000.000
+        100  GANESAN                      6400         6400  DEV                   YOW                           101         6400     10000.000
 
 --- 3 row(s) selected.
 >>SELECT *
@@ -3129,22 +3129,22 @@ E1
 >>
 >>select * from T038g where cast(g1 as numeric(1)) = cast (-8 as numeric(1)) - 1;
 
-*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:SMALLINT SIGNED(REC_BIN16_SIGNED).
+*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:NUMERIC(1, 0)(REC_BIN16_SIGNED).
 
 --- 0 row(s) selected.
 >>select * from T038g where cast(g1 as numeric(1)) = cast (-9 as numeric(1)) - 1;
 
-*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:SMALLINT SIGNED(REC_BIN16_SIGNED).
+*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:NUMERIC(1, 0)(REC_BIN16_SIGNED).
 
 --- 0 row(s) selected.
 >>select * from T038g where cast(g1 as numeric(1)) = cast (8 as numeric(1)) + 1;
 
-*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:SMALLINT SIGNED(REC_BIN16_SIGNED).
+*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:NUMERIC(1, 0)(REC_BIN16_SIGNED).
 
 --- 0 row(s) selected.
 >>select * from T038g where cast(g1 as numeric(1)) = cast (9 as numeric(1)) + 1;
 
-*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:SMALLINT SIGNED(REC_BIN16_SIGNED).
+*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:123456 to Target Type:NUMERIC(1, 0)(REC_BIN16_SIGNED).
 
 --- 0 row(s) selected.
 >>select * from T038g where g1 = cast (1 as numeric(1)) / cast (0 as numeric(1));
diff --git a/core/sql/regress/executor/EXPECTED022.SB b/core/sql/regress/executor/EXPECTED022.SB
index b1ad245..324058a 100644
--- a/core/sql/regress/executor/EXPECTED022.SB
+++ b/core/sql/regress/executor/EXPECTED022.SB
@@ -1974,7 +1974,7 @@ Hello
 --- 0 row(s) selected.
 >>select cast (cast (32768 as decimal(5)) as smallint) from dual;
 
-*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:32768 to Target Type:SMALLINT SIGNED(REC_BIN16_SIGNED).
+*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:32768 to Target Type:SMALLINT(REC_BIN16_SIGNED).
 
 --- 0 row(s) selected.
 >>select cast (cast (-10 as decimal(2)) as numeric(1)) from dual;
@@ -2065,7 +2065,7 @@ Hello
 >>
 >>select cast (cast (32768 as decimal(5) unsigned) as smallint) from dual;
 
-*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:32768 to Target Type:SMALLINT SIGNED(REC_BIN16_SIGNED).
+*** ERROR[8411] A numeric overflow occurred during an arithmetic computation or data conversion. Intermediate conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:32768 to Target Type:SMALLINT(REC_BIN16_SIGNED).
 
 --- 0 row(s) selected.
 >>select cast (cast (10 as decimal(2) unsigned) as numeric(1)) from dual;
@@ -3928,12 +3928,12 @@ Hello
 >>-- negative test on cast smallint to VAR/NCAR 
 >>select cast(cast(N'65535' as SMALLINT UNSIGNED) as NCHAR(1)) from dual;
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:65535 to Target Type:CHAR(REC_BYTE_F_ASCII,1 BYTES,UTF8).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:65535 to Target Type:CHAR(1) CHARACTER SET UCS2(REC_BYTE_F_ASCII).
 
 --- 0 row(s) selected.
 >>select cast(cast(N'-5535' as SMALLINT SIGNED) as NCHAR VARYING(1)) from dual;
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:-5535 to Target Type:VARCHAR(REC_BYTE_V_ASCII,1 BYTES,UTF8).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:-5535 to Target Type:VARCHAR(1) CHARACTER SET UCS2(REC_BYTE_V_ASCII).
 
 --- 0 row(s) selected.
 >>
@@ -3979,7 +3979,7 @@ Hello
 --- 0 row(s) selected.
 >>select cast(cast(N'-10' as integer) as nchar(1)) from dual;
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:-10 to Target Type:CHAR(REC_BYTE_F_ASCII,1 BYTES,UTF8).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:-10 to Target Type:CHAR(1) CHARACTER SET UCS2(REC_BYTE_F_ASCII).
 
 --- 0 row(s) selected.
 >>select cast(cast(N'2147483648' as integer) as nchar varying(1)) from dual;
@@ -4021,7 +4021,7 @@ Hello
 >>-- negative test on cast DEC to VAR/NCAR 
 >>select cast(cast(N'12345.56' as DEC (7,2) unsigned) as nchar(2)) from dual;
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:12345.56 to Target Type:CHAR(REC_BYTE_F_ASCII,2 BYTES,UTF8).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:LARGEINT(REC_BIN64_SIGNED) Source Value:12345.56 to Target Type:CHAR(2) CHARACTER SET UCS2(REC_BYTE_F_ASCII).
 
 --- 0 row(s) selected.
 >>
@@ -4514,12 +4514,12 @@ IU          SS
 >>-- should return truncation error
 >>insert into t022u2 (a) values ('abcdefghijkl');
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:VARCHAR(REC_BYTE_V_ASCII,12 BYTES,ISO88591) Source Value:abcdefghijkl to Target Type:CHAR(REC_BYTE_F_ASCII,10 BYTES,ISO88591).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:VARCHAR(12) CHARACTER SET ISO88591(REC_BYTE_V_ASCII) Source Value:abcdefghijkl to Target Type:CHAR(10) CHARACTER SET ISO88591(REC_BYTE_F_ASCII).
 
 --- 0 row(s) inserted.
 >>update t022u2 set a = 'abcdefghijkl';
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:CHAR(REC_BYTE_F_ASCII,12 BYTES,ISO88591) Source Value:abcdefghijkl to Target Type:CHAR(REC_BYTE_F_ASCII,10 BYTES,ISO88591).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:CHAR(12) CHARACTER SET ISO88591(REC_BYTE_F_ASCII) Source Value:abcdefghijkl to Target Type:CHAR(10) CHARACTER SET ISO88591(REC_BYTE_F_ASCII).
 
 --- 0 row(s) updated.
 >>
diff --git a/core/sql/regress/executor/EXPECTED050 b/core/sql/regress/executor/EXPECTED050
index e963454..ec2d159 100755
--- a/core/sql/regress/executor/EXPECTED050
+++ b/core/sql/regress/executor/EXPECTED050
@@ -468,7 +468,7 @@ zz     ZZ     ZZ               1            1            1
 >>-- Ansi 6.13 GR 2:  char and varchar concats are different vis-a-vis length
 >>update T050a set b=a, c=trim(lower(b))||trim(a);
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:VARCHAR(REC_BYTE_V_ASCII,6 BYTES,ISO88591) Source Value:UPPLOW to Target Type:CHAR(REC_BYTE_F_ASCII,5 BYTES,ISO88591).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:VARCHAR(6) CHARACTER SET ISO88591(REC_BYTE_V_ASCII) Source Value:UPPLOW to Target Type:CHAR(5) CHARACTER SET ISO88591(REC_BYTE_F_ASCII).
 
 --- 0 row(s) updated.
 >>		-- 1 warn 8402
@@ -485,7 +485,7 @@ zz     ZZ     ZZ               1            1            1
 >>		-- aa,AA,BBAA; Low,LOW,UPPLO; zz,ZZ,ZZZZ
 >>update T050a set b=a, c=lower(b)||a;
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:CHAR(REC_BYTE_F_ASCII,10 BYTES,ISO88591) Source Value:BB   AA    to Target Type:CHAR(REC_BYTE_F_ASCII,5 BYTES,ISO88591).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:CHAR(10) CHARACTER SET ISO88591(REC_BYTE_F_ASCII) Source Value:BB   AA    to Target Type:CHAR(5) CHARACTER SET ISO88591(REC_BYTE_F_ASCII).
 
 --- 0 row(s) updated.
 >>				-- 3 ERROR 8402
diff --git a/core/sql/regress/seabase/EXPECTED002 b/core/sql/regress/seabase/EXPECTED002
index 2d79c5e..4b52ce0 100644
--- a/core/sql/regress/seabase/EXPECTED002
+++ b/core/sql/regress/seabase/EXPECTED002
@@ -1265,6 +1265,9 @@ hive
 *** WARNING[8742] GetMetaDataInfo operation could not be completed. Reason: Datatype array<string> for column 'a' in table hive.hive.thivearr is not supported. This table will be ignored.
 
 --- 0 row(s) selected.
+>>process hive ddl 'drop table thivearr';
+
+--- SQL operation complete.
 >>
 >>process hive ddl 'drop table thivealldt';
 
diff --git a/core/sql/regress/seabase/EXPECTED004 b/core/sql/regress/seabase/EXPECTED004
new file mode 100644
index 0000000..2bc5093
--- /dev/null
+++ b/core/sql/regress/seabase/EXPECTED004
@@ -0,0 +1,603 @@
+>>
+>>cqd traf_binary_support 'ON';
+
+--- SQL operation complete.
+>>cqd traf_binary_input 'ON';
+
+--- SQL operation complete.
+>>cqd traf_binary_output 'ON';
+
+--- SQL operation complete.
+>>
+>>obey TEST004(setup_binary);
+>>-----------------------------------------------------------
+>>-------------- BINARY datatype ---------------------------
+>>-----------------------------------------------------------
+>>
+>>drop table if exists t004t3 cascade;
+
+--- SQL operation complete.
+>>drop table if exists t004t3_like;
+
+--- SQL operation complete.
+>>drop table if exists t004t3_as;
+
+--- SQL operation complete.
+>>
+>>create table t004t3(a binary(5) not null primary key, b varbinary(10));
+
+--- SQL operation complete.
+>>invoke t004t3;
+
+-- Definition of Trafodion table TRAFODION.SCH.T004T3
+-- Definition current  Mon Aug 13 23:34:27 2018
+
+  (
+    A                                BINARY(5) NO DEFAULT NOT NULL NOT
+      DROPPABLE
+  , B                                VARBINARY(10) DEFAULT NULL
+  )
+  PRIMARY KEY (A ASC)
+
+--- SQL operation complete.
+>>
+>>create table if not exists t004t3_like like t004t3;
+
+--- SQL operation complete.
+>>invoke t004t3_like;
+
+-- Definition of Trafodion table TRAFODION.SCH.T004T3_LIKE
+-- Definition current  Mon Aug 13 23:34:37 2018
+
+  (
+    A                                BINARY(5) NO DEFAULT NOT NULL NOT
+      DROPPABLE
+  , B                                VARBINARY(10) DEFAULT NULL
+  )
+  PRIMARY KEY (A ASC)
+
+--- SQL operation complete.
+>>
+>>create table if not exists t004t3_as primary key (a) as select * from t004t3;
+
+--- 0 row(s) inserted.
+>>invoke t004t3_as;
+
+-- Definition of Trafodion table TRAFODION.SCH.T004T3_AS
+-- Definition current  Mon Aug 13 23:34:44 2018
+
+  (
+    A                                BINARY(5) NO DEFAULT NOT NULL NOT
+      DROPPABLE
+  , B                                VARBINARY(10) DEFAULT NULL
+  )
+  PRIMARY KEY (A ASC)
+
+--- SQL operation complete.
+>>
+>>create table if not exists t004t3_salt(a binary(4) not null primary key)
++>  salt using 2 partitions;
+
+--- SQL operation complete.
+>>invoke t004t3_salt;
+
+-- Definition of Trafodion table TRAFODION.SCH.T004T3_SALT
+-- Definition current  Mon Aug 13 23:34:46 2018
+
+  (
+    A                                BINARY(4) NO DEFAULT NOT NULL NOT
+      DROPPABLE
+  , "_SALT_"                         INT UNSIGNED NO DEFAULT NOT NULL NOT
+      DROPPABLE
+  )
+  PRIMARY KEY ("_SALT_" ASC, A ASC)
+
+--- SQL operation complete.
+>>
+>>create view t004t3_view as select * from t004t3;
+
+--- SQL operation complete.
+>>invoke t004t3_view;
+
+-- Definition of Trafodion view TRAFODION.SCH.T004T3_VIEW
+-- Definition current  Mon Aug 13 23:34:50 2018
+
+  (
+    A                                BINARY(5) NO DEFAULT NOT NULL NOT
+      DROPPABLE
+  , B                                VARBINARY(10) DEFAULT NULL
+  )
+
+--- SQL operation complete.
+>>
+>>obey TEST004(dml_binary);
+>>insert into t004t3 values ('ab', 123);
+
+--- 1 row(s) inserted.
+>>insert into t004t3 values (234, 'ba');
+
+--- 1 row(s) inserted.
+>>
+>>select to_hex(a), to_hex(b) from t004t3;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+6162000000  7B00                
+EA00000000  6261                
+
+--- 2 row(s) selected.
+>>select to_hex(left(a, 1)) from t004t3;
+
+(EXPR)
+------
+
+61    
+EA    
+
+--- 2 row(s) selected.
+>>select to_hex(b || 'a') from t004t3;
+
+(EXPR)                
+----------------------
+
+7B0061                
+626161                
+
+--- 2 row(s) selected.
+>>select to_hex( a || 'a') from t004t3;
+
+(EXPR)      
+------------
+
+616200000061
+EA0000000061
+
+--- 2 row(s) selected.
+>>
+>>insert into t004t3_as select * from t004t3;
+
+--- 2 row(s) inserted.
+>>select to_hex(a), to_hex(b) from t004t3_as;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+6162000000  7B00                
+EA00000000  6261                
+
+--- 2 row(s) selected.
+>>
+>>select cast(to_binary('ab') as char(10)) from dual;
+
+(EXPR)    
+----------
+
+ab        
+
+--- 1 row(s) selected.
+>>
+>>select * from t004t3 where a = to_binary('ab');
+
+A           B                   
+----------  --------------------
+
+6162000000  7B00                
+
+--- 1 row(s) selected.
+>>
+>>select to_hex(cast(10 as binary(4))) from dual;
+
+(EXPR)  
+--------
+
+0A000000
+
+--- 1 row(s) selected.
+>>select to_hex(cast(-10 as binary(4))) from dual;
+
+(EXPR)  
+--------
+
+F6FF0000
+
+--- 1 row(s) selected.
+>>select cast(10 as binary(4)) from dual;
+
+(EXPR)  
+--------
+
+0A000000
+
+--- 1 row(s) selected.
+>>select cast(-10 as binary(4)) from dual;
+
+(EXPR)  
+--------
+
+F6FF0000
+
+--- 1 row(s) selected.
+>>
+>>select cast(to_binary(12.34) as smallint) from dual;
+
+(EXPR)
+------
+
+  1234
+
+--- 1 row(s) selected.
+>>select cast(to_binary(12.34) as numeric(4,2)) from dual;
+
+(EXPR) 
+-------
+
+  12.34
+
+--- 1 row(s) selected.
+>>
+>>select cast(cast(10 as binary(4)) as  int) from dual;
+
+(EXPR)     
+-----------
+
+         10
+
+--- 1 row(s) selected.
+>>
+>>select to_hex(cast(a as binary(10))), 
++>       to_hex(cast (b as varbinary(11))) from t004t3;
+
+(EXPR)                (EXPR)                
+--------------------  ----------------------
+
+61620000000000000000  7B00                  
+EA000000000000000000  6261                  
+
+--- 2 row(s) selected.
+>>
+>>select char_length(a), char_length(b) from t004t3;
+
+(EXPR)      (EXPR)    
+----------  ----------
+
+         5           2
+         5           2
+
+--- 2 row(s) selected.
+>>select octet_length(a), octet_length(b) from t004t3;
+
+(EXPR)      (EXPR)    
+----------  ----------
+
+         5           2
+         5           2
+
+--- 2 row(s) selected.
+>>
+>>delete from t004t3;
+
+--- 2 row(s) deleted.
+>>prepare s from insert into t004t3 values (?, ?);
+
+--- SQL command prepared.
+>>execute s using 1, 'abc';
+
+--- 1 row(s) inserted.
+>>execute s using 'x', 20.34;
+
+--- 1 row(s) inserted.
+>>select to_hex(a), to_hex(b) from t004t3;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+3100000000  616263              
+7800000000  32302E3334          
+
+--- 2 row(s) selected.
+>>
+>>begin work;
+
+--- SQL operation complete.
+>>delete from t004t3 where a = to_binary('x');
+
+--- 1 row(s) deleted.
+>>select to_hex(a), to_hex(b) from t004t3;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+3100000000  616263              
+
+--- 1 row(s) selected.
+>>rollback work;
+
+--- SQL operation complete.
+>>select to_hex(a), to_hex(b) from t004t3;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+3100000000  616263              
+7800000000  32302E3334          
+
+--- 2 row(s) selected.
+>>
+>>begin work;
+
+--- SQL operation complete.
+>>update t004t3 set b = 1;
+
+--- 2 row(s) updated.
+>>select to_hex(a), to_hex(b) from t004t3;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+3100000000  01                  
+7800000000  01                  
+
+--- 2 row(s) selected.
+>>rollback work;
+
+--- SQL operation complete.
+>>select to_hex(a), to_hex(b) from t004t3;
+
+(EXPR)      (EXPR)              
+----------  --------------------
+
+3100000000  616263              
+7800000000  32302E3334          
+
+--- 2 row(s) selected.
+>>
+>>select to_binary(10000000) from dual;
+
+(EXPR)  
+--------
+
+80969800
+
+--- 1 row(s) selected.
+>>
+>>-- select after turning off traf_binary_output. 
+>>-- this is to test selects from clients which not yet support binary datatype
+>>cqd traf_binary_output 'OFF';
+
+--- SQL operation complete.
+>>select a,b from t004t3;
+
+A           B                   
+----------  --------------------
+
+3100000000  616263              
+7800000000  32302E3334          
+
+--- 2 row(s) selected.
+>>select to_binary(10000000) from dual;
+
+(EXPR)  
+--------
+
+80969800
+
+--- 1 row(s) selected.
+>>cqd traf_binary_output 'ON';
+
+--- SQL operation complete.
+>>
+>>-- input after turning off traf_binary_input.
+>>-- this is to test inserts from clients which do not yet support binary datatype
+>>-- params are typed as char/varchar in this case.
+>>cqd traf_binary_input 'OFF';
+
+--- SQL operation complete.
+>>begin work;
+
+--- SQL operation complete.
+>>prepare s from insert into t004t3 values (?,?);
+
+--- SQL command prepared.
+>>execute s using 'abc', 'xyz';
+
+--- 1 row(s) inserted.
+>>select * from t004t3;
+
+A           B                   
+----------  --------------------
+
+3100000000  616263              
+6162632020  78797A              
+7800000000  32302E3334          
+
+--- 3 row(s) selected.
+>>rollback work;
+
+--- SQL operation complete.
+>>cqd traf_binary_input 'ON';
+
+--- SQL operation complete.
+>>
+>>-- return warning and truncate 2 digits.
+>>select cast(to_binary(10000000) as binary(2)) from dual;
+
+*** WARNING[8408] An error occurred during the evaluation of a conversion expression. Details: Conversion of Source Type:BINARY(4)(REC_BINARY_STRING) Source Value:0x80969800 to Target Type:BINARY(2)(REC_BINARY_STRING).
+
+(EXPR)
+------
+
+8096  
+
+--- 1 row(s) selected.
+>>
+>>obey TEST004(errors_binary);
+>>select * from t004t3 where a = 'ab';
+
+*** ERROR[4041] Type BINARY(5)  cannot be compared with type CHAR(2) CHARACTER SET ISO88591.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>select b + 1 from t004t3;
+
+*** ERROR[4034] The operation (VARBINARY(10) + NUMERIC(1))  is not allowed.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>select -b from t004t3;
+
+*** ERROR[4034] The operation (NUMERIC(1) - VARBINARY(10))  is not allowed.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>select * from t004t3 where a = 1;
+
+*** ERROR[4041] Type BINARY(5) cannot be compared with type NUMERIC(1).
+
+*** ERROR[8822] The statement was not prepared.
+
+>>select cast(100 as binary(1)) from dual;
+
+*** ERROR[8408] An error occurred during the evaluation of a conversion expression. Details: Conversion of Source Type:NUMERIC(3, 0)(REC_BIN16_SIGNED) Source Value:100 to Target Type:BINARY(1)(REC_BINARY_STRING).
+
+--- 0 row(s) selected.
+>>select cast(to_binary(1) as date) from dual;
+
+*** ERROR[8408] An error occurred during the evaluation of a conversion expression. Details: Conversion of Source Type:BINARY(1)(REC_BINARY_STRING) Source Value:0x01 to Target Type:DATE(REC_DATETIME).
+
+--- 0 row(s) selected.
+>>select cast(to_binary('ab') as char(1)) from dual;
+
+*** ERROR[8408] An error occurred during the evaluation of a conversion expression. Details: Conversion of Source Type:BINARY(2)(REC_BINARY_STRING) Source Value:0x6162 to Target Type:CHAR(1) CHARACTER SET ISO88591(REC_BYTE_F_ASCII).
+
+--- 0 row(s) selected.
+>>select cast(to_binary(12.34) as int) from dual;
+
+*** ERROR[8408] An error occurred during the evaluation of a conversion expression. Details: Conversion of Source Type:BINARY(2)(REC_BINARY_STRING) Source Value:0xD204 to Target Type:INT(REC_BIN32_SIGNED).
+
+--- 0 row(s) selected.
+>>
+>>obey TEST004(hive_binary);
+>>-- create and populate hive binary datatype from hive
+>>process hive ddl 'drop table tbinary';
+
+--- SQL operation complete.
+>>process hive ddl 'create table tbinary(a binary)';
+
+--- SQL operation complete.
+>>sh echo "insert into tbinary values ('a'), (1), (NULL);" > TEST004_junk;
+>>sh regrhive.ksh -f TEST004_junk;
+>>
+>>cqd hive_max_binary_length '10';
+
+--- SQL operation complete.
+>>invoke hive.hive.tbinary;
+
+-- Definition of hive table HIVE.HIVE.TBINARY
+-- Definition current  Mon Aug 13 23:35:31 2018
+
+  (
+    A                                VARBINARY(10)
+  )
+  /* stored as textfile */
+
+--- SQL operation complete.
+>>select to_hex(a) from hive.hive.tbinary;
+
+(EXPR)              
+--------------------
+
+61                  
+31                  
+?                   
+
+--- 3 row(s) selected.
+>>insert into hive.hive.tbinary values ('a'), (1), (null);
+
+--- 3 row(s) inserted.
+>>select * from hive.hive.tbinary;
+
+A                   
+--------------------
+
+61                  
+31                  
+?                   
+61                  
+31                  
+?                   
+
+--- 6 row(s) selected.
+>>select to_hex(a) from hive.hive.tbinary;
+
+(EXPR)              
+--------------------
+
+61                  
+31                  
+?                   
+61                  
+31                  
+?                   
+
+--- 6 row(s) selected.
+>>insert overwrite table hive.hive.tbinary select a from t004t3;
+
+--- 2 row(s) inserted.
+>>select to_hex(a) from hive.hive.tbinary;
+
+(EXPR)              
+--------------------
+
+3100000000          
+7800000000          
+
+--- 2 row(s) selected.
+>>
+>>prepare s from insert into hive.hive.tbinary values (?);
+
+--- SQL command prepared.
+>>execute s using x'1020';
+
+--- 1 row(s) inserted.
+>>set param ?p x'3040';
+>>insert into hive.hive.tbinary values (?p);
+
+--- 1 row(s) inserted.
+>>select a from hive.hive.tbinary;
+
+A                   
+--------------------
+
+3100000000          
+7800000000          
+1020                
+3040                
+
+--- 4 row(s) selected.
+>>select * from hive.hive.tbinary where a = _binary x'1020';
+
+A                   
+--------------------
+
+1020                
+
+--- 1 row(s) selected.
+>>
+>>select cast(column_name as char(30) character set iso88591), 
++>       sql_data_type, fs_data_type, hive_data_type,
++>       column_size, column_scale, 
++>       column_number, part_col_number, bucket_col_number, sort_col_number
++>  from table(hivemd(columns))
++>  where table_name = 'tbinary'
++>  order by column_number;
+
+(EXPR)                          SQL_DATA_TYPE                     FS_DATA_TYPE  HIVE_DATA_TYPE                    COLUMN_SIZE  COLUMN_SCALE  COLUMN_NUMBER  PART_COL_NUMBER  BUCKET_COL_NUMBER  SORT_COL_NUMBER
+------------------------------  --------------------------------  ------------  --------------------------------  -----------  ------------  -------------  ---------------  -----------------  ---------------
+
+a                               VARBINARY                                   69  binary                                     10            -1              0               -1                 -1               -1
+
+--- 1 row(s) selected.
+>>
+>>
+>>log;
diff --git a/core/sql/regress/seabase/EXPECTED027 b/core/sql/regress/seabase/EXPECTED027
index 0972679..73c0f72 100644
--- a/core/sql/regress/seabase/EXPECTED027
+++ b/core/sql/regress/seabase/EXPECTED027
@@ -15,7 +15,7 @@
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:09:22 2017
+-- Definition current  Mon Nov  6 11:03:38 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -43,7 +43,7 @@ CREATE TABLE TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:09:35 2017
+-- Definition current  Mon Nov  6 11:03:56 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -72,7 +72,7 @@ CREATE TABLE TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:09:45 2017
+-- Definition current  Mon Nov  6 11:04:04 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -104,7 +104,7 @@ CREATE TABLE TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:09:55 2017
+-- Definition current  Mon Nov  6 11:04:12 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -134,7 +134,7 @@ CREATE TABLE TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:10:02 2017
+-- Definition current  Mon Nov  6 11:04:19 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -199,7 +199,7 @@ A            B            C
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:10:13 2017
+-- Definition current  Mon Nov  6 11:04:26 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -237,7 +237,7 @@ CREATE INDEX T027T01I1 ON TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:10:21 2017
+-- Definition current  Mon Nov  6 11:04:31 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -277,7 +277,7 @@ CREATE INDEX T027T01I1 ON TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:10:25 2017
+-- Definition current  Mon Nov  6 11:04:35 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -315,7 +315,7 @@ CREATE INDEX T027T01I1 ON TRAFODION.SCH027.T027T01
 >>invoke t027t01;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T01
--- Definition current  Fri Mar 17 06:10:28 2017
+-- Definition current  Mon Nov  6 11:04:38 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -355,7 +355,7 @@ CREATE INDEX T027T01I1 ON TRAFODION.SCH027.T027T01
 >>invoke t027t011;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T011
--- Definition current  Fri Mar 17 06:10:34 2017
+-- Definition current  Mon Nov  6 11:04:45 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -400,7 +400,7 @@ A            B            C            E            D
 >>invoke t027t011;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T011
--- Definition current  Fri Mar 17 06:10:37 2017
+-- Definition current  Mon Nov  6 11:04:47 2017
 
   (
     "cf".A                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -440,7 +440,7 @@ CREATE TABLE TRAFODION.SCH027.T027T011
 >>invoke t027t011;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T011
--- Definition current  Fri Mar 17 06:10:45 2017
+-- Definition current  Mon Nov  6 11:05:00 2017
 
   (
     SYSKEY                           LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -475,7 +475,7 @@ CREATE TABLE TRAFODION.SCH027.T027T011
 >>invoke t027t011;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T011
--- Definition current  Fri Mar 17 06:10:52 2017
+-- Definition current  Mon Nov  6 11:05:07 2017
 
   (
     SYSKEY                           LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -507,7 +507,7 @@ CREATE TABLE TRAFODION.SCH027.T027T011
 >>invoke t027t03;
 
 -- Definition of Trafodion volatile table T027T03
--- Definition current  Fri Mar 17 06:11:08 2017
+-- Definition current  Mon Nov  6 11:05:24 2017
 
   (
     "cf1".A                          INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -539,7 +539,7 @@ CREATE VOLATILE TABLE T027T03
 >>invoke t027t03;
 
 -- Definition of Trafodion volatile table T027T03
--- Definition current  Fri Mar 17 06:11:42 2017
+-- Definition current  Mon Nov  6 11:05:54 2017
 
   (
     "cf1".A                          INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -588,7 +588,7 @@ CREATE VOLATILE TABLE T027T03
 >>invoke t027t02;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T02
--- Definition current  Fri Mar 17 06:12:21 2017
+-- Definition current  Mon Nov  6 11:06:30 2017
 
   (
     "cf".SYSKEY                      LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -640,7 +640,7 @@ CREATE VOLATILE TABLE T027T03
 >>invoke t027t03;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T03
--- Definition current  Fri Mar 17 06:12:54 2017
+-- Definition current  Mon Nov  6 11:07:05 2017
 
   (
     "cf1".A                          INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -677,7 +677,7 @@ A            B            C            D
 >>invoke t027t02;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T02
--- Definition current  Fri Mar 17 06:13:14 2017
+-- Definition current  Mon Nov  6 11:07:24 2017
 
   (
     OBJECT_UID                       LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -790,7 +790,7 @@ create index t027t01i2 on t027t01("cf2".b);
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:13:52 2017
+-- Definition current  Mon Nov  6 11:08:04 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -822,7 +822,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:14:06 2017
+-- Definition current  Mon Nov  6 11:08:17 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -843,7 +843,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:14:44 2017
+-- Definition current  Mon Nov  6 11:08:55 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -864,7 +864,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:15:18 2017
+-- Definition current  Mon Nov  6 11:09:32 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -886,7 +886,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:15:52 2017
+-- Definition current  Mon Nov  6 11:10:08 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -907,7 +907,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:16:26 2017
+-- Definition current  Mon Nov  6 11:10:44 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -928,7 +928,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:17:04 2017
+-- Definition current  Mon Nov  6 11:11:19 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -949,7 +949,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:17:38 2017
+-- Definition current  Mon Nov  6 11:11:51 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -970,7 +970,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:18:11 2017
+-- Definition current  Mon Nov  6 11:12:26 2017
 
   (
     A                                INT DEFAULT NULL /*altered_col*/
@@ -991,7 +991,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:18:44 2017
+-- Definition current  Mon Nov  6 11:13:02 2017
 
   (
     A                                SMALLINT DEFAULT 0 NOT NULL NOT DROPPABLE
@@ -1028,7 +1028,7 @@ A       B   C       Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:19:18 2017
+-- Definition current  Mon Nov  6 11:13:38 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -1060,7 +1060,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:19:59 2017
+-- Definition current  Mon Nov  6 11:14:16 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -1089,7 +1089,7 @@ A                     B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:20:41 2017
+-- Definition current  Mon Nov  6 11:14:58 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -1116,7 +1116,7 @@ A                     C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:20:55 2017
+-- Definition current  Mon Nov  6 11:15:10 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -1145,7 +1145,7 @@ A                     C                 Z            B
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:21:36 2017
+-- Definition current  Mon Nov  6 11:15:51 2017
 
   (
     A                                LARGEINT DEFAULT NULL /*altered_col*/
@@ -1183,7 +1183,7 @@ TRAFODION.SCH027.T027V1
 >>invoke t027v1;
 
 -- Definition of Trafodion view TRAFODION.SCH027.T027V1
--- Definition current  Fri Mar 17 06:21:54 2017
+-- Definition current  Mon Nov  6 11:16:08 2017
 
   (
     A                                LARGEINT DEFAULT NULL
@@ -1199,7 +1199,7 @@ TRAFODION.SCH027.T027V1
 >>invoke t027v1;
 
 -- Definition of Trafodion view TRAFODION.SCH027.T027V1
--- Definition current  Fri Mar 17 06:22:46 2017
+-- Definition current  Mon Nov  6 11:17:02 2017
 
   (
     A                                SMALLINT DEFAULT NULL
@@ -1223,7 +1223,7 @@ TRAFODION.SCH027.T027V1
 --- SQL operation failed with errors.
 >>alter table t027t7 alter column c char(1);
 
-*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:VARCHAR(REC_BYTE_V_ASCII,2 BYTES,ISO88591) Source Value:cd to Target Type:CHAR(REC_BYTE_F_ASCII,1 BYTES,ISO88591).
+*** ERROR[8402] A string overflow occurred during the evaluation of a character expression. Conversion of Source Type:VARCHAR(2) CHARACTER SET ISO88591(REC_BYTE_V_ASCII) Source Value:cd to Target Type:CHAR(1) CHARACTER SET ISO88591(REC_BYTE_F_ASCII).
 
 *** ERROR[1404] Column C cannot be altered. Reason: Old data could not be updated using the altered column definition.
 
@@ -1276,7 +1276,7 @@ TRAFODION.SCH027.T027V1
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:25:45 2017
+-- Definition current  Mon Nov  6 11:20:11 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -1305,7 +1305,7 @@ A            B   C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:26:05 2017
+-- Definition current  Mon Nov  6 11:20:30 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -1334,7 +1334,7 @@ A            BB  C                 Z
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:26:23 2017
+-- Definition current  Mon Nov  6 11:20:48 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -1543,7 +1543,7 @@ TRAFODION.SCH027.T027V122
 >>invoke t027t7;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T7
--- Definition current  Fri Mar 17 06:33:35 2017
+-- Definition current  Mon Nov  6 11:27:14 2017
 
   (
     SYSKEY                           INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -1567,7 +1567,7 @@ TRAFODION.SCH027.T027V122
 >>invoke t027t1;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T1
--- Definition current  Fri Mar 17 06:33:56 2017
+-- Definition current  Mon Nov  6 11:27:48 2017
 
   (
     SYSKEY                           LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -1598,7 +1598,7 @@ A            B            C            D            E            F            G
 >>invoke t027t1;
 
 -- Definition of Trafodion table TRAFODION.SCH027.T027T1
--- Definition current  Fri Mar 17 06:34:13 2017
+-- Definition current  Mon Nov  6 11:28:01 2017
 
   (
     SYSKEY                           LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
diff --git a/core/sql/regress/seabase/TEST002 b/core/sql/regress/seabase/TEST002
index 081793f..4c014c9 100644
--- a/core/sql/regress/seabase/TEST002
+++ b/core/sql/regress/seabase/TEST002
@@ -232,6 +232,7 @@ process hive statement 'drop table thivearr';
 process hive statement 'create table thivearr (a array<string>)';
 -- should return warning 8742
 select table_name from table(hivemd(columns)) where table_name = 'thivearr';
+process hive ddl 'drop table thivearr';
 
 process hive ddl 'drop table thivealldt';
 process hive ddl 'create table thivealldt(a smallint, b int, c bigint, d decimal(3,1), e string, f char(10), g varchar(7), h date, i timestamp)';
diff --git a/core/sql/regress/seabase/TEST003 b/core/sql/regress/seabase/TEST003
index 4f170b9..a7d58a7 100644
--- a/core/sql/regress/seabase/TEST003
+++ b/core/sql/regress/seabase/TEST003
@@ -19,7 +19,7 @@
 --
 -- @@@ END COPYRIGHT @@@
 
--- Tests for tinyint, largeint unsigned datatypes
+-- Tests for tinyint, largeint unsigned, binary datatypes
 
 
 obey TEST003(clean_up);
diff --git a/core/sql/regress/seabase/TEST004 b/core/sql/regress/seabase/TEST004
new file mode 100644
index 0000000..8bff224
--- /dev/null
+++ b/core/sql/regress/seabase/TEST004
@@ -0,0 +1,181 @@
+-- @@@ START COPYRIGHT @@@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+--
+-- @@@ END COPYRIGHT @@@
+
+-- Tests for binary datatype
+
+obey TEST004(clean_up);
+
+log LOG004 clear;
+
+cqd traf_binary_support 'ON';
+cqd traf_binary_input 'ON';
+cqd traf_binary_output 'ON';
+
+obey TEST004(setup_binary);
+obey TEST004(dml_binary);
+obey TEST004(errors_binary);
+obey TEST004(hive_binary);
+
+log;
+
+?section setup_binary
+-----------------------------------------------------------
+-------------- BINARY datatype ---------------------------
+-----------------------------------------------------------
+
+drop table if exists t004t3 cascade;
+drop table if exists t004t3_like;
+drop table if exists t004t3_as;
+
+create table t004t3(a binary(5) not null primary key, b varbinary(10));
+invoke t004t3;
+
+create table if not exists t004t3_like like t004t3;
+invoke t004t3_like;
+
+create table if not exists t004t3_as primary key (a) as select * from t004t3;
+invoke t004t3_as;
+
+create table if not exists t004t3_salt(a binary(4) not null primary key)
+  salt using 2 partitions;
+invoke t004t3_salt;
+
+create view t004t3_view as select * from t004t3;
+invoke t004t3_view;
+
+?section dml_binary
+insert into t004t3 values ('ab', 123);
+insert into t004t3 values (234, 'ba');
+
+select to_hex(a), to_hex(b) from t004t3;
+select to_hex(left(a, 1)) from t004t3;
+select to_hex(b || 'a') from t004t3;
+select to_hex( a || 'a') from t004t3;
+
+insert into t004t3_as select * from t004t3;
+select to_hex(a), to_hex(b) from t004t3_as;
+
+select cast(to_binary('ab') as char(10)) from dual;
+
+select * from t004t3 where a = to_binary('ab');
+
+select to_hex(cast(10 as binary(4))) from dual;
+select to_hex(cast(-10 as binary(4))) from dual;
+select cast(10 as binary(4)) from dual;
+select cast(-10 as binary(4)) from dual;
+
+select cast(to_binary(12.34) as smallint) from dual;
+select cast(to_binary(12.34) as numeric(4,2)) from dual;
+
+select cast(cast(10 as binary(4)) as  int) from dual;
+
+select to_hex(cast(a as binary(10))), 
+       to_hex(cast (b as varbinary(11))) from t004t3;
+
+select char_length(a), char_length(b) from t004t3;
+select octet_length(a), octet_length(b) from t004t3;
+
+delete from t004t3;
+prepare s from insert into t004t3 values (?, ?);
+execute s using 1, 'abc';
+execute s using 'x', 20.34;
+select to_hex(a), to_hex(b) from t004t3;
+
+begin work;
+delete from t004t3 where a = to_binary('x');
+select to_hex(a), to_hex(b) from t004t3;
+rollback work;
+select to_hex(a), to_hex(b) from t004t3;
+
+begin work;
+update t004t3 set b = 1;
+select to_hex(a), to_hex(b) from t004t3;
+rollback work;
+select to_hex(a), to_hex(b) from t004t3;
+
+select to_binary(10000000) from dual;
+
+-- select after turning off traf_binary_output. 
+-- this is to test selects from clients which not yet support binary datatype
+cqd traf_binary_output 'OFF';
+select a,b from t004t3;
+select to_binary(10000000) from dual;
+cqd traf_binary_output 'ON';
+
+-- input after turning off traf_binary_input.
+-- this is to test inserts from clients which do not yet support binary datatype
+-- params are typed as char/varchar in this case.
+cqd traf_binary_input 'OFF';
+begin work;
+prepare s from insert into t004t3 values (?,?);
+execute s using 'abc', 'xyz';
+select * from t004t3;
+rollback work;
+cqd traf_binary_input 'ON';
+
+-- return warning and truncate 2 digits.
+select cast(to_binary(10000000) as binary(2)) from dual;
+
+?section errors_binary
+select * from t004t3 where a = 'ab';
+select b + 1 from t004t3;
+select -b from t004t3;
+select * from t004t3 where a = 1;
+select cast(100 as binary(1)) from dual;
+select cast(to_binary(1) as date) from dual;
+select cast(to_binary('ab') as char(1)) from dual;
+select cast(to_binary(12.34) as int) from dual;
+
+?section hive_binary
+-- create and populate hive binary datatype from hive
+process hive ddl 'drop table tbinary';
+process hive ddl 'create table tbinary(a binary)';
+sh echo "insert into tbinary values ('a'), (1), (NULL);" > TEST004_junk;
+sh regrhive.ksh -f TEST004_junk;
+
+cqd hive_max_binary_length '10';
+invoke hive.hive.tbinary;
+select to_hex(a) from hive.hive.tbinary;
+insert into hive.hive.tbinary values ('a'), (1), (null);
+select * from hive.hive.tbinary;
+select to_hex(a) from hive.hive.tbinary;
+insert overwrite table hive.hive.tbinary select a from t004t3;
+select to_hex(a) from hive.hive.tbinary;
+
+prepare s from insert into hive.hive.tbinary values (?);
+execute s using x'1020';
+set param ?p x'3040';
+insert into hive.hive.tbinary values (?p);
+select a from hive.hive.tbinary;
+select * from hive.hive.tbinary where a = _binary x'1020';
+
+select cast(column_name as char(30) character set iso88591), 
+       sql_data_type, fs_data_type, hive_data_type,
+       column_size, column_scale, 
+       column_number, part_col_number, bucket_col_number, sort_col_number
+  from table(hivemd(columns))
+  where table_name = 'tbinary'
+  order by column_number;
+
+?section errors_binary
+select b + 1 from t004t3;
+select -b from t004t3;
+select * from t004t3 where a = 1;
diff --git a/core/sql/sqlci/Formatter.cpp b/core/sql/sqlci/Formatter.cpp
index f15a379..8ee7229 100644
--- a/core/sql/sqlci/Formatter.cpp
+++ b/core/sql/sqlci/Formatter.cpp
@@ -231,6 +231,13 @@ Lng32 Formatter::display_length(Lng32 datatype,
       d_len = d_buflen = SQL_BOOLEAN_DISPLAY_SIZE;
       break;
 
+    // binary values are displayed in HEX format. 
+    // 1 source byte will be displayed as 2 HEX bytes.
+    case REC_BINARY_STRING:
+    case REC_VARBINARY_STRING:
+      d_len = d_buflen = str_computeHexAsciiLen(length);
+      break;
+
     default:
       d_len = d_buflen = length;
       break;
@@ -285,6 +292,7 @@ Int32 Formatter::buffer_it(SqlciEnv * sqlci_env, char *data,
       (datatype == REC_BYTE_V_ANSI) ||
       (datatype == REC_NCHAR_V_UNICODE) ||	// 12/9/97
       (datatype == REC_NCHAR_V_ANSI_UNICODE) ||	// 6/26/98
+      (datatype == REC_VARBINARY_STRING) ||
       (datatype == REC_BLOB) ||
       (datatype == REC_CLOB)
      ) 
@@ -346,6 +354,8 @@ Int32 Formatter::buffer_it(SqlciEnv * sqlci_env, char *data,
   case REC_FLOAT64: 
   case REC_DATETIME: 
   case REC_BOOLEAN:
+    //  case REC_BINARY_STRING:
+    //  case REC_VARBINARY_STRING:
   {
     short retcode = convDoIt(data,
 			     length,
@@ -479,6 +489,20 @@ Int32 Formatter::buffer_it(SqlciEnv * sqlci_env, char *data,
   }
   break;
 
+  case REC_BINARY_STRING:
+  case REC_VARBINARY_STRING:
+    {
+      Lng32 retLen = str_convertToHexAscii(
+           data, length,
+           buf, display_length, FALSE);
+      if (retLen < 0)
+        {
+          // should not happen
+          assert(0);
+        }
+    }
+  break;
+
   default:
     break;
   }
diff --git a/core/sql/sqlci/Param.cpp b/core/sql/sqlci/Param.cpp
index 62b54af..1b53277 100644
--- a/core/sql/sqlci/Param.cpp
+++ b/core/sql/sqlci/Param.cpp
@@ -349,6 +349,8 @@ short Param::convertValue(SqlciEnv * sqlci_env, short targetType,
   case REC_NCHAR_F_UNICODE:
   case REC_NCHAR_V_UNICODE:
   case REC_BLOB:
+  case REC_BINARY_STRING:
+  case REC_VARBINARY_STRING:
   case REC_CLOB:
   {
     char *VCLen = NULL;
@@ -365,15 +367,16 @@ short Param::convertValue(SqlciEnv * sqlci_env, short targetType,
     // 5/27/98: added VARCHAR cases
     if ((targetType == REC_BYTE_V_ASCII) || 
         (targetType == REC_BYTE_V_ASCII_LONG) ||
-        (targetType == REC_NCHAR_V_UNICODE))       
+        (targetType == REC_NCHAR_V_UNICODE) ||
+        (targetType == REC_VARBINARY_STRING))
       {
         // add bytes for variable length field
         VCLenSize = vcIndLen; //sizeof(short);
         VCLen = converted_value = new char[targetLen + VCLenSize];
-      } else
+      } 
+    else
       converted_value = new char[targetLen];
-
-
+    
     ex_expr::exp_return_type ok;
     CharInfo::CharSet TCS = sqlci_env->getTerminalCharset();
     CharInfo::CharSet ISOMAPCS = sqlci_env->getIsoMappingCharset();
@@ -381,12 +384,12 @@ short Param::convertValue(SqlciEnv * sqlci_env, short targetType,
     NAString* tempstr;
     if ( 
          (
-              DFS2REC::isAnyCharacter(sourceType) && DFS2REC::isAnyCharacter(targetType) &&
+              DFS2REC::isCharacterString(sourceType) && DFS2REC::isCharacterString(targetType) &&
               !(getUTF16StrLit() != NULL && sourceType == REC_NCHAR_F_UNICODE && targetScale == CharInfo::UCS2) &&
               /*source*/cs != targetScale/*i.e., targetCharSet*/
           ) && (origTargetType != REC_BLOB)
          )
-         
+      
     {
       charBuf cbuf((unsigned char*)pParamValue, sourceLen);
       NAWcharBuf* wcbuf = 0;
diff --git a/core/sql/sqlci/SqlCmd.cpp b/core/sql/sqlci/SqlCmd.cpp
index d2b5176..4b19806 100644
--- a/core/sql/sqlci/SqlCmd.cpp
+++ b/core/sql/sqlci/SqlCmd.cpp
@@ -77,6 +77,7 @@
 #include "SqlciList_templ.h"
 #include "ComCextMisc.h"
 #include "ComCextdecs.h"
+#include "conversionHex.h"
 
 #include "ComQueue.h"
 #include "ExExeUtilCli.h"
@@ -2679,6 +2680,8 @@ Lng32 Execute::storeParams(char* argument_, short &num_params,
   {
     NABoolean literal = TRUE;    // if this arg is a literal, set it to 1
                               // otherwise, set it to 0.  It's set to 1 as default.
+
+    NABoolean isHex = FALSE;
     while (isspace((unsigned char)*args)) args++;  // For VS2003
 
     if (num_params >= MAX_NUM_UNNAMED_PARAMS)
@@ -2766,7 +2769,6 @@ Lng32 Execute::storeParams(char* argument_, short &num_params,
                       }
                     }
 
-
 		    if (i >= MAX_LEN_UNNAMED_PARAM)
 		    {
 		      *args = '\0';		// terminate errarg
@@ -2787,6 +2789,57 @@ Lng32 Execute::storeParams(char* argument_, short &num_params,
 		  }
 		  break;
 
+      case 'x':
+      case 'X':
+        {
+          // if this is a hex string, convert to hex and break out.
+          // hex literal format:  x'hexval'
+          //          Int32 arglen = strlen(args);
+          //          if ((arglen > (1 + 1 + 1)) &&
+          if (args[1] && args[1] == '\'')
+            {
+              Int32 j = 2;
+              Int32 arglen = 0;
+              while (args[j] && (NOT isHex) && (j < MAX_LEN_UNNAMED_PARAM))
+                {
+                  if (args[j] == '\'')
+                    {
+                      NAWString pvalue_in_wchar(CharInfo::ISO88591, 
+                                                &args[2], arglen);
+                      void* result = NULL;
+                      enum hex_conversion_code code = 
+                        verifyAndConvertHex(pvalue_in_wchar, 
+                                            pvalue_in_wchar.length(), 
+                                            L'\'', CharInfo::ISO88591, 
+                                            &sqlci_Heap, result);
+                      if (code == INVALID)
+                        {
+                          return errorParams(-SQLCI_SYNTAX_ERROR, errarg);
+                        }
+                      
+                      NAString* conv_pvalue = (NAString*)result;
+                      
+                      str_cpy_all(param, (char*)conv_pvalue->data(), 
+                                  conv_pvalue->length());
+                      
+                      i = conv_pvalue->length();
+
+                      args += (1 + 1 + arglen + 1);
+                      isHex = TRUE;
+                    }
+                  else
+                    arglen++; 
+
+                  j++;
+                } // while
+
+              if (isHex)
+                break;
+            }
+
+          // fall through to default case.
+        }
+
       default:	  // Copy as is, including embedded squotes and blanks
 		  // (leading blanks were already removed above),
       		  // to param value buffer, until we hit a comma
@@ -2852,7 +2905,11 @@ Lng32 Execute::storeParams(char* argument_, short &num_params,
     //using_params
     if (!literal && !strcmp(param, "NULL"))
       using_params[num_params] = NULL;
-    else {
+    else if (isHex) {
+      using_params[num_params] = new char[i+1];
+      str_cpy_all(using_params[num_params], param, i);
+      using_params[num_params][i] = 0;
+    } else {
       using_params[num_params] = new char[i+1];
       strcpy(using_params[num_params], param);
     }
diff --git a/core/sql/sqlci/SqlciEnv.cpp b/core/sql/sqlci/SqlciEnv.cpp
index 53da9a3..ed05feb 100644
--- a/core/sql/sqlci/SqlciEnv.cpp
+++ b/core/sql/sqlci/SqlciEnv.cpp
@@ -487,6 +487,11 @@ void SqlciEnv::datatypeSupport()
   // can handle boolean datatype
   SqlCmd::executeQuery("CONTROL QUERY DEFAULT TRAF_BOOLEAN_IO 'ON';", this);
 
+  // can handle binary datatype
+  SqlCmd::executeQuery("CONTROL QUERY DEFAULT TRAF_BINARY_SUPPORT 'ON';", this);
+  SqlCmd::executeQuery("CONTROL QUERY DEFAULT TRAF_BINARY_INPUT 'ON';", this);
+  SqlCmd::executeQuery("CONTROL QUERY DEFAULT TRAF_BINARY_OUTPUT 'ON';", this);
+
   if (!specialError_)
     {
       exit(EXIT_FAILURE);
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 6aaa084..aae1e23 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -2908,7 +2908,7 @@ short CmpSeabaseDDL::getTypeInfo(const NAType * naType,
 
         if (serializedOption == 1) // option explicitly specified
           {
-            if (DFS2REC::isBinary(datatype))
+            if (DFS2REC::isBinaryNumeric(datatype))
               setFlags(hbaseColFlags, NAColumn::SEABASE_SERIALIZED);
             else if (numericType->isEncodingNeeded())
               {
@@ -2919,7 +2919,7 @@ short CmpSeabaseDDL::getTypeInfo(const NAType * naType,
           }
         else if ((serializedOption == -1) && // not specified
                  (CmpCommon::getDefault(HBASE_SERIALIZATION) == DF_ON) &&
-                 (DFS2REC::isBinary(datatype)) &&
+                 (DFS2REC::isBinaryNumeric(datatype)) &&
                  (NOT alignedFormat))
           {
             setFlags(hbaseColFlags, NAColumn::SEABASE_SERIALIZED);
@@ -2974,7 +2974,6 @@ short CmpSeabaseDDL::getTypeInfo(const NAType * naType,
       }
       break;
       
-
     default:
       {
         *CmpCommon::diags() << DgSqlCode(-CAT_INVALID_COLUMN_DATATYPE);
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp b/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp
index c208424..86fac48 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLutil.cpp
@@ -260,6 +260,8 @@ const literalAndEnumStruct ODBCDataTypeXlateArray [] =
   {COM_BLOB_SDT, COM_BLOB_ODT_LIT},
   {COM_CLOB_SDT, COM_CLOB_ODT_LIT},
   {COM_BOOLEAN_SDT, COM_BOOLEAN_ODT_LIT},
+  {COM_BINARY_SDT, COM_BINARY_ODT_LIT},
+  {COM_VARBINARY_SDT, COM_VARBINARY_ODT_LIT},
   {COM_DATETIME_ODT, COM_DATETIME_ODT_LIT},
   {COM_TIMESTAMP_ODT, COM_TIMESTAMP_ODT_LIT},
   {COM_DATE_ODT, COM_DATE_ODT_LIT},
@@ -295,6 +297,8 @@ const literalAndEnumStruct SQLDataTypeXlateArray [] =
   {COM_BLOB_SDT, COM_BLOB_SDT_LIT},
   {COM_CLOB_SDT, COM_CLOB_SDT_LIT},
   {COM_BOOLEAN_SDT, COM_BOOLEAN_SDT_LIT},
+  {COM_BINARY_SDT, COM_BINARY_SDT_LIT},
+  {COM_VARBINARY_SDT, COM_VARBINARY_SDT_LIT},
   {COM_DATETIME_SDT, COM_DATETIME_SDT_LIT},
   {COM_TIMESTAMP_SDT, COM_TIMESTAMP_SDT_LIT},
   {COM_DATE_SDT, COM_DATE_SDT_LIT},
diff --git a/core/sql/sqlcomp/DefaultConstants.h b/core/sql/sqlcomp/DefaultConstants.h
index 9cb6aff..d36b36c 100644
--- a/core/sql/sqlcomp/DefaultConstants.h
+++ b/core/sql/sqlcomp/DefaultConstants.h
@@ -3300,12 +3300,33 @@ enum DefaultConstants
   BMO_MEMORY_LIMIT_UPPER_BOUND,
   BMO_MEMORY_ESTIMATE_RATIO_CAP,
 
+  // if OFF, binary/varbinary is not supported. It is treated as char/varchar.
+  // if ON,  binary is supported as table cols and in cast stmts.
+  // This is needed until binary/varbinary support is fully
+  // supported and externalized.
+  TRAF_BINARY_SUPPORT,
+
+  // If ON, binary is supported as returned datatype from a select stmt,
+  // otherwise returned as char/varchar.
+  TRAF_BINARY_OUTPUT,
+
+  // If ON, input params are typed as binary,
+  // otherwise typed as char/varchar.
+  TRAF_BINARY_INPUT,
+
+  // if ON, spj input/output params are typed as binary.
+  // Otherwise typed as char/varchar.
+  TRAF_BINARY_SPJ_SUPPORT,
+
   // if set, cleanse output of explain text by filtering values that
   // may not be deterministic on different systems.
   // Same as explain format: options 'c'
   // Used during dev regressions to cleanse explain output.
   EXPLAIN_OPTION_C,
 
+  // max length of hive binary datatype
+  HIVE_MAX_BINARY_LENGTH,
+
   // Threshold when TOPN sort becomes a regular sort
   GEN_SORT_TOPN_THRESHOLD,
 
diff --git a/core/sql/sqlcomp/nadefaults.cpp b/core/sql/sqlcomp/nadefaults.cpp
index e2ae6d7..a63ff18 100644
--- a/core/sql/sqlcomp/nadefaults.cpp
+++ b/core/sql/sqlcomp/nadefaults.cpp
@@ -1647,6 +1647,7 @@ SDDkwd__(EXE_DIAGNOSTIC_EVENTS,		"OFF"),
   DDui___(HIVE_INSERT_ERROR_MODE,               "1"),
   DDint__(HIVE_LIB_HDFS_PORT_OVERRIDE,          "-1"),
   DDint__(HIVE_LOCALITY_BALANCE_LEVEL,          "0"),
+  DDui___(HIVE_MAX_BINARY_LENGTH,               "128"), 
   DDui___(HIVE_MAX_ESPS,                        "9999"),
   DDui___(HIVE_MAX_STRING_LENGTH_IN_BYTES,      "32000"),
   DDint__(HIVE_METADATA_REFRESH_INTERVAL,       "0"),
@@ -2875,6 +2876,11 @@ XDDkwd__(SUBQUERY_UNNESTING,			"ON"),
 
   DDkwd__(TRAF_AUTO_CREATE_SCHEMA,                 "OFF"),   
 
+  DDkwd__(TRAF_BINARY_INPUT,                          "OFF"),
+  DDkwd__(TRAF_BINARY_OUTPUT,                         "OFF"),
+  DDkwd__(TRAF_BINARY_SPJ_SUPPORT,                    "OFF"),
+  DDkwd__(TRAF_BINARY_SUPPORT,                        "ON"),
+
   DDkwd__(TRAF_BLOB_AS_VARCHAR,                 "OFF"), //set to OFF to enable Lobs support  
 
   DDkwd__(TRAF_BOOLEAN_IO,                        "OFF"),
diff --git a/core/sql/ustat/hs_cli.cpp b/core/sql/ustat/hs_cli.cpp
index dbefed0..0840097 100644
--- a/core/sql/ustat/hs_cli.cpp
+++ b/core/sql/ustat/hs_cli.cpp
@@ -3444,6 +3444,14 @@ Lng32 HSCursor::buildNAType()
           type = new(heap_) SQLBooleanNative(heap_, nullflag);
           break;
 
+        case REC_BINARY_STRING:
+          type = new(heap_) SQLBinaryString(heap_, length, nullflag, FALSE);
+          break;
+
+        case REC_VARBINARY_STRING:
+          type = new(heap_) SQLBinaryString(heap_, length, nullflag, TRUE);
+          break;
+
         default:
           HSFuncMergeDiags(- UERR_UNSUPPORTED_DATATYPE);
           retcode_ = -1;
diff --git a/core/sql/ustat/hs_globals.cpp b/core/sql/ustat/hs_globals.cpp
index 04220d9..d9dfdd7 100644
--- a/core/sql/ustat/hs_globals.cpp
+++ b/core/sql/ustat/hs_globals.cpp
@@ -333,6 +333,7 @@ Lng32 MCWrapper::setupMCColumnIterator (HSColGroupStruct *group, MCIterator** it
 
       case REC_BYTE_F_ASCII: 
       case REC_BYTE_F_DOUBLE:
+      case REC_BINARY_STRING:
         iter[currentLoc] = new (STMTHEAP) MCFixedCharIterator((char*)group->strData, group->ISlength);
 
         MCFcharIter = (MCFixedCharIterator*)(iter[currentLoc]);
@@ -345,6 +346,7 @@ Lng32 MCWrapper::setupMCColumnIterator (HSColGroupStruct *group, MCIterator** it
 
       case REC_BYTE_V_ASCII: 
       case REC_BYTE_V_DOUBLE:
+      case REC_VARBINARY_STRING:
         iter[currentLoc] = new (STMTHEAP) MCVarCharIterator((char*)group->strData);
 
         MCVcharIter = (MCVarCharIterator*)iter[currentLoc];
@@ -5258,6 +5260,7 @@ void HSGlobalsClass::getMemoryRequirementsForOneGroup(HSColGroupStruct* group, I
 
           case REC_BYTE_F_ASCII:
           case REC_BYTE_F_DOUBLE:
+          case REC_BINARY_STRING:
             // Length is in bytes, not chars. Add size for object that references
             // the string, which is stored in a separate array.
             elementSize = group->ISlength + sizeof(ISFixedChar);
@@ -5265,6 +5268,7 @@ void HSGlobalsClass::getMemoryRequirementsForOneGroup(HSColGroupStruct* group, I
 
           case REC_BYTE_V_ASCII:
           case REC_BYTE_V_DOUBLE:
+          case REC_VARBINARY_STRING:
             elementSize = group->varcharContentSize() + sizeof(ISVarChar);
             break;
 
@@ -7734,6 +7738,7 @@ Int32 HSGlobalsClass::processIUSColumn(HSColGroupStruct* smplGroup,
         break;
       case REC_BYTE_F_ASCII:
       case REC_BYTE_F_DOUBLE:
+      case REC_BINARY_STRING:
         {
           // Create an object to be used with the value iterator; does not own its content.
           // In setting length, take into account that length in IUSFixedChar is in
@@ -7751,6 +7756,7 @@ Int32 HSGlobalsClass::processIUSColumn(HSColGroupStruct* smplGroup,
         break;
       case REC_BYTE_V_ASCII:
       case REC_BYTE_V_DOUBLE:
+      case REC_VARBINARY_STRING:
         {
           // Create an object to be used with the value iterator; does not own its content.
           // In setting length, take into account that length in IUSFixedChar is in
@@ -10659,8 +10665,10 @@ void processNullsForColumn(HSColGroupStruct *group, Lng32 rowsRead, T* dummyPtr)
   // copy data for MC
   if ( HSGlobalsClass::performISForMC() && (group->mcs_usingme > 0) &&
       (group->ISdatatype != REC_BYTE_F_ASCII) && 
+      (group->ISdatatype != REC_BINARY_STRING) && 
       (group->ISdatatype != REC_BYTE_F_DOUBLE) &&
       (group->ISdatatype != REC_BYTE_V_ASCII) && 
+      (group->ISdatatype != REC_VARBINARY_STRING) && 
       (group->ISdatatype != REC_BYTE_V_DOUBLE)   
      )
 
@@ -10814,6 +10822,7 @@ Lng32 HSGlobalsClass::processInternalSortNulls(Lng32 rowsRead, HSColGroupStruct
 
           case REC_BYTE_F_ASCII:
           case REC_BYTE_F_DOUBLE:
+          case REC_BINARY_STRING:
             // Set up elements of data array, which are pointers to char values.
             chPtr = (ISFixedChar*)group->nextData;
             dataPtr = (char*)group->strNextData;
@@ -10830,6 +10839,7 @@ Lng32 HSGlobalsClass::processInternalSortNulls(Lng32 rowsRead, HSColGroupStruct
 
           case REC_BYTE_V_ASCII:
           case REC_BYTE_V_DOUBLE:
+          case REC_VARBINARY_STRING:
             {
               // Set up elements of data array, which are pointers to varchar
               // values (2-byte length field followed by string). The length
@@ -10997,6 +11007,8 @@ bool isInternalSortType(HSColumnStruct &col)
       case REC_IEEE_FLOAT64:
       case REC_BYTE_F_ASCII:
       case REC_BYTE_V_ASCII:
+      case REC_BINARY_STRING:
+      case REC_VARBINARY_STRING:
         return true;
 
       case REC_BYTE_F_DOUBLE:
@@ -11087,8 +11099,8 @@ NABoolean isInternalSortEfficient(Int64 rows, HSColGroupStruct *group)
        // then compute this column using IS regardless of UEC
        returnVal = TRUE;
     }
-  else if ((dataType >= REC_MIN_BINARY &&
-       dataType <= REC_MAX_BINARY)||
+  else if ((dataType >= REC_MIN_BINARY_NUMERIC &&
+       dataType <= REC_MAX_BINARY_NUMERIC)||
        dataType == REC_DECIMAL_LSE ||
        dataType == REC_DECIMAL_UNSIGNED ||
        dataType == REC_DECIMAL_LS)
@@ -11931,6 +11943,7 @@ Lng32 doSort(HSColGroupStruct *group)
 
       case REC_BYTE_F_ASCII:
       case REC_BYTE_F_DOUBLE:
+      case REC_BINARY_STRING:
       {
         //
         // Set the GLOBAL ISFixedChar instance with this column's values
@@ -11961,6 +11974,7 @@ Lng32 doSort(HSColGroupStruct *group)
       }
       case REC_BYTE_V_ASCII:
       case REC_BYTE_V_DOUBLE:
+      case REC_VARBINARY_STRING:
       {
         //
         // Set the GLOBAL ISVarChar instance with this column's values
@@ -12431,6 +12445,7 @@ Lng32 HSGlobalsClass::createStatsForColumn(HSColGroupStruct *group, Int64 rowsAl
 
       case REC_BYTE_F_ASCII:
       case REC_BYTE_F_DOUBLE:
+      case REC_BINARY_STRING:
         //
         // Set the GLOBAL ISFixedChar instance with this column's values
         //
@@ -12444,6 +12459,7 @@ Lng32 HSGlobalsClass::createStatsForColumn(HSColGroupStruct *group, Int64 rowsAl
 
       case REC_BYTE_V_ASCII:
       case REC_BYTE_V_DOUBLE:
+      case REC_VARBINARY_STRING:
         //
         // Set the GLOBAL ISVarChar instance with this column's values
         //
@@ -12794,7 +12810,7 @@ T HSGlobalsClass::convertToISdatatype(T* dummy,  // just so compiler can instant
         }
     }
   else if (col.datatype >= REC_MIN_DECIMAL && col.datatype <= REC_MAX_DECIMAL ||
-           col.datatype >= REC_MIN_BINARY && col.datatype <= REC_MAX_BINARY)    //scale > 0, per caller
+           col.datatype >= REC_MIN_BINARY_NUMERIC && col.datatype <= REC_MAX_BINARY_NUMERIC)    //scale > 0, per caller
     {
       // The fractional part has been normalized to use the full number of scale
       // digits (e.g., 123.1 is represented as "123.100" for a Numeric(6,3)).
@@ -13859,6 +13875,7 @@ Lng32 HSGlobalsClass::mergeDatasetsForIUS(
         break;
       case REC_BYTE_F_ASCII:
       case REC_BYTE_F_DOUBLE:
+      case REC_BINARY_STRING:
         {
           // Create an object to be used with the value iterator; does not own its content.
           IUSFixedChar fixedChar(FALSE);
@@ -13872,6 +13889,7 @@ Lng32 HSGlobalsClass::mergeDatasetsForIUS(
         break;
       case REC_BYTE_V_ASCII:
       case REC_BYTE_V_DOUBLE:
+      case REC_VARBINARY_STRING:
         {
           // Create an object to be used with the value iterator; does not own its content.
           IUSVarChar varChar(FALSE);
@@ -14177,6 +14195,7 @@ Int32 copyValue(ISFixedChar &value, char *valueBuff, const HSColumnStruct &colDe
   switch (colDesc.datatype)
     {
         case REC_BYTE_F_ASCII:
+        case REC_BINARY_STRING:
           *len = (short)MINOF(colDesc.length, maxCharBoundaryLen);
           memmove(valueBuff,
                  ((ISFixedChar*)((void*)&value))->getContent(), // make it work with template
@@ -14230,6 +14249,7 @@ Int32 copyValue(ISVarChar &value, char *valueBuff, const HSColumnStruct &colDesc
   switch (colDesc.datatype)
     {
         case REC_BYTE_V_ASCII:
+        case REC_VARBINARY_STRING:
           ptr = ((ISVarChar*)((void*)&value))->getContent(); // make it work with template
           *len = (short)MINOF(*(short*)ptr, maxCharBoundaryLen);
           memmove(valueBuff, ptr+sizeof(short), *len);
@@ -14272,8 +14292,8 @@ Int32 copyValue(Int64 value, char *valueBuff, const HSColumnStruct &colDesc, sho
     char *ptr = NULL;
     Int32 retcode = 0;  // status is good unless no case for type
 
-    if ((colDesc.datatype >= REC_MIN_BINARY &&
-        colDesc.datatype <= REC_MAX_BINARY)||
+    if ((colDesc.datatype >= REC_MIN_BINARY_NUMERIC &&
+        colDesc.datatype <= REC_MAX_BINARY_NUMERIC)||
         colDesc.datatype == REC_DECIMAL_LSE ||
         colDesc.datatype == REC_DECIMAL_UNSIGNED ||
         colDesc.datatype == REC_DECIMAL_LS)
@@ -14821,11 +14841,13 @@ Lng32 setBufferValue(MCWrapper& value,
                break;
              case REC_BYTE_F_ASCII:
              case REC_BYTE_F_DOUBLE:
+             case REC_BINARY_STRING:
                 ((MCFixedCharIterator*)(value.allCols_[i]))->copyToISFixChar(isf, value.index_);
                 retcode = copyValue(isf, valueBuff, mgroup->colSet[i], len);
                break;
              case REC_BYTE_V_ASCII:
              case REC_BYTE_V_DOUBLE:
+             case REC_VARBINARY_STRING:
                 ((MCVarCharIterator*)(value.allCols_[i]))->copyToISVarChar(isv, value.index_);
                 retcode = copyValue(isv, valueBuff, mgroup->colSet[i], len);
                break;
@@ -16705,6 +16727,7 @@ Lng32 HSGlobalsClass::processFastStatsBatch(CollIndex numCols, HSColGroupStruct*
 
         case REC_BYTE_F_ASCII:
         case REC_BYTE_F_DOUBLE:
+        case REC_BINARY_STRING:
           //group->fastStatsHist = new(STMTHEAP) FastStatsHist<ISFixedChar*>(group, cbf);
           LM->Log("char types not yet supported for fast-stats");
           retcode=-1;
@@ -16713,6 +16736,7 @@ Lng32 HSGlobalsClass::processFastStatsBatch(CollIndex numCols, HSColGroupStruct*
 
         case REC_BYTE_V_ASCII:
         case REC_BYTE_V_DOUBLE:
+        case REC_VARBINARY_STRING:
           //group->fastStatsHist = new(STMTHEAP) FastStatsHist<ISVarChar*>(group, cbf);
           LM->Log("char types not yet supported for fast-stats");
           retcode=-1;
diff --git a/core/sql/ustat/hs_globals.h b/core/sql/ustat/hs_globals.h
index 2f8f4f9..5c73735 100644
--- a/core/sql/ustat/hs_globals.h
+++ b/core/sql/ustat/hs_globals.h
@@ -1944,7 +1944,7 @@ private:
       // from its original type, or is a fixed numeric with nonzero scale.
       Int32 actualDatatype = group->colSet[0].datatype;
       if (group->ISdatatype != actualDatatype ||
-          (actualDatatype >= REC_MIN_BINARY && actualDatatype <= REC_MAX_BINARY
+          (actualDatatype >= REC_MIN_BINARY_NUMERIC && actualDatatype <= REC_MAX_BINARY_NUMERIC
                                             && group->colSet[0].scale > 0))
         convertedValues[index] = convertToISdatatype((T*)NULL, valToConvert, group);
       else
diff --git a/core/sql/ustat/hs_la.cpp b/core/sql/ustat/hs_la.cpp
index 8c812c8..d188853 100644
--- a/core/sql/ustat/hs_la.cpp
+++ b/core/sql/ustat/hs_la.cpp
@@ -344,8 +344,8 @@ Lng32 HSSqTableDef::DescribeColumnNames()
                                             (Lng32*)&colInfo_[i].colCollation, 0, 0, 0, 0);
             HSHandleError(retcode_);
           }
-        else if ((colInfo_[i].datatype >= REC_MIN_BINARY &&  // May be type NUMERIC
-                  colInfo_[i].datatype <= REC_MAX_BINARY)    //    instead of INT
+        else if ((colInfo_[i].datatype >= REC_MIN_BINARY_NUMERIC &&  // May be type NUMERIC
+                  colInfo_[i].datatype <= REC_MAX_BINARY_NUMERIC)    //    instead of INT
                      ||
                  (colInfo_[i].datatype >= REC_MIN_DECIMAL &&
                  colInfo_[i].datatype <= REC_MAX_DECIMAL))


[trafodion] 02/03: turn off binary support by default except from sqlci/trafci

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ansharma pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafodion.git

commit e8d2c3c3fa3d2cec8c95bc970ef57439d0dcf9ea
Author: Anoop Sharma <an...@esgyn.com>
AuthorDate: Fri Feb 22 01:32:50 2019 +0000

    turn off binary support by default except from sqlci/trafci
    
    When all clients have been updated to handle binary datatypes,
    then default will be turned on.
    Queries coming from sqlci and trafci will be ok as this feature
    is automatically turned on during sqlci/trafci initialization.
---
 core/conn/trafci/src/main/java/org/trafodion/ci/Session.java | 11 +++++++++++
 core/sql/sqlcomp/nadefaults.cpp                              |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java b/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java
index 194f2fb..d2c7d4b 100644
--- a/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java
@@ -1568,11 +1568,22 @@ static {
         try
             {
                 Statement stmt = this.connObj.createStatement();
+                stmt.executeUpdate("CQD TRAF_BINARY_SUPPORT 'ON'");
+            } catch (Exception se)
+            {
+                System.out.println("error:"+se.getMessage());
+            }
+
+        try
+            {
+                Statement stmt = this.connObj.createStatement();
                 stmt.executeUpdate("CQD TRAF_BINARY_OUTPUT 'ON'");
             } catch (Exception se)
             {
                 System.out.println("error:"+se.getMessage());
             }
+
+
     }
 
    protected String getUserRoleName()
diff --git a/core/sql/sqlcomp/nadefaults.cpp b/core/sql/sqlcomp/nadefaults.cpp
index a63ff18..a429eeb 100644
--- a/core/sql/sqlcomp/nadefaults.cpp
+++ b/core/sql/sqlcomp/nadefaults.cpp
@@ -2879,7 +2879,7 @@ XDDkwd__(SUBQUERY_UNNESTING,			"ON"),
   DDkwd__(TRAF_BINARY_INPUT,                          "OFF"),
   DDkwd__(TRAF_BINARY_OUTPUT,                         "OFF"),
   DDkwd__(TRAF_BINARY_SPJ_SUPPORT,                    "OFF"),
-  DDkwd__(TRAF_BINARY_SUPPORT,                        "ON"),
+  DDkwd__(TRAF_BINARY_SUPPORT,                        "OFF"),
 
   DDkwd__(TRAF_BLOB_AS_VARCHAR,                 "OFF"), //set to OFF to enable Lobs support