You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by su...@apache.org on 2017/02/23 17:20:06 UTC
[1/4] incubator-trafodion git commit: TRAFODION-2492 Support for
native hive views, plus few more changes
Repository: incubator-trafodion
Updated Branches:
refs/heads/master b44e5d0d5 -> 549850a58
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/optimizer/NATable.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.h b/core/sql/optimizer/NATable.h
index d4e0c12..214f97c 100644
--- a/core/sql/optimizer/NATable.h
+++ b/core/sql/optimizer/NATable.h
@@ -572,6 +572,8 @@ public:
const char *getViewCheck() const { return viewCheck_; }
const NAList<ComViewColUsage*> *getViewColUsages() const { return viewColUsages_; }
+ const char *getHiveOriginalViewText() const { return hiveOrigViewText_; }
+
NABoolean hasSaltedColumn(Lng32 * saltColPos = NULL);
NABoolean hasDivisioningColumn(Lng32 * divColPos = NULL);
@@ -726,6 +728,12 @@ public:
NABoolean isExternalTable() const
{ return (flags_ & IS_EXTERNAL_TABLE) != 0; }
+ void setIsImplicitExternalTable( NABoolean value )
+ { value ? flags_ |= IS_IMPLICIT_EXTERNAL_TABLE : flags_ &= ~IS_IMPLICIT_EXTERNAL_TABLE; }
+
+ NABoolean isImplicitExternalTable() const
+ { return (flags_ & IS_IMPLICIT_EXTERNAL_TABLE) != 0; }
+
void setHasExternalTable( NABoolean value )
{ value ? flags_ |= HAS_EXTERNAL_TABLE : flags_ &= ~HAS_EXTERNAL_TABLE; }
@@ -987,7 +995,8 @@ private:
HBASE_DATA_FORMAT_STRING = 0x00800000,
HAS_HIVE_EXT_TABLE = 0x01000000,
HIVE_EXT_COL_ATTRS = 0x02000000,
- HIVE_EXT_KEY_ATTRS = 0x04000000
+ HIVE_EXT_KEY_ATTRS = 0x04000000,
+ IS_IMPLICIT_EXTERNAL_TABLE= 0x08000000
};
UInt32 flags_;
@@ -1109,6 +1118,9 @@ private:
char *viewCheck_;
NAList<ComViewColUsage *> *viewColUsages_;
+ // original hive select text used when view was created.
+ char *hiveOrigViewText_;
+
// ---------------------------------------------------------------------
// Flags
// ---------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/optimizer/hiveHook.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/hiveHook.h b/core/sql/optimizer/hiveHook.h
index bf79f98..e8fa528 100644
--- a/core/sql/optimizer/hiveHook.h
+++ b/core/sql/optimizer/hiveHook.h
@@ -187,6 +187,14 @@ struct hive_tbl_desc
char* owner_;
char* tableType_;
Int64 creationTS_;
+
+ // next 2 fields are used if hive object is a view.
+ // Contents are populated during HiveMetaData::getTableDesc.
+ // original text is what was used at view creation time.
+ // expanded text contains fully qualified object/col names.
+ char * viewOriginalText_;
+ char * viewExpandedText_;
+
struct hive_sd_desc* sd_;
struct hive_pkey_desc* pkey_;
@@ -195,11 +203,22 @@ struct hive_tbl_desc
hive_tbl_desc(Int32 tblID, const char* name, const char* schName,
const char * owner,
const char * tableType,
- Int64 creationTS, struct hive_sd_desc* sd,
+ Int64 creationTS,
+ const char * viewOriginalText,
+ const char * viewExpandedText,
+ struct hive_sd_desc* sd,
struct hive_pkey_desc* pk);
~hive_tbl_desc();
+ NABoolean isView()
+ {
+ if (tableType_ && (strcmp(tableType_, "VIRTUAL_VIEW") == 0))
+ return TRUE;
+ else
+ return FALSE;
+ }
+
struct hive_sd_desc* getSDs() { return sd_; };
struct hive_skey_desc* getSortKeys();
@@ -245,7 +264,8 @@ public:
struct hive_tbl_desc * getNext();
void advance();
NABoolean atEnd();
-
+ void clear();
+
// what the Hive default schema is called in the Hive metadata
static const char *getDefaultSchemaName() { return "default"; }
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/parser/SqlParserAux.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/SqlParserAux.cpp b/core/sql/parser/SqlParserAux.cpp
index 1be2f05..6f533c9 100644
--- a/core/sql/parser/SqlParserAux.cpp
+++ b/core/sql/parser/SqlParserAux.cpp
@@ -3322,6 +3322,11 @@ TableTokens::setTableTokens(StmtDDLCreateTable *pNode)
pNode->setIsExternal(TRUE);
break;
+ case TableTokens::TYPE_IMPLICIT_EXTERNAL_TABLE:
+ pNode->setIsExternal(TRUE);
+ pNode->setIsImplicitExternal(TRUE);
+ break;
+
case TableTokens::TYPE_SET_TABLE:
pNode->setInsertMode(COM_SET_TABLE_INSERT_MODE);
break;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/parser/SqlParserAux.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/SqlParserAux.h b/core/sql/parser/SqlParserAux.h
index 5c52bea..7c27ca8 100644
--- a/core/sql/parser/SqlParserAux.h
+++ b/core/sql/parser/SqlParserAux.h
@@ -760,6 +760,7 @@ public:
enum TableType
{ TYPE_REGULAR_TABLE = 0,
TYPE_EXTERNAL_TABLE,
+ TYPE_IMPLICIT_EXTERNAL_TABLE,
TYPE_SET_TABLE,
TYPE_MULTISET_TABLE,
TYPE_VOLATILE_TABLE,
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/parser/StmtDDLNode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLNode.cpp b/core/sql/parser/StmtDDLNode.cpp
index eab9ea2..fe13797 100644
--- a/core/sql/parser/StmtDDLNode.cpp
+++ b/core/sql/parser/StmtDDLNode.cpp
@@ -69,6 +69,7 @@ StmtDDLNode::StmtDDLNode(OperatorTypeEnum otype)
isGhostObject_(FALSE),
inMemoryObjectDefn_(FALSE),
isExternal_(FALSE),
+ isImplicitExternal_(FALSE),
ddlXns_(FALSE)
{
ddlXns_ = (CmpCommon::getDefault(DDL_TRANSACTIONS) == DF_ON);
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/parser/StmtDDLNode.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLNode.h b/core/sql/parser/StmtDDLNode.h
index 8a1d479..4e51c60 100644
--- a/core/sql/parser/StmtDDLNode.h
+++ b/core/sql/parser/StmtDDLNode.h
@@ -106,6 +106,9 @@ public:
NABoolean isExternal() { return isExternal_; }
NABoolean isExternal() const { return isExternal_; }
void setIsExternal(NABoolean e) { isExternal_ = e; }
+ NABoolean isImplicitExternal() { return isImplicitExternal_; }
+ NABoolean isImplicitExternal() const { return isImplicitExternal_; }
+ void setIsImplicitExternal(NABoolean e) { isImplicitExternal_ = e; }
// Ghost Object
NABoolean isGhostObject() { return isGhostObject_; }
@@ -148,6 +151,13 @@ private:
// if this DDL operation was specified using EXTERNAL syntax.
NABoolean isExternal_;
+ // if this DDL was specified using 'IMPLICIT EXTERNAL' syntax
+ // through the use of 'create implicit external'... stmt.
+ // Used when external table on hive tables is created for internal usage
+ // (for ex: for privs, ustat, views)
+ // Valid only if isExternal_ is set.
+ NABoolean isImplicitExternal_;
+
// if TRUE, this ddl operation will run using DTM transactions
NABoolean ddlXns_;
}; // class StmtDDLNode
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 3a2b3aa..fd1e942 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -6116,6 +6116,7 @@ hivemd_identifier :
| TOK_TABLES { $$ = new (PARSERHEAP()) NAString("TABLES"); }
| TOK_VIEWS { $$ = new (PARSERHEAP()) NAString("VIEWS"); }
| TOK_SYSTEM TOK_TABLES { $$ = new (PARSERHEAP()) NAString("SYSTEM_TABLES"); }
+ | TOK_SCHEMAS { $$ = new (PARSERHEAP()) NAString("SCHEMAS"); }
/* type boolean */
sp_proxy_stmt_prefix : TOK_TABLE '(' TOK_SP_RESULT_SET
@@ -25317,6 +25318,19 @@ create_table_start_tokens :
$$ = tableTokens;
}
+ | TOK_CREATE TOK_IMPLICIT TOK_EXTERNAL TOK_TABLE optional_if_not_exists_clause
+ {
+ if (! Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL))
+ {
+ yyerror(""); YYERROR; /*internal syntax only!*/
+ }
+
+ ParNameCTLocListPtr = new (PARSERHEAP())
+ ParNameLocList(SQLTEXT(), (CharInfo::CharSet)SQLTEXTCHARSET(), SQLTEXTW(), PARSERHEAP());
+ TableTokens *tableTokens = new TableTokens(TableTokens::TYPE_IMPLICIT_EXTERNAL_TABLE, $5);
+ $$ = tableTokens;
+ }
+
| TOK_CREATE TOK_SET TOK_TABLE optional_if_not_exists_clause
{
ParNameCTLocListPtr = new (PARSERHEAP())
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/regress/hive/EXPECTED007
----------------------------------------------------------------------
diff --git a/core/sql/regress/hive/EXPECTED007 b/core/sql/regress/hive/EXPECTED007
index 14ba827..19ea623 100644
--- a/core/sql/regress/hive/EXPECTED007
+++ b/core/sql/regress/hive/EXPECTED007
@@ -1,4 +1,4 @@
->>obey TEST007(setup);
+>>obey TEST007(setup_traf);
>>set schema hive.hive;
--- SQL operation complete.
@@ -9,7 +9,7 @@
--- SQL operation complete.
>>
->>obey TEST007(tests);
+>>obey TEST007(tests_traf);
>>-- tests for views on hive tables
>>sh echo "drop table thive1;" > TEST007_junk;
>>sh regrhive.ksh -f TEST007_junk;
@@ -45,7 +45,7 @@ CREATE TABLE THIVE1
/* Trafodion DDL */
-CREATE EXTERNAL TABLE THIVE1
+CREATE /*IMPLICIT*/ EXTERNAL TABLE THIVE1
FOR HIVE.HIVE.THIVE1
;
@@ -79,7 +79,7 @@ CREATE EXTERNAL TABLE THIVE1
>>invoke trafodion.sch007.vhivehbase;
-- Definition of Trafodion view TRAFODION.SCH007.VHIVEHBASE
--- Definition current Fri Jan 20 16:31:37 2017
+-- Definition current Wed Feb 22 04:31:49 2017
(
AA INT DEFAULT NULL
@@ -266,7 +266,7 @@ CREATE TABLE THIVE2
--- SQL operation complete.
>>
->>obey TEST007(error_tests);
+>>obey TEST007(error_tests_traf);
>>
>>create view trafodion.sch007.vhive4 as select x.a, y.b from thive1 x, thive1 y;
@@ -327,12 +327,14 @@ A B
>>sh regrhive.ksh -f TEST007_junk;
>>execute s;
-*** ERROR[8442] Unable to access HDFS interface. Call to ExpLOBInterfaceDataModCheck returned error LOB_DATA_FILE_NOT_FOUND_ERROR(554). Error detail 0.
+*** ERROR[4262] Object HIVE.HIVE.THIVE1 has invalid state and cannot be accessed. It has an external table but the correponding hive table does not exist. Use 'drop external table' command to drop the external table.
+
+*** ERROR[8822] The statement was not prepared.
--- 0 row(s) selected.
>>select * from trafodion.sch007.vhive1;
-*** ERROR[1388] Object HIVE.HIVE.THIVE1 does not exist in hive metadata.
+*** ERROR[4262] Object HIVE.HIVE.THIVE1 has invalid state and cannot be accessed. It has an external table but the correponding hive table does not exist. Use 'drop external table' command to drop the external table.
*** ERROR[8822] The statement was not prepared.
@@ -370,4 +372,322 @@ CREATE TABLE THIVE3
--- SQL operation complete.
>>
+>>
+>>obey TEST007(setup_hive);
+>>sh echo "create database hivesch007;" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>sh echo "create table hivesch007.thive1 (a int);" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>sh echo "insert into hivesch007.thive1 values (1);" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>sh echo "create view hivesch007.vhive1 as select * from hivesch007.thive1 where thive1.a > 0;" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>sh echo "create view hivesch007.vhive11 as select * from hivesch007.vhive1 where vhive1.a > 0;" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>sh echo "create table thive007 (a int);" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>sh echo "create view vhive007 as select * from thive007 where a > 0;" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>insert into hive.hive.thive007 values (1);
+
+--- 1 row(s) inserted.
+>>
+>>obey TEST007(tests_hive);
+>>invoke hive.hivesch007.vhive1;
+
+-- Definition of native Hive view VHIVE1
+-- Definition current Wed Feb 22 04:35:19 2017
+
+ (
+ A INT
+ )
+
+--- SQL operation complete.
+>>showddl hive.hivesch007.vhive1;
+
+Original native Hive view text:
+select * from hivesch007.thive1 where thive1.a > 0
+
+Expanded native Hive view text:
+CREATE VIEW vhive1 AS
+ select thive1.a from hivesch007.thive1 where thive1.a > 0 ;
+
+--- SQL operation complete.
+>>
+>>prepare s from select * from hive.hivesch007.vhive1;
+
+--- SQL command prepared.
+>>explain options 'f' s;
+
+LC RC OP OPERATOR OPT DESCRIPTION CARD
+---- ---- ---- -------------------- -------- -------------------- ---------
+
+1 . 2 root 3.29E+001
+. . 1 hive_scan THIVE1 3.29E+001
+
+--- SQL operation complete.
+>>execute s;
+
+A
+-----------
+
+ 1
+
+--- 1 row(s) selected.
+>>
+>>invoke hive.hivesch007.vhive11;
+
+-- Definition of native Hive view VHIVE11
+-- Definition current Wed Feb 22 04:35:22 2017
+
+ (
+ A INT
+ )
+
+--- SQL operation complete.
+>>showddl hive.hivesch007.vhive11;
+
+Original native Hive view text:
+select * from hivesch007.vhive1 where vhive1.a > 0
+
+Expanded native Hive view text:
+CREATE VIEW vhive11 AS
+ select vhive1.a from hivesch007.vhive1 where vhive1.a > 0 ;
+
+--- SQL operation complete.
+>>
+>>prepare s from select * from hive.hivesch007.vhive11;
+
+--- SQL command prepared.
+>>explain options 'f' s;
+
+LC RC OP OPERATOR OPT DESCRIPTION CARD
+---- ---- ---- -------------------- -------- -------------------- ---------
+
+1 . 2 root 3.29E+001
+. . 1 hive_scan THIVE1 3.29E+001
+
+--- SQL operation complete.
+>>execute s;
+
+A
+-----------
+
+ 1
+
+--- 1 row(s) selected.
+>>
+>>prepare s from select * from hive.hive.vhive007;
+
+--- SQL command prepared.
+>>explain options 'f' s;
+
+LC RC OP OPERATOR OPT DESCRIPTION CARD
+---- ---- ---- -------------------- -------- -------------------- ---------
+
+1 . 2 root 3.29E+001
+. . 1 hive_scan THIVE007 3.29E+001
+
+--- SQL operation complete.
+>>execute s;
+
+A
+-----------
+
+ 1
+
+--- 1 row(s) selected.
+>>
+>>get tables in schema hive.hivesch007;
+
+Tables in Schema HIVE.HIVESCH007
+================================
+
+thive1
+
+--- SQL operation complete.
+>>get views in schema hive.hivesch007;
+
+Views in Schema HIVE.HIVESCH007
+===============================
+
+vhive1
+vhive11
+
+--- SQL operation complete.
+>>
+>>get tables in schema hive.hive, match '%007%';
+
+Tables in Schema HIVE.HIVE
+==========================
+
+thive007
+
+--- SQL operation complete.
+>>get views in schema hive.hive, match '%007%';
+
+Views in Schema HIVE.HIVE
+=========================
+
+vhive007
+
+--- SQL operation complete.
+>>
+>>get tables in catalog hive, match 'hivesch007%';
+
+Tables in Catalog HIVE
+======================
+
+hivesch007.thive1
+
+--- SQL operation complete.
+>>get views in catalog hive, match 'hivesch007%';
+
+Views in Catalog HIVE
+=====================
+
+hivesch007.vhive1
+hivesch007.vhive11
+
+--- SQL operation complete.
+>>
+>>set schema hive.hive;
+
+--- SQL operation complete.
+>>prepare s from select * from vhive007 x, hive.hivesch007.vhive1 y
++> where x.a = y.a;
+
+--- SQL command prepared.
+>>explain options 'f' s;
+
+LC RC OP OPERATOR OPT DESCRIPTION CARD
+---- ---- ---- -------------------- -------- -------------------- ---------
+
+3 . 4 root 1.08E+003
+2 1 3 hybrid_hash_join u 1.08E+003
+. . 2 hive_scan THIVE007 3.29E+001
+. . 1 hive_scan THIVE1 3.29E+001
+
+--- SQL operation complete.
+>>execute s;
+
+A A
+----------- -----------
+
+ 1 1
+
+--- 1 row(s) selected.
+>>
+>>-- create traf view on native hive view
+>>create schema if not exists trafodion.sch007;
+
+--- SQL operation complete.
+>>create view trafodion.sch007.vtrafonhive as select * from hive.hivesch007.vhive11;
+
+--- SQL operation complete.
+>>showddl trafodion.sch007.vtrafonhive;
+
+CREATE VIEW TRAFODION.SCH007.VTRAFONHIVE AS
+ SELECT HIVE.HIVESCH007.VHIVE11.A FROM HIVE.HIVESCH007.VHIVE11 ;
+
+--- SQL operation complete.
+>>prepare s from select * from trafodion.sch007.vtrafonhive;
+
+--- SQL command prepared.
+>>explain options 'f' s;
+
+LC RC OP OPERATOR OPT DESCRIPTION CARD
+---- ---- ---- -------------------- -------- -------------------- ---------
+
+1 . 2 root 3.29E+001
+. . 1 hive_scan THIVE1 3.29E+001
+
+--- SQL operation complete.
+>>execute s;
+
+A
+-----------
+
+ 1
+
+--- 1 row(s) selected.
+>>get tables in view trafodion.sch007.vtrafonhive;
+
+--- SQL operation complete.
+>>
+>>obey TEST007(error_tests_hive);
+>>get tables in view hive.hivesch007.vhive11;
+
+*** ERROR[4219] This command is not supported on the specified object or an incorrect object type was specified.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>get views on table hive.hivesch007.thive1;
+
+--- SQL operation complete.
+>>
+>>insert into hive.hivesch007.vhive1 values (1);
+
+*** ERROR[4027] Table or view HIVE.HIVESCH007.VHIVE1 does not permit insertions.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>delete from hive.hivesch007.vhive1;
+
+*** ERROR[4028] Table or view HIVE.HIVESCH007.VHIVE1 is not updatable.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>
+>>-- drop underlying hive table
+>>cqd auto_query_retry_warnings 'ON';
+
+--- SQL operation complete.
+>>
+>>sh echo "drop table hivesch007.thive1;" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>prepare s from select * from hive.hivesch007.vhive11;
+
+*** ERROR[1388] Object HIVE.HIVESCH007.THIVE1 does not exist in hive metadata.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>execute s;
+
+*** ERROR[15017] Statement S was not found.
+
+>>
+>>sh echo "create table hivesch007.thive1 (a int);" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>prepare s from select * from hive.hivesch007.vhive11;
+
+--- SQL command prepared.
+>>execute s;
+
+--- 0 row(s) selected.
+>>
+>>sh echo "drop table hivesch007.thive1;" > TEST007_junk;
+>>sh regrhive.ksh -f TEST007_junk;
+>>
+>>execute s;
+
+*** ERROR[1388] Object HIVE.HIVESCH007.THIVE1 does not exist in hive metadata.
+
+*** ERROR[8822] The statement was not prepared.
+
+*** WARNING[8597] Statement was automatically retried 1 time(s). Delay before each retry was 0 seconds. See next entry for the error that caused this retry.
+
+*** WARNING[8577] Table, index, or view HIVE.HIVESCH007.THIVE1 was not found.
+
+--- 0 row(s) selected.
+>>
>>log;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/regress/hive/TEST007
----------------------------------------------------------------------
diff --git a/core/sql/regress/hive/TEST007 b/core/sql/regress/hive/TEST007
index 1e1a555..d1e8fd8 100644
--- a/core/sql/regress/hive/TEST007
+++ b/core/sql/regress/hive/TEST007
@@ -1,4 +1,4 @@
--- Tests for views on hive tables
+-- Tests for trafodion views on hive tables and native hive views
--
-- @@@ START COPYRIGHT @@@
--
@@ -21,22 +21,25 @@
--
-- @@@ END COPYRIGHT @@@
-obey TEST007(clean_up);
+obey TEST007(clean_up_traf);
+obey TEST007(clean_up_hive);
log LOG007 clear;
-obey TEST007(setup);
-obey TEST007(tests);
-obey TEST007(error_tests);
+obey TEST007(setup_traf);
+obey TEST007(tests_traf);
+obey TEST007(error_tests_traf);
+
+obey TEST007(setup_hive);
+obey TEST007(tests_hive);
+obey TEST007(error_tests_hive);
+
log;
-obey TEST007(clean_up);
-exit;
+obey TEST007(clean_up_traf);
+obey TEST007(clean_up_hive);
-?section setup
-set schema hive.hive;
-cqd HIVE_MAX_STRING_LENGTH '20' ;
-create schema if not exists trafodion.sch007;
+exit;
-?section clean_up
+?section clean_up_traf
drop view trafodion.sch007.vhive1 cascade;
drop view trafodion.sch007.vhive11 cascade;
drop view trafodion.sch007.vhive2 cascade;
@@ -55,9 +58,13 @@ drop external table thive3 for hive.hive.thive3;
sh echo "drop table thive3;" > TEST007_junk;
sh regrhive.ksh -f TEST007_junk;
drop table if exists trafodion.sch007.thbase1 cascade;
-drop schema trafodion.sch007 cascade;
-?section tests
+?section setup_traf
+set schema hive.hive;
+cqd HIVE_MAX_STRING_LENGTH '20' ;
+create schema if not exists trafodion.sch007;
+
+?section tests_traf
-- tests for views on hive tables
sh echo "drop table thive1;" > TEST007_junk;
sh regrhive.ksh -f TEST007_junk;
@@ -121,7 +128,7 @@ showddl hive.hive.thive2;
showddl trafodion.sch007.vhive3;
get all views on table hive.hive.thive2;
-?section error_tests
+?section error_tests_traf
create view trafodion.sch007.vhive4 as select x.a, y.b from thive1 x, thive1 y;
@@ -158,3 +165,119 @@ showddl hive.hive.thive3;
get all views on table hive.hive.thive3;
get all tables in view trafodion.sch007.vhive6;
+?section clean_up_hive
+sh echo "drop table hivesch007.thive1;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "drop view hivesch007.vhive11;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "drop view hivesch007.vhive1;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "drop database hivesch007;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "drop table thive007;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "drop view vhive007;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+drop view trafodion.sch007.vtrafonhive;
+
+drop schema trafodion.sch007 cascade;
+
+?section setup_hive
+sh echo "create database hivesch007;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "create table hivesch007.thive1 (a int);" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "insert into hivesch007.thive1 values (1);" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "create view hivesch007.vhive1 as select * from hivesch007.thive1 where thive1.a > 0;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "create view hivesch007.vhive11 as select * from hivesch007.vhive1 where vhive1.a > 0;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "create table thive007 (a int);" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+sh echo "create view vhive007 as select * from thive007 where a > 0;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+insert into hive.hive.thive007 values (1);
+
+?section tests_hive
+invoke hive.hivesch007.vhive1;
+showddl hive.hivesch007.vhive1;
+
+prepare s from select * from hive.hivesch007.vhive1;
+explain options 'f' s;
+execute s;
+
+invoke hive.hivesch007.vhive11;
+showddl hive.hivesch007.vhive11;
+
+prepare s from select * from hive.hivesch007.vhive11;
+explain options 'f' s;
+execute s;
+
+prepare s from select * from hive.hive.vhive007;
+explain options 'f' s;
+execute s;
+
+get tables in schema hive.hivesch007;
+get views in schema hive.hivesch007;
+
+get tables in schema hive.hive, match '%007%';
+get views in schema hive.hive, match '%007%';
+
+get tables in catalog hive, match 'hivesch007%';
+get views in catalog hive, match 'hivesch007%';
+
+set schema hive.hive;
+prepare s from select * from vhive007 x, hive.hivesch007.vhive1 y
+ where x.a = y.a;
+explain options 'f' s;
+execute s;
+
+-- create traf view on native hive view
+create schema if not exists trafodion.sch007;
+create view trafodion.sch007.vtrafonhive as select * from hive.hivesch007.vhive11;
+showddl trafodion.sch007.vtrafonhive;
+prepare s from select * from trafodion.sch007.vtrafonhive;
+explain options 'f' s;
+execute s;
+get tables in view trafodion.sch007.vtrafonhive;
+
+?section error_tests_hive
+get tables in view hive.hivesch007.vhive11;
+get views on table hive.hivesch007.thive1;
+
+insert into hive.hivesch007.vhive1 values (1);
+delete from hive.hivesch007.vhive1;
+
+-- drop underlying hive table
+cqd auto_query_retry_warnings 'ON';
+
+sh echo "drop table hivesch007.thive1;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+prepare s from select * from hive.hivesch007.vhive11;
+execute s;
+
+sh echo "create table hivesch007.thive1 (a int);" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+prepare s from select * from hive.hivesch007.vhive11;
+execute s;
+
+sh echo "drop table hivesch007.thive1;" > TEST007_junk;
+sh regrhive.ksh -f TEST007_junk;
+
+execute s;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/regress/seabase/EXPECTED002
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED002 b/core/sql/regress/seabase/EXPECTED002
index 753aee2..f417114 100644
--- a/core/sql/regress/seabase/EXPECTED002
+++ b/core/sql/regress/seabase/EXPECTED002
@@ -63,7 +63,7 @@ A B
>>invoke table(region stats ());
-- Definition of Trafodion table TRAFODION.T002SCH.EXE_UTIL_REGION_STATS__
--- Definition current Mon Nov 21 23:47:42 2016
+-- Definition current Sun Feb 19 01:38:58 2017
(
CATALOG_NAME CHAR(256 BYTES) CHARACTER SET UTF8 COLLATE
@@ -90,7 +90,7 @@ A B
>>invoke table(region stats (t002t1));
-- Definition of Trafodion table TRAFODION.T002SCH.EXE_UTIL_REGION_STATS__
--- Definition current Mon Nov 21 23:47:42 2016
+-- Definition current Sun Feb 19 01:38:59 2017
(
CATALOG_NAME CHAR(256 BYTES) CHARACTER SET UTF8 COLLATE
@@ -125,7 +125,7 @@ A B
(EXPR) REGION_NUM REGION_NAME NUM_STORES NUM_STORE_FILES STORE_FILE_UNCOMP_SIZE STORE_FILE_SIZE MEM_STORE_SIZE (EXPR) (EXPR)
-------------------------------------------------------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- --------------- ---------------------- -------------------- -------------------- ----------------------------- ------------------------------
-T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1/1479772003905 2 0 0 0 0 ReadRequestsCount: 2 WriteRequestsCount: 1
+T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1/1487468269771 2 0 0 0 0 ReadRequestsCount: 2 WriteRequestsCount: 1
--- 1 row(s) selected.
>>
@@ -139,7 +139,7 @@ T002SCH.T002T1 1
(EXPR) REGION_NUM REGION_NAME NUM_STORES NUM_STORE_FILES STORE_FILE_UNCOMP_SIZE STORE_FILE_SIZE MEM_STORE_SIZE (EXPR) (EXPR)
-------------------------------------------------------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- --------------- ---------------------- -------------------- -------------------- ----------------------------- ------------------------------
-T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1I1/1479772006300 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 1
+T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1I1/1487468274213 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 1
--- 1 row(s) selected.
>>
@@ -153,10 +153,10 @@ T002SCH.T002T1 1
(EXPR) REGION_NUM REGION_NAME NUM_STORES NUM_STORE_FILES STORE_FILE_UNCOMP_SIZE STORE_FILE_SIZE MEM_STORE_SIZE (EXPR) (EXPR)
-------------------------------------------------------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- --------------- ---------------------- -------------------- -------------------- ----------------------------- ------------------------------
-T002SCH.T002T2 1 TRAFODION.T002SCH.T002T2/1479772039247 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 0
-T002SCH.T002T2 2 TRAFODION.T002SCH.T002T2/1479772039247 2 0 0 0 0 ReadRequestsCount: 1 WriteRequestsCount: 1
-T002SCH.T002T2 3 TRAFODION.T002SCH.T002T2/1479772039247 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 0
-T002SCH.T002T2 4 TRAFODION.T002SCH.T002T2/1479772039247 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 0
+T002SCH.T002T2 1 TRAFODION.T002SCH.T002T2/1487468311299 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 0
+T002SCH.T002T2 2 TRAFODION.T002SCH.T002T2/1487468311299 2 0 0 0 0 ReadRequestsCount: 1 WriteRequestsCount: 1
+T002SCH.T002T2 3 TRAFODION.T002SCH.T002T2/1487468311299 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 0
+T002SCH.T002T2 4 TRAFODION.T002SCH.T002T2/1487468311299 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 0
--- 4 row(s) selected.
>>
@@ -170,7 +170,7 @@ T002SCH.T002T2 4
(EXPR) REGION_NUM REGION_NAME NUM_STORES NUM_STORE_FILES STORE_FILE_UNCOMP_SIZE STORE_FILE_SIZE MEM_STORE_SIZE (EXPR) (EXPR)
-------------------------------------------------------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- --------------- ---------------------- -------------------- -------------------- ----------------------------- ------------------------------
-T002SCH.T002T2 1 TRAFODION.T002SCH.T002T2I1/1479772043929 2 0 0 0 0 ReadRequestsCount: 1 WriteRequestsCount: 1
+T002SCH.T002T2 1 TRAFODION.T002SCH.T002T2I1/1487468316703 2 0 0 0 0 ReadRequestsCount: 1 WriteRequestsCount: 1
--- 1 row(s) selected.
>>
@@ -230,9 +230,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T1/1479772003905
+ RegionName: TRAFODION.T002SCH.T002T1/1487468269771
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -263,9 +263,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T1I1/1479772006300
+ RegionName: TRAFODION.T002SCH.T002T1I1/1487468274213
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -296,9 +296,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -307,9 +307,9 @@ Stats Details
ReadRequestsCount: 0
WriteRequestsCount: 0
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 2
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -318,9 +318,9 @@ Stats Details
ReadRequestsCount: 1
WriteRequestsCount: 1
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 3
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -329,9 +329,9 @@ Stats Details
ReadRequestsCount: 0
WriteRequestsCount: 0
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 4
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -362,9 +362,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T2I1/1479772043929
+ RegionName: TRAFODION.T002SCH.T002T2I1/1487468316703
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -396,9 +396,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T1/1479772003905
+ RegionName: TRAFODION.T002SCH.T002T1/1487468269771
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -432,9 +432,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.SB_HISTOGRAMS/1479771997150
+ RegionName: TRAFODION.T002SCH.SB_HISTOGRAMS/1487468261131
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -461,9 +461,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.SB_HISTOGRAM_INTERVALS/1479771999149
+ RegionName: TRAFODION.T002SCH.SB_HISTOGRAM_INTERVALS/1487468264073
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -490,9 +490,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.SB_PERSISTENT_SAMPLES/1479772001686
+ RegionName: TRAFODION.T002SCH.SB_PERSISTENT_SAMPLES/1487468266488
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -519,9 +519,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T1/1479772003905
+ RegionName: TRAFODION.T002SCH.T002T1/1487468269771
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -548,9 +548,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -559,9 +559,9 @@ Stats Details
ReadRequestsCount: 0
WriteRequestsCount: 0
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 2
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -570,9 +570,9 @@ Stats Details
ReadRequestsCount: 1
WriteRequestsCount: 1
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 3
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -581,9 +581,9 @@ Stats Details
ReadRequestsCount: 0
WriteRequestsCount: 0
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 4
- RegionName: TRAFODION.T002SCH.T002T2/1479772039247
+ RegionName: TRAFODION.T002SCH.T002T2/1487468311299
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -607,8 +607,8 @@ Stats Details
(EXPR) REGION_NUM REGION_NAME NUM_STORES NUM_STORE_FILES STORE_FILE_UNCOMP_SIZE STORE_FILE_SIZE MEM_STORE_SIZE (EXPR) (EXPR)
-------------------------------------------------------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- --------------- ---------------------- -------------------- -------------------- ----------------------------- ------------------------------
-T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1I1/1479772006300 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 1
-T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1I2/1479772011884 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 1
+T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1I1/1487468274213 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 1
+T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1I2/1487468279138 2 0 0 0 0 ReadRequestsCount: 0 WriteRequestsCount: 1
--- 2 row(s) selected.
>>get region stats for
@@ -633,9 +633,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T1I1/1479772006300
+ RegionName: TRAFODION.T002SCH.T002T1I1/1487468274213
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -662,9 +662,9 @@ Stats Summary
Stats Details
=============
- RegionServer: ansharma-4:45984
+ RegionServer: edev08:44319
RegionNum: 1
- RegionName: TRAFODION.T002SCH.T002T1I2/1479772011884
+ RegionName: TRAFODION.T002SCH.T002T1I2/1487468279138
NumStores: 2
NumStoreFiles: 0
UncompressedSize: 0 (less than 1MB)
@@ -836,7 +836,7 @@ Stats Summary
(EXPR) REGION_NUM REGION_NAME NUM_STORES NUM_STORE_FILES
------------------------------ -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- ---------------
-T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1/1479772003905 2 0
+T002SCH.T002T1 1 TRAFODION.T002SCH.T002T1/1487468269771 2 0
--- 1 row(s) selected.
>>
@@ -858,7 +858,7 @@ T002T1 0
>>invoke table(cluster stats());
-- Definition of Trafodion table TRAFODION.T002SCH.EXE_UTIL_CLUSTER_STATS__
--- Definition current Mon Nov 21 23:47:47 2016
+-- Definition current Sun Feb 19 01:39:04 2017
(
REGION_SERVER CHAR(256 BYTES) CHARACTER SET UTF8 COLLATE
@@ -911,14 +911,14 @@ T002SCH.T002T2I1 0
(EXPR) (EXPR)
------------------------------ --------------------
-RegionName: 1479771997150 0
-RegionName: 1479771999149 0
-RegionName: 1479772039247 0
-RegionName: 1479772011884 0
-RegionName: 1479772006300 0
-RegionName: 1479772001686 0
-RegionName: 1479772003905 0
-RegionName: 1479772043929 0
+RegionName: 1487468266488 0
+RegionName: 1487468311299 0
+RegionName: 1487468274213 0
+RegionName: 1487468269771 0
+RegionName: 1487468261131 0
+RegionName: 1487468279138 0
+RegionName: 1487468264073 0
+RegionName: 1487468316703 0
--- 8 row(s) selected.
>>
@@ -929,7 +929,7 @@ RegionName: 1479772043929 0
>>invoke table(hivemd(tables));
-- Definition of Trafodion table TRAFODION.T002SCH.HIVEMD_TABLES__
--- Definition current Mon Nov 21 23:47:48 2016
+-- Definition current Sun Feb 19 01:39:05 2017
(
CATALOG_NAME CHAR(256 BYTES) CHARACTER SET UTF8 COLLATE
@@ -961,7 +961,7 @@ RegionName: 1479772043929 0
>>invoke table(hivemd(columns));
-- Definition of Trafodion table TRAFODION.T002SCH.HIVEMD_COLUMNS__
--- Definition current Mon Nov 21 23:47:49 2016
+-- Definition current Sun Feb 19 01:39:06 2017
(
CATALOG_NAME CHAR(256 BYTES) CHARACTER SET UTF8 COLLATE
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/regress/tools/runallsb
----------------------------------------------------------------------
diff --git a/core/sql/regress/tools/runallsb b/core/sql/regress/tools/runallsb
index 6411547..b5a8e2d 100755
--- a/core/sql/regress/tools/runallsb
+++ b/core/sql/regress/tools/runallsb
@@ -42,6 +42,8 @@ export SQLMX_REGRESS=1
export SEABASE_REGRESS=2
TEST_SUBDIRS="core compGeneral executor seabase hive fullstack2 charsets qat privs1 privs2 udr"
+BASE_SUBDIRS="core compGeneral executor seabase hive"
+OTHER_SUBDIRS="fullstack2 charsets qat privs1 privs2 udr"
#
# Make sure we're running from the regress subdir
@@ -56,6 +58,8 @@ fi
diffOnly=0
failedOnly=0
+baseTests=0
+otherTests=0
OK=-1
while [ $OK -ne 0 ]; do # loop to allow options to appear in any order
@@ -76,8 +80,24 @@ while [ $OK -ne 0 ]; do # loop to allow options to appear in any order
OK=1
fi
+ if [ "$1" = "-basetests" ]; then
+ baseTests=1
+ OK=1
+ fi
+
+ if [ "$1" = "-othertests" ]; then
+ otherTests=1
+ OK=1
+ fi
+
done
+if [ $baseTests -ne 0 ]; then
+ TEST_SUBDIRS=$BASE_SUBDIRS
+elif [ $otherTests -ne 0 ]; then
+ TEST_SUBDIRS=$OTHER_SUBDIRS
+fi
+
test ! -d $TRAF_HOME/sql/regress && ln -s $TRAF_HOME/../sql/regress $TRAF_HOME/sql/regress
test ! -d $TRAF_HOME/sql/sqludr && ln -s $TRAF_HOME/../sql/sqludr $TRAF_HOME/sql/sqludr
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp
index c9e98e3..1ff4457 100644
--- a/core/sql/sqlcomp/CmpDescribe.cpp
+++ b/core/sql/sqlcomp/CmpDescribe.cpp
@@ -2262,11 +2262,43 @@ short CmpDescribeHiveTable (
return -1;
+ NABoolean isView = (naTable->getViewText() ? TRUE : FALSE);
+
+ if ((type == 2) && (isView))
+ {
+ outputShortLine(space,"Original native Hive view text:");
+ NAString origViewText(naTable->getHiveOriginalViewText());
+ outputLongLine(space, origViewText, 0);
+ outputShortLine(space, " ");
+
+ outputShortLine(space,"Expanded native Hive view text:");
+ NAString viewtext(naTable->getViewText());
+
+ viewtext = viewtext.strip(NAString::trailing, ';');
+ viewtext += " ;";
+
+ outputLongLine(space, viewtext, 0);
+
+ outbuflen = space.getAllocatedSpaceSize();
+ outbuf = new (heap) char[outbuflen];
+ space.makeContiguous(outbuf, outbuflen);
+
+ NADELETEBASIC(buf, heap);
+
+ return 0;
+ }
+
if (type == 1)
{
- sprintf(buf, "-- Definition of hive table %s\n"
- "-- Definition current %s",
- tableName.data(), ctime(&tp));
+ if (isView)
+ sprintf(buf, "-- Definition of native Hive view %s\n"
+ "-- Definition current %s",
+ tableName.data(), ctime(&tp));
+ else
+ sprintf(buf, "-- Definition of hive table %s\n"
+ "-- Definition current %s",
+ tableName.data(), ctime(&tp));
+
outputShortLine(space, buf);
}
else if (type == 2)
@@ -2305,28 +2337,32 @@ short CmpDescribeHiveTable (
outputShortLine(space, " )");
- const HHDFSTableStats* hTabStats =
- naTable->getClusteringIndex()->getHHDFSTableStats();
- if (hTabStats->isOrcFile())
- {
- if (type == 1)
- outputShortLine(space, " /* stored as orc */");
- else
- outputShortLine(space, " stored as orc ");
- }
- else if (hTabStats->isTextFile())
- {
- if (type == 1)
- outputShortLine(space, " /* stored as textfile */");
- else
- outputShortLine(space, " stored as textfile ");
- }
- else if (hTabStats->isSequenceFile())
+ const HHDFSTableStats* hTabStats = NULL;
+ if (naTable->getClusteringIndex())
+ hTabStats = naTable->getClusteringIndex()->getHHDFSTableStats();
+ if (hTabStats)
{
- if (type == 1)
- outputShortLine(space, " /* stored as sequence */");
- else
- outputShortLine(space, " stored as sequence ");
+ if (hTabStats->isOrcFile())
+ {
+ if (type == 1)
+ outputShortLine(space, " /* stored as orc */");
+ else
+ outputShortLine(space, " stored as orc ");
+ }
+ else if (hTabStats->isTextFile())
+ {
+ if (type == 1)
+ outputShortLine(space, " /* stored as textfile */");
+ else
+ outputShortLine(space, " stored as textfile ");
+ }
+ else if (hTabStats->isSequenceFile())
+ {
+ if (type == 1)
+ outputShortLine(space, " /* stored as sequence */");
+ else
+ outputShortLine(space, " stored as sequence ");
+ }
}
if (type == 2)
@@ -2786,6 +2822,7 @@ short CmpDescribeSeabaseTable (
NABoolean isVolatile = naTable->isVolatileTable();
NABoolean isExternalTable = naTable->isExternalTable();
+ NABoolean isImplicitExternalTable = naTable->isImplicitExternalTable();
NABoolean isHbaseMapTable = naTable->isHbaseMapTable();
NABoolean isExternalHbaseTable = FALSE;
@@ -2958,7 +2995,12 @@ short CmpDescribeSeabaseTable (
if (isVolatile)
tabType = " VOLATILE ";
else if (isExternalTable)
- tabType = " EXTERNAL ";
+ {
+ if (isImplicitExternalTable)
+ tabType = " /*IMPLICIT*/ EXTERNAL ";
+ else
+ tabType = " EXTERNAL ";
+ }
else
tabType = " ";
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/sqlcomp/CmpSeabaseDDLmd.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLmd.h b/core/sql/sqlcomp/CmpSeabaseDDLmd.h
index 5900a80..64434f4 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLmd.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLmd.h
@@ -263,7 +263,13 @@ enum SeabaseObjectsFlags {
MD_OBJECTS_STORED_DESC = 0x0000000000000004,
// stored descriptor is disabled, should not be used
- MD_OBJECTS_DISABLE_STORED_DESC = 0x0000000000000008
+ MD_OBJECTS_DISABLE_STORED_DESC = 0x0000000000000008,
+
+ // set if this object was created as an implicit external hive table.
+ // This happens if an external table was created for internal usage
+ // (currently for: privilege info, ustat, views).
+ SEABASE_OBJECT_IS_IMPLICIT_EXTERNAL_HIVE = 0x0000000000000010
+
};
static const QString seabaseRefConstraintsDDL[] =
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index cdf46b8..e921382 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -509,8 +509,14 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
tableInfo->hbaseCreateOptions = NULL;
tableInfo->numSaltPartns = 0;
tableInfo->rowFormat = COM_UNKNOWN_FORMAT_TYPE;
- tableInfo->objectFlags = (isHive) ? SEABASE_OBJECT_IS_EXTERNAL_HIVE :
- SEABASE_OBJECT_IS_EXTERNAL_HBASE;
+ if (isHive)
+ {
+ tableInfo->objectFlags = SEABASE_OBJECT_IS_EXTERNAL_HIVE;
+ if (createTableNode->isImplicitExternal())
+ tableInfo->objectFlags |= SEABASE_OBJECT_IS_IMPLICIT_EXTERNAL_HIVE;
+ }
+ else
+ tableInfo->objectFlags = SEABASE_OBJECT_IS_EXTERNAL_HBASE;
tableInfo->tablesFlags = 0;
if (isAuthorizationEnabled())
@@ -555,6 +561,17 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
return -1;
}
+ if ((naTable->isHiveTable()) &&
+ (naTable->getViewText()) &&
+ (!Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL)))
+ {
+ *CmpCommon::diags()
+ << DgSqlCode(-3242)
+ << DgString0("Cannot create external table on a native Hive view.");
+
+ return -1;
+ }
+
ElemDDLColDefArray &colArray = createTableNode->getColDefArray();
ElemDDLColRefArray &keyArray =
(createTableNode->getIsConstraintPKSpecified() ?
@@ -3644,7 +3661,8 @@ short CmpSeabaseDDL::dropSeabaseTable2(
schemaNamePart,
catalogNamePart);
- bindWA.setExternalTableDrop(TRUE);
+ if (dropTableNode->isExternal())
+ bindWA.setExternalTableDrop(TRUE);
NATable *naTable = bindWA.getNATableInternal(cn, TRUE, NULL, TRUE);
bindWA.setExternalTableDrop(FALSE);
@@ -9621,7 +9639,7 @@ void CmpSeabaseDDL::seabaseGrantRevoke(
// not exists, the "create external" table command creates it.
char query[(ComMAX_ANSI_IDENTIFIER_EXTERNAL_LEN*4) + 100];
snprintf(query, sizeof(query),
- "create external table \"%s\" for %s.\"%s\".\"%s\"",
+ "create implicit external table \"%s\" for %s.\"%s\".\"%s\"",
objectNamePart.data(),
catalogNamePart.data(),
schemaNamePart.data(),
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
index e974880..31950d9 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
@@ -371,11 +371,12 @@ short CmpSeabaseDDL::updateViewUsage(StmtDDLCreateView * createViewParseNode,
}
if ((naTable->isHiveTable()) &&
+ (NOT naTable->getViewText()) &&
(NOT naTable->hasExternalTable()) &&
(CmpCommon::getDefault(HIVE_VIEWS_CREATE_EXTERNAL_TABLE) == DF_ON))
{
// create an external table for this hive table.
- str_sprintf(query, "create external table \"%s\" for %s.\"%s\".\"%s\"",
+ str_sprintf(query, "create implicit external table \"%s\" for %s.\"%s\".\"%s\"",
objectNamePart.data(),
catalogNamePart.data(),
schemaNamePart.data(),
@@ -412,7 +413,8 @@ short CmpSeabaseDDL::updateViewUsage(StmtDDLCreateView * createViewParseNode,
// do not put in view usage list if it doesn't have an external table
if (usedObjUID == -1)
{
- appendErrorObjName(hiveObjsNoUsage, extUsedObjName);
+ if (! naTable->getViewText())
+ appendErrorObjName(hiveObjsNoUsage, extUsedObjName);
continue;
}
} // hive table
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/ustat/hs_la.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_la.cpp b/core/sql/ustat/hs_la.cpp
index cdcbe13..8d5685a 100644
--- a/core/sql/ustat/hs_la.cpp
+++ b/core/sql/ustat/hs_la.cpp
@@ -883,6 +883,16 @@ NABoolean HSHiveTableDef::objExists(NABoolean createExternalTable)
if (!setObjectUID(createExternalTable))
return FALSE;
+ // cannot upd stats if the object is a hive view
+ if (naTbl_->getViewText())
+ {
+ *CmpCommon::diags()
+ << DgSqlCode(-UERR_INVALID_OBJECT)
+ << DgString0(naTbl_->getTableName().getQualifiedNameAsString());
+
+ return FALSE;
+ }
+
tableStats_ = naTbl_->getClusteringIndex()->getHHDFSTableStats();
*ansiName_ = *catalog_;
@@ -1084,7 +1094,7 @@ Lng32 CreateExternalTable(const NAString& catName, const NAString& schName, cons
// do not have to worry about the catalog and schema for the new external table
// here. These names will be determined by the processing logic.
- NAString ddl = "CREATE EXTERNAL TABLE ";
+ NAString ddl = "CREATE IMPLICIT EXTERNAL TABLE ";
ddl.append(nativeTableName);
ddl.append(" FOR ");
ddl.append(catName);
@@ -1095,8 +1105,13 @@ Lng32 CreateExternalTable(const NAString& catName, const NAString& schName, cons
ddl.append(" ATTRIBUTE NO AUDIT"); // The external table will not be audited because it
// does not store any data.
+ // set INTERNAL_QUERY_FROM_EXEUTIL bit in Sql_ParserFlags.
+ // This is needed to process 'implicit external' syntax
+ ULng32 flagToSet = INTERNAL_QUERY_FROM_EXEUTIL;
+ PushAndSetSqlParserFlags savedParserFlags(flagToSet);
+
Lng32 retcode = HSFuncExecDDL(ddl.data(), - UERR_INTERNAL_ERROR, NULL,
- "Create external table", NULL);
+ "Create implicit external table", NULL);
if (retcode < 0 && LM->LogNeeded())
{
[3/4] incubator-trafodion git commit: TRAFODION-2492 Support for
native hive views, plus few more changes
Posted by su...@apache.org.
TRAFODION-2492 Support for native hive views, plus few more changes
-- added support for native hive views created externally. These views
can be accessed in a traf sql query.
There are some restrictions as listed below:
-- privileges support has not yet been added. That will be done, as
needed, in the next checkin.
-- usage info for tables contained in a native hive view is not maintained.
-- native hive views cannot be inserted/updated/deleted
-- cannot update stats on a native hive view
-- support for GET statements to retrieve hive data
get tables/views/objects in schema hive.sch;
-- this will return all tables/views in specified schema(hive database)
get tables/views/objects in catalog hive;
-- this will return all tables/views in hive
get schemas in catalog hive;
-- this will return all schemas(databases) that exist in hive
-- GET statements to retrieve hive data now supports optional MATCH clause.
This can be used to filter results.
-- showddl will show if an external table on hive was created implicitly
for internal usage (upd stats, privileges, views) or explicitly by user.
Internal creation of external table now use 'create implicit external table'
syntax and that info is stored in metadata.
-- drop external table will drop that table even if underlying hive table
is missing. Currently it returns an error.
-- at runtime, accessing a missing hive table now returns a better error
message instead of an internal "data mod check failed" message.
-- regress/tools/runallsb has 2 new options:
-basetests (this will run core,compGeneral,executor,seabase,hive)
-othertests (this will run all other tests suites)
-- optimizer/NATable.cpp was incorrectly indented by some checkin from
a few days back. TABs were used instead of spaces which caused code
to become all crooked. That has been fixed.
-- regress/hive/TEST007 has been updated with additional hive view tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/4c3077ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/4c3077ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/4c3077ce
Branch: refs/heads/master
Commit: 4c3077ce8277ac4ced7d114464348b992e94b4b0
Parents: cd83797
Author: Anoop Sharma <an...@esgyn.com>
Authored: Wed Feb 22 18:02:05 2017 +0000
Committer: Anoop Sharma <an...@esgyn.com>
Committed: Wed Feb 22 18:02:05 2017 +0000
----------------------------------------------------------------------
core/sql/bin/SqlciErrors.txt | 1 +
core/sql/cli/Statement.cpp | 7 +
core/sql/comexe/ComTdbExeUtil.h | 21 +-
core/sql/executor/ExExeUtil.h | 10 +-
core/sql/executor/ExExeUtilGet.cpp | 203 +-
core/sql/executor/ExHdfsScan.cpp | 11 +-
core/sql/executor/hiveHook.cpp | 66 +-
core/sql/generator/GenRelExeUtil.cpp | 62 +-
core/sql/generator/GenRelScan.cpp | 2 +-
core/sql/optimizer/BindRelExpr.cpp | 34 +-
core/sql/optimizer/NATable.cpp | 4860 +++++++++++++-------------
core/sql/optimizer/NATable.h | 14 +-
core/sql/optimizer/hiveHook.h | 24 +-
core/sql/parser/SqlParserAux.cpp | 5 +
core/sql/parser/SqlParserAux.h | 1 +
core/sql/parser/StmtDDLNode.cpp | 1 +
core/sql/parser/StmtDDLNode.h | 10 +
core/sql/parser/sqlparser.y | 14 +
core/sql/regress/hive/EXPECTED007 | 334 +-
core/sql/regress/hive/TEST007 | 153 +-
core/sql/regress/seabase/EXPECTED002 | 118 +-
core/sql/regress/tools/runallsb | 20 +
core/sql/sqlcomp/CmpDescribe.cpp | 92 +-
core/sql/sqlcomp/CmpSeabaseDDLmd.h | 8 +-
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 26 +-
core/sql/sqlcomp/CmpSeabaseDDLview.cpp | 6 +-
core/sql/ustat/hs_la.cpp | 19 +-
27 files changed, 3540 insertions(+), 2582 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index fe99787..69b628a 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -1310,6 +1310,7 @@ $1~String1 --------------------------------
4259 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Primary Key clause must be specified for an HBase mapped table.
4260 ZZZZZ 99999 BEGINNER MAJOR DBADMIN HBase table($0~String0) to be mapped as an external table does not exist.
4261 ZZZZZ 99999 BEGINNER MAJOR DBADMIN The schema name $0~SchemaName is reserved for HBase mapped tables and cannot be explicitly specified.
+4262 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~String0 has invalid state and cannot be accessed. It has an external table but the correponding hive table does not exist. Use 'drop external table' command to drop the external table.
4300 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Use of procedure $0~TableName was not valid - a UDR was invoked within a trigger.
4301 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Use of routine $0~TableName was not valid - return of result sets is not allowed within a trigger.
4302 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Procedure $0~TableName expects $1~Int0 parameters but was called with $1~int1 parameters.
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/cli/Statement.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Statement.cpp b/core/sql/cli/Statement.cpp
index a395b12..d1a0bcc 100644
--- a/core/sql/cli/Statement.cpp
+++ b/core/sql/cli/Statement.cpp
@@ -2100,6 +2100,13 @@ RETCODE Statement::doHiveTableSimCheck(TrafSimilarityTableInfo *si,
<< DgString2(getLobErrStr(intParam1))
<< DgInt0(intParam1)
<< DgInt1(0);
+
+ if (intParam1 == LOB_DATA_FILE_NOT_FOUND_ERROR)
+ {
+ diagsArea << DgSqlCode(-EXE_TABLE_NOT_FOUND)
+ << DgString0(si->tableName());
+ }
+
return ERROR;
}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/comexe/ComTdbExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbExeUtil.h b/core/sql/comexe/ComTdbExeUtil.h
index 3abc2a5..0d9f289 100644
--- a/core/sql/comexe/ComTdbExeUtil.h
+++ b/core/sql/comexe/ComTdbExeUtil.h
@@ -2425,6 +2425,8 @@ public:
VIEWS_IN_CATALOG_,
INVALID_VIEWS_IN_CATALOG_,
SEQUENCES_IN_CATALOG_,
+ TABLES_IN_CATALOG_,
+ OBJECTS_IN_CATALOG_,
TABLES_IN_SCHEMA_,
INDEXES_IN_SCHEMA_,
@@ -3252,6 +3254,18 @@ struct HiveMDSysTablesColInfoStruct
char tblName[256];
};
+static const ComTdbVirtTableColumnInfo hiveMDSchemasColInfo[] =
+{
+ { "CATALOG_NAME", 0, COM_USER_COLUMN, REC_BYTE_F_ASCII, 256, FALSE , SQLCHARSETCODE_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, COM_NO_DEFAULT, "" ,NULL,NULL,COM_UNKNOWN_DIRECTION_LIT, 0},
+ { "SCHEMA_NAME", 1, COM_USER_COLUMN, REC_BYTE_F_ASCII, 256, FALSE , SQLCHARSETCODE_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, COM_NO_DEFAULT, "" ,NULL,NULL,COM_UNKNOWN_DIRECTION_LIT, 0}
+};
+
+struct HiveMDSchemasColInfoStruct
+{
+ char catName[256];
+ char schName[256];
+};
+
class ComTdbExeUtilHiveMDaccess : public ComTdbExeUtil
{
friend class ExExeUtilHiveMDaccessTcb;
@@ -3267,7 +3281,8 @@ public:
FKEYS_,
ALIAS_,
SYNONYMS_,
- SYSTEM_TABLES_
+ SYSTEM_TABLES_,
+ SCHEMAS_
};
// Constructors
@@ -3368,6 +3383,8 @@ public:
return sizeof(hiveMDSynonymColInfo)/sizeof(ComTdbVirtTableColumnInfo);
else if (strcmp(name, "SYSTEM_TABLES") == 0)
return sizeof(hiveMDSysTablesColInfo)/sizeof(ComTdbVirtTableColumnInfo);
+ else if (strcmp(name, "SCHEMAS") == 0)
+ return sizeof(hiveMDSchemasColInfo)/sizeof(ComTdbVirtTableColumnInfo);
else
return -1;
}
@@ -3390,6 +3407,8 @@ public:
return (ComTdbVirtTableColumnInfo*)hiveMDSynonymColInfo;
else if (strcmp(name, "SYSTEM_TABLES") == 0)
return (ComTdbVirtTableColumnInfo*)hiveMDSysTablesColInfo;
+ else if (strcmp(name, "SCHEMAS") == 0)
+ return (ComTdbVirtTableColumnInfo*)hiveMDSchemasColInfo;
else
return NULL;
}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index b0c63f3..46b2d5d 100755
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -3337,14 +3337,19 @@ protected:
enum Step
{
INITIAL_,
- READ_HIVE_MD_,
+ SETUP_SCHEMAS_,
+ GET_ALL_SCHEMAS_,
+ GET_ALL_TABLES_,
+ GET_ALL_TABLES_IN_SCHEMA_,
POSITION_,
+ FETCH_SCHEMA_,
FETCH_TABLE_,
FETCH_COLUMN_,
FETCH_PKEY_,
APPLY_PRED_,
RETURN_ROW_,
ADVANCE_ROW_,
+ ADVANCE_SCHEMA_,
DONE_,
HANDLE_ERROR_,
CANCELLED_
@@ -3357,9 +3362,11 @@ protected:
hive_column_desc * currColDesc_;
hive_pkey_desc * currPartnDesc_;
hive_bkey_desc * currKeyDesc_;
+ Int32 currSchNum_;
Int32 currColNum_;
char * mdRow_;
+ LIST (NAText *) schNames_;
LIST (NAText *) tblNames_;
char hiveCat_[1024];
@@ -3378,7 +3385,6 @@ public:
protected:
};
-
// -----------------------------------------------------------------------
// ExExeUtilHiveTruncateTdb
// -----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp b/core/sql/executor/ExExeUtilGet.cpp
index 7eb6eb1..2d42d70 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -841,6 +841,13 @@ short ExExeUtilGetMetadataInfoTcb::displayHeading()
}
break;
+ case ComTdbExeUtilGetMetadataInfo::TABLES_IN_CATALOG_:
+ {
+ str_sprintf(headingBuf_, "Tables in Catalog %s",
+ getMItdb().getCat());
+ }
+ break;
+
case ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_:
{
str_sprintf(headingBuf_, "Views in Catalog %s",
@@ -848,6 +855,13 @@ short ExExeUtilGetMetadataInfoTcb::displayHeading()
}
break;
+ case ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_CATALOG_:
+ {
+ str_sprintf(headingBuf_, "Objects in Catalog %s",
+ getMItdb().getCat());
+ }
+ break;
+
case ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_:
{
str_sprintf(headingBuf_, "Tables in Schema %s.%s",
@@ -869,6 +883,13 @@ short ExExeUtilGetMetadataInfoTcb::displayHeading()
}
break;
+ case ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_SCHEMA_:
+ {
+ str_sprintf(headingBuf_, "Objects in Schema %s.%s",
+ getMItdb().getCat(), getMItdb().getSch());
+ }
+ break;
+
case ComTdbExeUtilGetMetadataInfo::INVALID_VIEWS_IN_SCHEMA_:
{
str_sprintf(headingBuf_, "Invalid Views in Schema %s.%s",
@@ -3689,8 +3710,28 @@ short ExExeUtilGetHiveMetadataInfoTcb::fetchAllHiveRows(Queue * &infoList,
rc = 0;
char buf[2000];
- str_sprintf(buf, "select rtrim(table_name) from table(hivemd(tables, \"%s\"))",
- getMItdb().getSch());
+ char wherePred[400];
+ if ((getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_) ||
+ (getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::TABLES_IN_CATALOG_))
+ strcpy(wherePred, " where hive_table_type = 'MANAGED_TABLE' or hive_table_type = 'EXTERNAL_TABLE' ");
+ else if ((getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_SCHEMA_) ||
+ (getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_))
+ strcpy(wherePred, " where hive_table_type = 'VIRTUAL_VIEW' ");
+ else if ((getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_SCHEMA_) ||
+ (getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_CATALOG_) ||
+ (getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_))
+ strcpy(wherePred, " ");
+
+ if (getMItdb().queryType() == ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_)
+ str_sprintf(buf, "select trim(schema_name) from table(hivemd(schemas)) group by 1 order by 1");
+ else if (getMItdb().getSch())
+ str_sprintf(buf, "select rtrim(table_name) from table(hivemd(tables, \"%s\")) %s order by 1",
+ getMItdb().getSch(),
+ wherePred);
+ else
+ str_sprintf(buf, "select trim(schema_name) || '.' || trim(table_name) from table(hivemd(tables)) %s order by 1",
+ wherePred);
+
cliRC = fetchAllRows(infoList, buf, 1, TRUE, rc, FALSE);
return cliRC;
@@ -3769,8 +3810,22 @@ short ExExeUtilGetHiveMetadataInfoTcb::work()
OutputInfo * vi = (OutputInfo*)infoList_->getCurr();
char * ptr = vi->get(0);
short len = *(short*)ptr;
- ptr += SQL_VARCHAR_HDR_SIZE;
+ ex_expr::exp_return_type exprRetCode =
+ exprRetCode = evalScanExpr(ptr, len, FALSE);
+ if (exprRetCode == ex_expr::EXPR_FALSE)
+ {
+ // row does not pass the scan expression,
+ // move to the next row.
+ infoList_->advance();
+ break;
+ }
+ else if (exprRetCode == ex_expr::EXPR_ERROR)
+ {
+ step_ = HANDLE_ERROR_;
+ break;
+ }
+
if (NOT headingReturned_)
{
step_ = DISPLAY_HEADING_;
@@ -3778,6 +3833,7 @@ short ExExeUtilGetHiveMetadataInfoTcb::work()
}
short rc = 0;
+ ptr += SQL_VARCHAR_HDR_SIZE;
if (moveRowToUpQueue(ptr, len, &rc))
{
return rc;
@@ -4919,14 +4975,14 @@ ex_tcb * ExExeUtilHiveMDaccessTdb::build(ex_globals * glob)
exe_util_tcb =
new(glob->getSpace()) ExExeUtilHiveMDaccessTcb(*this, glob);
-
+
exe_util_tcb->registerSubtasks();
return (exe_util_tcb);
}
////////////////////////////////////////////////////////////////
-// Constructor for class ExExeUtilGetMetadataInfoTcb
+// Constructor for class ExExeUtilHiveMDaccessTcb
///////////////////////////////////////////////////////////////
ExExeUtilHiveMDaccessTcb::ExExeUtilHiveMDaccessTcb(
const ComTdbExeUtilHiveMDaccess & exe_util_tdb,
@@ -4935,7 +4991,10 @@ ExExeUtilHiveMDaccessTcb::ExExeUtilHiveMDaccessTcb(
hiveMD_(NULL),
currColDesc_(NULL),
currKeyDesc_(NULL),
- tblNames_(getHeap())
+ schNames_(getHeap()),
+ tblNames_(getHeap()),
+ currSchNum_(0),
+ currColNum_(0)
{
step_ = INITIAL_;
@@ -5007,19 +5066,6 @@ short ExExeUtilHiveMDaccessTcb::work()
if (hiveMDtdb().getCatalog())
strcpy(hiveCat_, hiveMDtdb().getCatalog());
- if ((! hiveMDtdb().getSchema()) ||
- (! strcmp(hiveMDtdb().getSchema(), HIVE_SYSTEM_SCHEMA_LC)) ||
- (! strcmp(hiveMDtdb().getSchema(), HIVE_SYSTEM_SCHEMA)))
- {
- strcpy(hiveSch_, HIVE_SYSTEM_SCHEMA_LC);
- strcpy(schForHive_, HIVE_DEFAULT_SCHEMA_EXE);
- }
- else
- {
- strcpy(hiveSch_, hiveMDtdb().getSchema());
- strcpy(schForHive_, hiveSch_);
- }
-
retStatus = hiveMD_->init();
if (!retStatus)
{
@@ -5032,13 +5078,73 @@ short ExExeUtilHiveMDaccessTcb::work()
break;
}
- step_ = READ_HIVE_MD_;
+ step_ = SETUP_SCHEMAS_;
}
break;
- case READ_HIVE_MD_:
+ case SETUP_SCHEMAS_:
+ {
+ if ((hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::SCHEMAS_) ||
+ (! hiveMDtdb().getSchema()))
+ {
+ HVC_RetCode retCode = hiveMD_->getClient()->
+ getAllSchemas(schNames_);
+ if ((retCode != HVC_OK) && (retCode != HVC_DONE))
+ {
+ *diags << DgSqlCode(-1190)
+ << DgString0((char*)
+ "HiveClient_JNI::getAllSchemas()")
+ << DgString1(hiveMD_->getClient()->
+ getErrorText(retCode))
+ << DgInt0(retCode)
+ << DgString2(GetCliGlobals()->getJniErrorStr());
+ step_ = HANDLE_ERROR_;
+ break;
+ }
+ }
+ else
+ {
+ if ((!strcmp(hiveMDtdb().getSchema(), HIVE_SYSTEM_SCHEMA_LC)) ||
+ (!strcmp(hiveMDtdb().getSchema(), HIVE_SYSTEM_SCHEMA)))
+ {
+ strcpy(schForHive_, HIVE_DEFAULT_SCHEMA_EXE);
+ }
+ else
+ {
+ strcpy(schForHive_, hiveMDtdb().getSchema());
+ }
+
+ NAText * nat = new(getHeap()) NAText(schForHive_);
+ schNames_.insert(nat);
+ }
+
+ currSchNum_ = 0;
+
+ if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::SCHEMAS_)
+ step_ = POSITION_;
+ else
+ step_ = GET_ALL_TABLES_IN_SCHEMA_;
+ }
+ break;
+
+ case GET_ALL_TABLES_IN_SCHEMA_:
{
- char* currSch = schForHive_;
+ if (currSchNum_ == schNames_.entries())
+ {
+ step_ = DONE_;
+ break;
+ }
+
+ hiveMD_->clear();
+ tblNames_.clear();
+
+ char* currSch = (char*)schNames_[currSchNum_]->c_str();
+ strcpy(schForHive_, currSch);
+ if (! strcmp(schForHive_, HIVE_DEFAULT_SCHEMA_EXE))
+ strcpy(hiveSch_, HIVE_SYSTEM_SCHEMA_LC);
+ else
+ strcpy(hiveSch_, schForHive_);
+
char* currObj = hiveMDtdb().getObject();
if (! currObj)
@@ -5082,7 +5188,12 @@ short ExExeUtilHiveMDaccessTcb::work()
hiveMD_->position();
htd = hiveMD_->getNext();
- if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::TABLES_)
+ if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::SCHEMAS_)
+ {
+ currSchNum_ = 0;
+ step_ = FETCH_SCHEMA_;
+ }
+ else if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::TABLES_)
{
step_ = FETCH_TABLE_;
}
@@ -5120,6 +5231,30 @@ short ExExeUtilHiveMDaccessTcb::work()
}
break;
+ case FETCH_SCHEMA_:
+ {
+ if (qparent_.up->isFull())
+ return WORK_OK;
+
+ if (currSchNum_ == schNames_.entries())
+ {
+ step_ = DONE_;
+ break;
+ }
+
+ HiveMDSchemasColInfoStruct *infoCol =
+ (HiveMDSchemasColInfoStruct*)mdRow_;
+
+ str_cpy(infoCol->catName, hiveCat_, 256, ' ');
+ if (strcmp(schNames_[currSchNum_]->c_str(), HIVE_DEFAULT_SCHEMA_EXE) == 0)
+ str_cpy(infoCol->schName, HIVE_SYSTEM_SCHEMA_LC, 256, ' ');
+ else
+ str_cpy(infoCol->schName, schNames_[currSchNum_]->c_str(), 256, ' ');
+
+ step_ = APPLY_PRED_;
+ }
+ break;
+
case FETCH_TABLE_:
{
if (qparent_.up->isFull())
@@ -5127,7 +5262,7 @@ short ExExeUtilHiveMDaccessTcb::work()
if (hiveMD_->atEnd())
{
- step_ = DONE_;
+ step_ = ADVANCE_SCHEMA_;
break;
}
@@ -5183,7 +5318,7 @@ short ExExeUtilHiveMDaccessTcb::work()
if ((! currColDesc_) &&
(! currPartnDesc_))
{
- step_ = DONE_;
+ step_ = ADVANCE_SCHEMA_;
break;
}
@@ -5281,7 +5416,7 @@ short ExExeUtilHiveMDaccessTcb::work()
if (! currKeyDesc_)
{
- step_ = DONE_;
+ step_ = ADVANCE_SCHEMA_;
break;
}
@@ -5347,7 +5482,14 @@ short ExExeUtilHiveMDaccessTcb::work()
case ADVANCE_ROW_:
{
- if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::TABLES_)
+ if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::SCHEMAS_)
+ {
+ // move to the next schema
+ currSchNum_++;
+
+ step_ = FETCH_SCHEMA_;
+ }
+ else if (hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::TABLES_)
{
// move to the next table
hiveMD_->advance();
@@ -5401,6 +5543,13 @@ short ExExeUtilHiveMDaccessTcb::work()
}
break;
+ case ADVANCE_SCHEMA_:
+ {
+ currSchNum_++;
+ step_ = GET_ALL_TABLES_IN_SCHEMA_;
+ }
+ break;
+
case HANDLE_ERROR_:
{
retcode = handleError();
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/executor/ExHdfsScan.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExHdfsScan.cpp b/core/sql/executor/ExHdfsScan.cpp
index d8c3a6e..f2087fc 100644
--- a/core/sql/executor/ExHdfsScan.cpp
+++ b/core/sql/executor/ExHdfsScan.cpp
@@ -621,8 +621,14 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
((hdfsErrorDetail == ENOENT) || (hdfsErrorDetail == EAGAIN)))
{
ComDiagsArea * diagsArea = NULL;
- ExRaiseSqlError(getHeap(), &diagsArea,
- (ExeErrorCode)(EXE_HIVE_DATA_MOD_CHECK_ERROR));
+ if (hdfsErrorDetail == ENOENT)
+ ExRaiseSqlError(getHeap(), &diagsArea,
+ (ExeErrorCode)(EXE_TABLE_NOT_FOUND), NULL,
+ NULL, NULL, NULL,
+ hdfsScanTdb().tableName());
+ else
+ ExRaiseSqlError(getHeap(), &diagsArea,
+ (ExeErrorCode)(EXE_HIVE_DATA_MOD_CHECK_ERROR));
pentry_down->setDiagsArea(diagsArea);
step_ = HANDLE_ERROR_AND_DONE;
break;
@@ -682,6 +688,7 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
"HDFS",
(char*)"ExpLOBInterfaceSelectCursor/open",
getLobErrStr(intParam1));
+
pentry_down->setDiagsArea(diagsArea);
step_ = HANDLE_ERROR;
break;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/executor/hiveHook.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/hiveHook.cpp b/core/sql/executor/hiveHook.cpp
index 41bad09..0289423 100644
--- a/core/sql/executor/hiveHook.cpp
+++ b/core/sql/executor/hiveHook.cpp
@@ -71,16 +71,8 @@ HiveMetaData::HiveMetaData() : tbl_(NULL),
HiveMetaData::~HiveMetaData()
{
- CollHeap *h = CmpCommon::contextHeap();
-
+ clear();
disconnect();
-
- hive_tbl_desc* ptr ;
- while (tbl_) {
- ptr = tbl_->next_;
- NADELETEBASIC(tbl_, h);
- tbl_ = ptr;
- }
}
NABoolean HiveMetaData::init()
@@ -197,6 +189,20 @@ NABoolean HiveMetaData::atEnd()
return (currDesc_ ? FALSE : TRUE);
}
+void HiveMetaData::clear()
+{
+ CollHeap *h = CmpCommon::contextHeap();
+
+ hive_tbl_desc* ptr ;
+ while (tbl_) {
+ ptr = tbl_->next_;
+ NADELETEBASIC(tbl_, h);
+ tbl_ = ptr;
+ }
+
+ tbl_ = NULL;
+}
+
NABoolean HiveMetaData::recordError(Int32 errCode,
const char *errMethodName)
{
@@ -674,7 +680,7 @@ struct hive_tbl_desc* HiveMetaData::getFakedTableDesc(const char* tblName)
hive_tbl_desc* tbl1 = new (h) hive_tbl_desc(1, "myHive", "default", "me",
"MANAGED",
- 0, sd1, 0);
+ 0, NULL, NULL, sd1, 0);
return tbl1;
}
@@ -777,6 +783,21 @@ struct hive_tbl_desc* HiveMetaData::getTableDesc(const char* schemaName,
tableTypeStr, "getTableDesc:tableType:###"))
return NULL;
+ NAText viewOriginalStr;
+ NAText viewExpandedStr;
+ if ((NOT tableTypeStr.empty()) && (tableTypeStr == "VIRTUAL_VIEW"))
+ {
+ pos = 0;
+ if(!extractValueStr(this, tblStr, pos, " viewOriginalText:", ", viewExpandedText:",
+ viewOriginalStr, "getTableDesc:viewOriginalText:###"))
+ return NULL;
+
+ pos = 0;
+ if(!extractValueStr(this, tblStr, pos, "viewExpandedText:", ", tableType:",
+ viewExpandedStr, "getTableDesc:viewExpandedText:###"))
+ return NULL;
+ }
+
result =
new (CmpCommon::contextHeap())
struct hive_tbl_desc(0, // no tblID with JNI
@@ -785,6 +806,8 @@ struct hive_tbl_desc* HiveMetaData::getTableDesc(const char* schemaName,
ownerStr.c_str(),
tableTypeStr.c_str(),
creationTS,
+ viewOriginalStr.c_str(),
+ viewExpandedStr.c_str(),
sd, pkey);
// add the new table to the cache
@@ -824,9 +847,14 @@ NABoolean HiveMetaData::validate(Int32 tableId, Int64 redefTS,
hive_tbl_desc::hive_tbl_desc(Int32 tblID, const char* name, const char* schName,
const char * owner,
const char * tableType,
- Int64 creationTS, struct hive_sd_desc* sd,
+ Int64 creationTS,
+ const char * viewOriginalText,
+ const char * viewExpandedText,
+ struct hive_sd_desc* sd,
struct hive_pkey_desc* pk)
- : tblID_(tblID), sd_(sd), creationTS_(creationTS), pkey_(pk), next_(NULL)
+ : tblID_(tblID),
+ viewOriginalText_(NULL), viewExpandedText_(NULL),
+ sd_(sd), creationTS_(creationTS), pkey_(pk), next_(NULL)
{
tblName_ = strduph(name, CmpCommon::contextHeap());
schName_ = strduph(schName, CmpCommon::contextHeap());
@@ -840,6 +868,20 @@ hive_tbl_desc::hive_tbl_desc(Int32 tblID, const char* name, const char* schName,
tableType_ = strduph(tableType, CmpCommon::contextHeap());
else
tableType_ = NULL;
+
+ if (isView())
+ {
+ if (viewOriginalText)
+ viewOriginalText_ = strduph(viewOriginalText, CmpCommon::contextHeap());
+ else
+ viewOriginalText_ = NULL;
+
+ if (viewExpandedText)
+ viewExpandedText_ = strduph(viewExpandedText, CmpCommon::contextHeap());
+ else
+ viewExpandedText_ = NULL;
+ }
+
}
struct hive_column_desc* hive_tbl_desc::getColumns()
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/generator/GenRelExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelExeUtil.cpp b/core/sql/generator/GenRelExeUtil.cpp
index 1822725..74ded8e 100644
--- a/core/sql/generator/GenRelExeUtil.cpp
+++ b/core/sql/generator/GenRelExeUtil.cpp
@@ -1639,6 +1639,8 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
{ "ALL", "INVALID_VIEWS", "IN", "CATALOG", 1, 1, 0, 0, ComTdbExeUtilGetMetadataInfo::INVALID_VIEWS_IN_CATALOG_ },
{ "USER", "SEQUENCES", "IN", "CATALOG", 1, 1, 0, 0, ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
{ "ALL", "SEQUENCES", "IN", "CATALOG", 1, 1, 0, 0, ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
+ { "USER", "TABLES", "IN", "CATALOG", 1, 1, 0, 0, ComTdbExeUtilGetMetadataInfo::TABLES_IN_CATALOG_ },
+ { "USER", "OBJECTS", "IN", "CATALOG", 1, 1, 0, 0, ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_CATALOG_ },
{ "USER", "TABLES", "IN", "SCHEMA", 1, 2, 0, 0, ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_ },
{ "SYSTEM", "TABLES", "IN", "SCHEMA", 1, 2, 0, 0, ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_ },
@@ -1890,17 +1892,6 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
if (objectType_ == "COMPONENT")
objName = objectName_.getQualifiedNameObj().getObjectName();
- if (catName.isNull())
- catName =
- generator->currentCmpContext()->schemaDB_->getDefaultSchema().getCatalogName();
-
- if (schName.isNull())
- schName =
- generator->currentCmpContext()->schemaDB_->getDefaultSchema().getSchemaName();
-
- if (objName.isNull())
- objName = "DUMMY__";
-
NAString hiveDefCatName = "";
CmpCommon::getDefault(HIVE_CATALOG, hiveDefCatName, FALSE);
hiveDefCatName.toUpper();
@@ -1911,11 +1902,25 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
if (((catName == hiveDefCatName) ||
(catName == HIVE_SYSTEM_CATALOG)) &&
- (queryType == ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_))
+ (queryType != ComTdbExeUtilGetMetadataInfo::VIEWS_ON_TABLE_))
{
setHiveObjects(TRUE);
}
-
+
+ if (NOT hiveObjects())
+ {
+ if (catName.isNull())
+ catName =
+ generator->currentCmpContext()->schemaDB_->getDefaultSchema().getCatalogName();
+
+ if (schName.isNull())
+ schName =
+ generator->currentCmpContext()->schemaDB_->getDefaultSchema().getSchemaName();
+
+ if (objName.isNull())
+ objName = "DUMMY__";
+ }
+
if (hiveObjects())
{
if (CmpCommon::getDefault(MODE_SEAHIVE) == DF_OFF)
@@ -1926,10 +1931,15 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
GenExit();
}
- // right now, only retrieval of tables in hive schema is supported.
- // when other object types are supported, modify the following check
- // accordingly.
- if (queryType != ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_)
+ // retrieval of tables, views and all objects in hive schema is supported.
+ if (NOT((queryType == ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_SCHEMA_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_SCHEMA_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::TABLES_IN_CATALOG_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_CATALOG_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_ON_TABLE_) ||
+ (queryType == ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_)))
{
*CmpCommon::diags() << DgSqlCode(-4219);
GenExit();
@@ -4542,6 +4552,8 @@ const char * HiveMDaccessFunc::getVirtualTableName()
return "HIVEMD_SYNONYMS__";
else if (mdType_ == "SYSTEM_TABLES")
return "HIVEMD_SYSTEM_TABLES__";
+ else if (mdType_ == "SCHEMAS")
+ return "HIVEMD_SCHEMAS__";
else
return "HIVEMD__";
}
@@ -4797,12 +4809,12 @@ short HiveMDaccessFunc::codeGen(Generator * generator)
char * schemaName = NULL;
NAString schemaNameInt ;
- if (schemaName_.isNull())
- schemaNameInt = HIVE_SYSTEM_SCHEMA_LC;
- else
- schemaNameInt = schemaName_;
- schemaName = space->allocateAlignedSpace(schemaNameInt.length() + 1);
- strcpy(schemaName, schemaNameInt.data());
+ if (NOT schemaName_.isNull())
+ {
+ schemaNameInt = schemaName_;
+ schemaName = space->allocateAlignedSpace(schemaNameInt.length() + 1);
+ strcpy(schemaName, schemaNameInt.data());
+ }
char * objectName = NULL;
if (NOT objectName_.isNull()) {
@@ -4828,10 +4840,12 @@ short HiveMDaccessFunc::codeGen(Generator * generator)
type = ComTdbExeUtilHiveMDaccess::VIEWS_;
else if (mdType_ == "ALIAS")
type = ComTdbExeUtilHiveMDaccess::ALIAS_;
- else if (mdType_ == "SYNONYMSS")
+ else if (mdType_ == "SYNONYMS")
type = ComTdbExeUtilHiveMDaccess::SYNONYMS_;
else if (mdType_ == "SYSTEM_TABLES")
type = ComTdbExeUtilHiveMDaccess::SYSTEM_TABLES_;
+ else if (mdType_ == "SCHEMAS")
+ type = ComTdbExeUtilHiveMDaccess::SCHEMAS_;
ComTdbExeUtilHiveMDaccess *hiveTdb
= new(space)
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/generator/GenRelScan.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelScan.cpp b/core/sql/generator/GenRelScan.cpp
index 5dbc237..52304ea 100644
--- a/core/sql/generator/GenRelScan.cpp
+++ b/core/sql/generator/GenRelScan.cpp
@@ -1254,7 +1254,7 @@ if (hTabStats->isOrcFile())
}
char * tablename =
- space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName()), 0);
+ space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getTableDesc()->getNATable()->getTableName()), 0);
char * nullFormat = NULL;
if (hTabStats->getNullFormat())
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/optimizer/BindRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index ec706c6..cc3aea2 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -2000,7 +2000,20 @@ RelExpr *BindWA::bindView(const CorrName &viewName,
CMPASSERT(viewName.getQualifiedNameObj() == naTable->getTableName());
NABoolean inViewExpansion = bindWA->setInViewExpansion(TRUE); // QSTUFF
-
+
+ // If this is a native hive view, then temporarily change the default schema to
+ // that of viewName. This will make sure that all unqualified objects in view
+ // text are expanded in this schema.
+ NABoolean defSchWasChanged = FALSE;
+ SchemaName savedSch(bindWA->getDefaultSchema());
+ if (viewName.isHive())
+ {
+ SchemaName s(viewName.getQualifiedNameObj().getSchemaName(),
+ viewName.getQualifiedNameObj().getCatalogName());
+ bindWA->setDefaultSchema(s);
+ defSchWasChanged = TRUE;
+ }
+
// set a flag for overrride_schema
//if (overrideSchemaEnabled())
bindWA->getCurrentScope()->setInViewExpansion(TRUE);
@@ -2077,6 +2090,10 @@ RelExpr *BindWA::bindView(const CorrName &viewName,
if (NOT viewTree) {
bindWA->setErrStatus();
+
+ if (defSchWasChanged)
+ bindWA->setDefaultSchema(savedSch);
+
return NULL;
}
@@ -2150,14 +2167,17 @@ RelExpr *BindWA::bindView(const CorrName &viewName,
queryTree = queryTree->bindNode(bindWA);
if (bindWA->errStatus())
- return NULL;
+ {
+ if (defSchWasChanged)
+ bindWA->setDefaultSchema(savedSch);
+
+ return NULL;
+ }
+
bindWA->setNameLocListPtr(saveNameLocList);
bindWA->viewCount()--;
- if (bindWA->errStatus())
- return NULL;
-
// if RelRoot has an order by, insert a Logical Sort node below it
// and move the order by expr from view root to this sort node.
// The view root node is eliminated during transformation/normalization
@@ -2315,8 +2335,10 @@ RelExpr *BindWA::bindView(const CorrName &viewName,
bindWA->getUpdateToScanValueIds().clear();
// QSTUFF
- return queryTree;
+ if (defSchWasChanged)
+ bindWA->setDefaultSchema(savedSch);
+ return queryTree;
} // BindWA::bindView()
// -----------------------------------------------------------------------
[4/4] incubator-trafodion git commit: Merge [TRAFODION-2492] PR-976
Support for native hive views, plus few more changes
Posted by su...@apache.org.
Merge [TRAFODION-2492] PR-976 Support for native hive views, plus few more changes
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/549850a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/549850a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/549850a5
Branch: refs/heads/master
Commit: 549850a587aa3f7b7902be5a62a984c67815b093
Parents: b44e5d0 4c3077c
Author: Suresh Subbiah <su...@apache.org>
Authored: Thu Feb 23 17:19:31 2017 +0000
Committer: Suresh Subbiah <su...@apache.org>
Committed: Thu Feb 23 17:19:31 2017 +0000
----------------------------------------------------------------------
core/sql/bin/SqlciErrors.txt | 1 +
core/sql/cli/Statement.cpp | 7 +
core/sql/comexe/ComTdbExeUtil.h | 21 +-
core/sql/executor/ExExeUtil.h | 10 +-
core/sql/executor/ExExeUtilGet.cpp | 203 +-
core/sql/executor/ExHdfsScan.cpp | 11 +-
core/sql/executor/hiveHook.cpp | 66 +-
core/sql/generator/GenRelExeUtil.cpp | 62 +-
core/sql/generator/GenRelScan.cpp | 2 +-
core/sql/optimizer/BindRelExpr.cpp | 34 +-
core/sql/optimizer/NATable.cpp | 4860 +++++++++++++-------------
core/sql/optimizer/NATable.h | 14 +-
core/sql/optimizer/hiveHook.h | 24 +-
core/sql/parser/SqlParserAux.cpp | 5 +
core/sql/parser/SqlParserAux.h | 1 +
core/sql/parser/StmtDDLNode.cpp | 1 +
core/sql/parser/StmtDDLNode.h | 10 +
core/sql/parser/sqlparser.y | 14 +
core/sql/regress/hive/EXPECTED007 | 334 +-
core/sql/regress/hive/TEST007 | 153 +-
core/sql/regress/seabase/EXPECTED002 | 118 +-
core/sql/regress/tools/runallsb | 20 +
core/sql/sqlcomp/CmpDescribe.cpp | 92 +-
core/sql/sqlcomp/CmpSeabaseDDLmd.h | 8 +-
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 26 +-
core/sql/sqlcomp/CmpSeabaseDDLview.cpp | 6 +-
core/sql/ustat/hs_la.cpp | 19 +-
27 files changed, 3540 insertions(+), 2582 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/549850a5/core/sql/comexe/ComTdbExeUtil.h
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/549850a5/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/549850a5/core/sql/generator/GenRelExeUtil.cpp
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/549850a5/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
[2/4] incubator-trafodion git commit: TRAFODION-2492 Support for
native hive views, plus few more changes
Posted by su...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4c3077ce/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index 0918b6e..0e4bd31 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -4848,6 +4848,7 @@ NABoolean createNAFileSets(TrafDesc * table_desc /*IN*/,
viewTextCharSet_(CharInfo::UnknownCharSet),
viewCheck_(NULL),
viewColUsages_(NULL),
+ hiveOrigViewText_(NULL),
flags_(IS_INSERTABLE | IS_UPDATABLE),
insertMode_(COM_REGULAR_TABLE_INSERT_MODE),
isSynonymTranslationDone_(FALSE),
@@ -4963,36 +4964,36 @@ NABoolean createNAFileSets(TrafDesc * table_desc /*IN*/,
// Check if the synonym name translation to reference object has been done.
if (table_desc->tableDesc()->isSynonymTranslationDone())
- {
- isSynonymTranslationDone_ = TRUE;
- NAString synonymReferenceName(table_desc->tableDesc()->tablename);
- synonymReferenceName_ = synonymReferenceName;
- ComUID uid(table_desc->tableDesc()->objectUID);
- synonymReferenceObjectUid_ = uid;
- }
+ {
+ isSynonymTranslationDone_ = TRUE;
+ NAString synonymReferenceName(table_desc->tableDesc()->tablename);
+ synonymReferenceName_ = synonymReferenceName;
+ ComUID uid(table_desc->tableDesc()->objectUID);
+ synonymReferenceObjectUid_ = uid;
+ }
// Check if it is a UMD table, or SMD table or MV related UMD object
// and set cll correcsponding flags to indicate this.
if (table_desc->tableDesc()->isUMDTable())
- {
- isUMDTable_ = TRUE;
- }
+ {
+ isUMDTable_ = TRUE;
+ }
if (table_desc->tableDesc()->isSystemTableCode())
- {
- isSMDTable_ = TRUE;
- }
+ {
+ isSMDTable_ = TRUE;
+ }
if (table_desc->tableDesc()->isMVMetadataObject())
- {
- isMVUMDTable_ = TRUE;
- }
+ {
+ isMVUMDTable_ = TRUE;
+ }
isTrigTempTable_ = (qualifiedName_.getSpecialType() == ExtendedQualName::TRIGTEMP_TABLE);
if (table_desc->tableDesc()->isVolatileTable())
- {
- setVolatileTable( TRUE );
- }
+ {
+ setVolatileTable( TRUE );
+ }
switch(table_desc->tableDesc()->rowFormat())
{
@@ -5008,541 +5009,546 @@ NABoolean createNAFileSets(TrafDesc * table_desc /*IN*/,
}
if (table_desc->tableDesc()->isInMemoryObject())
- {
- setInMemoryObjectDefn( TRUE );
- }
+ {
+ setInMemoryObjectDefn( TRUE );
+ }
if (table_desc->tableDesc()->isDroppable())
- {
- setDroppableTable( TRUE );
- }
+ {
+ setDroppableTable( TRUE );
+ }
if (corrName.isExternal())
- {
- setIsExternalTable(TRUE);
- }
+ {
+ setIsExternalTable(TRUE);
+ }
if (qualifiedName_.getQualifiedNameObj().isHistograms() ||
qualifiedName_.getQualifiedNameObj().isHistogramIntervals())
- {
- setIsHistogramTable(TRUE);
- }
+ {
+ setIsHistogramTable(TRUE);
+ }
- insertMode_ = table_desc->tableDesc()->insertMode();
+ insertMode_ = table_desc->tableDesc()->insertMode();
- setRecordLength(table_desc->tableDesc()->record_length);
- //
- // Add timestamp information.
- //
- createTime_ = table_desc->tableDesc()->createTime;
- redefTime_ = table_desc->tableDesc()->redefTime;
- cacheTime_ = table_desc->tableDesc()->cacheTime;
+ setRecordLength(table_desc->tableDesc()->record_length);
+ //
+ // Add timestamp information.
+ //
+ createTime_ = table_desc->tableDesc()->createTime;
+ redefTime_ = table_desc->tableDesc()->redefTime;
+ cacheTime_ = table_desc->tableDesc()->cacheTime;
- catalogUID_ = table_desc->tableDesc()->catUID;
- schemaUID_ = table_desc->tableDesc()->schemaUID;
- objectUID_ = table_desc->tableDesc()->objectUID;
+ catalogUID_ = table_desc->tableDesc()->catUID;
+ schemaUID_ = table_desc->tableDesc()->schemaUID;
+ objectUID_ = table_desc->tableDesc()->objectUID;
- // Set the objectUID_ for hbase Cell and Row tables, if the table has
- // been defined in Trafodion use this value, otherwise, set to 0
- if (isHbaseCell_ || isHbaseRow_)
- {
- if ( !fetchObjectUIDForNativeTable(corrName) )
- return;
+ // Set the objectUID_ for hbase Cell and Row tables, if the table has
+ // been defined in Trafodion use this value, otherwise, set to 0
+ if (isHbaseCell_ || isHbaseRow_)
+ {
+ if ( !fetchObjectUIDForNativeTable(corrName) )
+ return;
- if (objectUID_ > 0 )
- setHasExternalTable(TRUE);
- }
+ if (objectUID_ > 0 )
+ setHasExternalTable(TRUE);
+ }
- if (table_desc->tableDesc()->owner)
- {
- Int32 userInfo (table_desc->tableDesc()->owner);
- owner_ = userInfo;
- }
- if (table_desc->tableDesc()->schemaOwner)
- {
- Int32 schemaUser(table_desc->tableDesc()->schemaOwner);
- schemaOwner_ = schemaUser;
- }
+ if (table_desc->tableDesc()->owner)
+ {
+ Int32 userInfo (table_desc->tableDesc()->owner);
+ owner_ = userInfo;
+ }
+ if (table_desc->tableDesc()->schemaOwner)
+ {
+ Int32 schemaUser(table_desc->tableDesc()->schemaOwner);
+ schemaOwner_ = schemaUser;
+ }
- objectType_ = table_desc->tableDesc()->objectType();
- partitioningScheme_ = table_desc->tableDesc()->partitioningScheme();
+ objectType_ = table_desc->tableDesc()->objectType();
+ partitioningScheme_ = table_desc->tableDesc()->partitioningScheme();
- // Set up privs
- if ((corrName.getSpecialType() == ExtendedQualName::SG_TABLE) ||
- (!(corrName.isSeabaseMD() || corrName.isSpecialTable())))
+ // Set up privs
+ if ((corrName.getSpecialType() == ExtendedQualName::SG_TABLE) ||
+ (!(corrName.isSeabaseMD() || corrName.isSpecialTable())))
getPrivileges(table_desc->tableDesc()->priv_desc);
- if ((table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_EXTERNAL_HIVE) != 0 ||
- (table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_EXTERNAL_HBASE) != 0)
- setIsExternalTable(TRUE);
-
- if (CmpSeabaseDDL::isMDflagsSet
- (table_desc->tableDesc()->tablesFlags, MD_TABLES_HIVE_EXT_COL_ATTRS))
- setHiveExtColAttrs(TRUE);
- if (CmpSeabaseDDL::isMDflagsSet
- (table_desc->tableDesc()->tablesFlags, MD_TABLES_HIVE_EXT_KEY_ATTRS))
- setHiveExtKeyAttrs(TRUE);
+ if ((table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_EXTERNAL_HIVE) != 0 ||
+ (table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_EXTERNAL_HBASE) != 0)
+ {
+ setIsExternalTable(TRUE);
- if (table_desc->tableDesc()->snapshotName)
- {
- snapshotName_ =
- new(heap_) char[strlen(table_desc->tableDesc()->snapshotName) + 1];
- strcpy(snapshotName_, table_desc->tableDesc()->snapshotName);
- }
+ if (table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_IMPLICIT_EXTERNAL_HIVE)
+ setIsImplicitExternalTable(TRUE);
+ }
- if (table_desc->tableDesc()->default_col_fam)
- defaultColFam_ = table_desc->tableDesc()->default_col_fam;
+ if (CmpSeabaseDDL::isMDflagsSet
+ (table_desc->tableDesc()->tablesFlags, MD_TABLES_HIVE_EXT_COL_ATTRS))
+ setHiveExtColAttrs(TRUE);
+ if (CmpSeabaseDDL::isMDflagsSet
+ (table_desc->tableDesc()->tablesFlags, MD_TABLES_HIVE_EXT_KEY_ATTRS))
+ setHiveExtKeyAttrs(TRUE);
- if (table_desc->tableDesc()->all_col_fams)
- {
- // Space delimited col families.
+ if (table_desc->tableDesc()->snapshotName)
+ {
+ snapshotName_ =
+ new(heap_) char[strlen(table_desc->tableDesc()->snapshotName) + 1];
+ strcpy(snapshotName_, table_desc->tableDesc()->snapshotName);
+ }
- string buf; // Have a buffer string
- stringstream ss(table_desc->tableDesc()->all_col_fams); // Insert the string into a stream
+ if (table_desc->tableDesc()->default_col_fam)
+ defaultColFam_ = table_desc->tableDesc()->default_col_fam;
- while (ss >> buf)
- {
- allColFams_.insert(buf.c_str());
- }
- }
- else
- allColFams_.insert(defaultColFam_);
+ if (table_desc->tableDesc()->all_col_fams)
+ {
+ // Space delimited col families.
- TrafDesc * files_desc = table_desc->tableDesc()->files_desc;
+ string buf; // Have a buffer string
+ stringstream ss(table_desc->tableDesc()->all_col_fams); // Insert the string into a stream
- // Some objects don't have a file_desc set up (e.g. views)
- // Therefore, only setup the partnsDesc_ if this is a partitionable object
- if (files_desc)
- {
- if (files_desc->filesDesc()->partns_desc)
- partnsDesc_ = files_desc->filesDesc()->partns_desc;
- }
- else
- partnsDesc_ = NULL;
+ while (ss >> buf)
+ {
+ allColFams_.insert(buf.c_str());
+ }
+ }
+ else
+ allColFams_.insert(defaultColFam_);
- //
- // Insert a NAColumn in the colArray_ for this NATable for each
- // columns_desc from the ARK SMD. Returns TRUE if error creating NAColumns.
- //
- if (createNAColumns(table_desc->tableDesc()->columns_desc,
- this,
- colArray_ /*OUT*/,
- heap_))
- //coverity[leaked_storage]
- return; // colcount_ == 0 indicates an error
+ TrafDesc * files_desc = table_desc->tableDesc()->files_desc;
- //
- // Add view information, if this is a view
- //
- TrafDesc *view_desc = table_desc->tableDesc()->views_desc;
- if (view_desc)
- {
- viewText_ = new (heap_) char[strlen(view_desc->viewDesc()->viewtext) + 2];
- strcpy(viewText_, view_desc->viewDesc()->viewtext);
- strcat(viewText_, ";");
-
- viewTextCharSet_ = (CharInfo::CharSet)view_desc->viewDesc()->viewtextcharset;
-
- viewCheck_ = NULL; //initialize
- if(view_desc->viewDesc()->viewchecktext){
- UInt32 viewCheckLength = str_len(view_desc->viewDesc()->viewchecktext)+1;
- viewCheck_ = new (heap_) char[ viewCheckLength];
- memcpy(viewCheck_, view_desc->viewDesc()->viewchecktext,
- viewCheckLength);
- }
+ // Some objects don't have a file_desc set up (e.g. views)
+ // Therefore, only setup the partnsDesc_ if this is a partitionable object
+ if (files_desc)
+ {
+ if (files_desc->filesDesc()->partns_desc)
+ partnsDesc_ = files_desc->filesDesc()->partns_desc;
+ }
+ else
+ partnsDesc_ = NULL;
- viewColUsages_ = NULL;
- if(view_desc->viewDesc()->viewcolusages){
- viewColUsages_ = new (heap_) NAList<ComViewColUsage *>(heap_); //initialize empty list
- char * beginStr (view_desc->viewDesc()->viewcolusages);
- char * endStr = strchr(beginStr, ';');
- while (endStr != NULL) {
- ComViewColUsage *colUsage = new (heap_) ComViewColUsage;
- NAString currentUsage(beginStr, endStr - beginStr + 1);
- colUsage->unpackUsage (currentUsage.data());
- viewColUsages_->insert(colUsage);
- beginStr = endStr+1;
- endStr = strchr(beginStr, ';');
- }
- }
- setUpdatable(view_desc->viewDesc()->isUpdatable());
- setInsertable(view_desc->viewDesc()->isInsertable());
+ //
+ // Insert a NAColumn in the colArray_ for this NATable for each
+ // columns_desc from the ARK SMD. Returns TRUE if error creating NAColumns.
+ //
+ if (createNAColumns(table_desc->tableDesc()->columns_desc,
+ this,
+ colArray_ /*OUT*/,
+ heap_))
+ //coverity[leaked_storage]
+ return; // colcount_ == 0 indicates an error
- //
- // The updatable flag is false for an MP view only if it is NOT a
- // protection view. Therefore updatable == FALSE iff it is a
- // shorthand view. See ReadTableDef.cpp, l. 3379.
- //
+ //
+ // Add view information, if this is a view
+ //
+ TrafDesc *view_desc = table_desc->tableDesc()->views_desc;
+ if (view_desc)
+ {
+ viewText_ = new (heap_) char[strlen(view_desc->viewDesc()->viewtext) + 2];
+ strcpy(viewText_, view_desc->viewDesc()->viewtext);
+ strcat(viewText_, ";");
+
+ viewTextCharSet_ = (CharInfo::CharSet)view_desc->viewDesc()->viewtextcharset;
+
+ viewCheck_ = NULL; //initialize
+ if(view_desc->viewDesc()->viewchecktext){
+ UInt32 viewCheckLength = str_len(view_desc->viewDesc()->viewchecktext)+1;
+ viewCheck_ = new (heap_) char[ viewCheckLength];
+ memcpy(viewCheck_, view_desc->viewDesc()->viewchecktext,
+ viewCheckLength);
+ }
- viewFileName_ = NULL;
- CMPASSERT(view_desc->viewDesc()->viewfilename);
- UInt32 viewFileNameLength = str_len(view_desc->viewDesc()->viewfilename) + 1;
- viewFileName_ = new (heap_) char[viewFileNameLength];
- memcpy(viewFileName_, view_desc->viewDesc()->viewfilename,
- viewFileNameLength);
- }
- else
- {
- //keep track of memory used by NAFileSets
- Lng32 preCreateNAFileSetsMemSize = heap_->getAllocSize();
+ viewColUsages_ = NULL;
+ if(view_desc->viewDesc()->viewcolusages){
+ viewColUsages_ = new (heap_) NAList<ComViewColUsage *>(heap_); //initialize empty list
+ char * beginStr (view_desc->viewDesc()->viewcolusages);
+ char * endStr = strchr(beginStr, ';');
+ while (endStr != NULL) {
+ ComViewColUsage *colUsage = new (heap_) ComViewColUsage;
+ NAString currentUsage(beginStr, endStr - beginStr + 1);
+ colUsage->unpackUsage (currentUsage.data());
+ viewColUsages_->insert(colUsage);
+ beginStr = endStr+1;
+ endStr = strchr(beginStr, ';');
+ }
+ }
+ setUpdatable(view_desc->viewDesc()->isUpdatable());
+ setInsertable(view_desc->viewDesc()->isInsertable());
- //
- // Process indexes and vertical partitions for this table.
- //
- if (createNAFileSets(table_desc /*IN*/,
- this /*IN*/,
- colArray_ /*IN*/,
- indexes_ /*OUT*/,
- vertParts_ /*OUT*/,
- clusteringIndex_ /*OUT*/,
- tableIdList_ /*OUT*/,
- heap_,
- bindWA,
- newColumns_, /*OUT*/
- maxIndexLevelsPtr)) {
- return; // colcount_ == 0 indicates an error
- }
+ //
+ // The updatable flag is false for an MP view only if it is NOT a
+ // protection view. Therefore updatable == FALSE iff it is a
+ // shorthand view. See ReadTableDef.cpp, l. 3379.
+ //
- // Add constraint info.
- //
- // This call to createConstraintInfo, calls the parser on
- // the constraint name
- //
+ viewFileName_ = NULL;
+ CMPASSERT(view_desc->viewDesc()->viewfilename);
+ UInt32 viewFileNameLength = str_len(view_desc->viewDesc()->viewfilename) + 1;
+ viewFileName_ = new (heap_) char[viewFileNameLength];
+ memcpy(viewFileName_, view_desc->viewDesc()->viewfilename,
+ viewFileNameLength);
+ }
+ else
+ {
+ //keep track of memory used by NAFileSets
+ Lng32 preCreateNAFileSetsMemSize = heap_->getAllocSize();
- NABoolean errorOccurred =
- createConstraintInfo(table_desc /*IN*/,
- getTableName() /*IN*/,
- getNAColumnArray()/*IN (some columns updated)*/,
- checkConstraints_ /*OUT*/,
- uniqueConstraints_/*OUT*/,
- refConstraints_ /*OUT*/,
- heap_,
- bindWA);
-
- if (errorOccurred) {
- // return before setting colcount_, indicating that there
- // was an error in constructing this NATable.
- //
- return;
- }
+ //
+ // Process indexes and vertical partitions for this table.
+ //
+ if (createNAFileSets(table_desc /*IN*/,
+ this /*IN*/,
+ colArray_ /*IN*/,
+ indexes_ /*OUT*/,
+ vertParts_ /*OUT*/,
+ clusteringIndex_ /*OUT*/,
+ tableIdList_ /*OUT*/,
+ heap_,
+ bindWA,
+ newColumns_, /*OUT*/
+ maxIndexLevelsPtr)) {
+ return; // colcount_ == 0 indicates an error
+ }
- //
- // FetchHistograms call used to be here -- moved to getStatistics().
- //
- }
+ // Add constraint info.
+ //
+ // This call to createConstraintInfo, calls the parser on
+ // the constraint name
+ //
- // change partFunc for base table if PARTITION clause has been used
- // to limit the number of partitions that will be accessed.
- if ((qualifiedName_.isPartitionNameSpecified()) ||
- (qualifiedName_.isPartitionRangeSpecified())) {
- if (filterUnusedPartitions(corrName.getPartnClause())) {
- return ;
- }
- }
+ NABoolean errorOccurred =
+ createConstraintInfo(table_desc /*IN*/,
+ getTableName() /*IN*/,
+ getNAColumnArray()/*IN (some columns updated)*/,
+ checkConstraints_ /*OUT*/,
+ uniqueConstraints_/*OUT*/,
+ refConstraints_ /*OUT*/,
+ heap_,
+ bindWA);
+
+ if (errorOccurred) {
+ // return before setting colcount_, indicating that there
+ // was an error in constructing this NATable.
+ //
+ return;
+ }
- //
- // Set colcount_ after all possible errors (Binder uses nonzero colcount
- // as an indicator of valid table definition).
- //
- CMPASSERT(table_desc->tableDesc()->colcount >= 0); // CollIndex cast ok?
- colcount_ = (CollIndex)table_desc->tableDesc()->colcount;
+ //
+ // FetchHistograms call used to be here -- moved to getStatistics().
+ //
+ }
- // If there is a host variable associated with this table, store it
- // for use by the generator to generate late-name resolution information.
- //
- HostVar *hv = corrName.getPrototype();
- prototype_ = hv ? new (heap_) HostVar(*hv) : NULL;
+ // change partFunc for base table if PARTITION clause has been used
+ // to limit the number of partitions that will be accessed.
+ if ((qualifiedName_.isPartitionNameSpecified()) ||
+ (qualifiedName_.isPartitionRangeSpecified())) {
+ if (filterUnusedPartitions(corrName.getPartnClause())) {
+ return ;
+ }
+ }
- // MV
- // Initialize the MV support data members
- isAnMV_ = table_desc->tableDesc()->isMVTable();
- isAnMVMetaData_ = table_desc->tableDesc()->isMVMetadataObject();
- mvAttributeBitmap_.initBitmap(table_desc->tableDesc()->mvAttributesBitmap);
+ //
+ // Set colcount_ after all possible errors (Binder uses nonzero colcount
+ // as an indicator of valid table definition).
+ //
+ CMPASSERT(table_desc->tableDesc()->colcount >= 0); // CollIndex cast ok?
+ colcount_ = (CollIndex)table_desc->tableDesc()->colcount;
- TrafDesc *mvs_desc = NULL; // using mvs not set or returned for traf tables
- // Memory Leak
- while (mvs_desc)
- {
- TrafUsingMvDesc* mv = mvs_desc->usingMvDesc();
+ // If there is a host variable associated with this table, store it
+ // for use by the generator to generate late-name resolution information.
+ //
+ HostVar *hv = corrName.getPrototype();
+ prototype_ = hv ? new (heap_) HostVar(*hv) : NULL;
+
+ // MV
+ // Initialize the MV support data members
+ isAnMV_ = table_desc->tableDesc()->isMVTable();
+ isAnMVMetaData_ = table_desc->tableDesc()->isMVMetadataObject();
+ mvAttributeBitmap_.initBitmap(table_desc->tableDesc()->mvAttributesBitmap);
+
+ TrafDesc *mvs_desc = NULL; // using mvs not set or returned for traf tables
+ // Memory Leak
+ while (mvs_desc)
+ {
+ TrafUsingMvDesc* mv = mvs_desc->usingMvDesc();
- UsingMvInfo *usingMv = new(heap_)
- UsingMvInfo(mv->mvName, mv->refreshType(), mv->rewriteEnabled,
- mv->isInitialized, heap_);
- mvsUsingMe_.insert(usingMv);
+ UsingMvInfo *usingMv = new(heap_)
+ UsingMvInfo(mv->mvName, mv->refreshType(), mv->rewriteEnabled,
+ mv->isInitialized, heap_);
+ mvsUsingMe_.insert(usingMv);
- mvs_desc = mvs_desc->next;
- }
+ mvs_desc = mvs_desc->next;
+ }
- // ++MV
+ // ++MV
- // fix the special-type for MV objects. There are case where the type is
- // set to NORMAL_TABLE although this is an MV.
- //
- // Example:
- // --------
- // in the statement "select * from MV1" mv1 will have a NORMAL_TABLE
- // special-type, while in "select * from table(mv_table MV1)" it will
- // have the MV_TABLE special-type.
+ // fix the special-type for MV objects. There are case where the type is
+ // set to NORMAL_TABLE although this is an MV.
+ //
+ // Example:
+ // --------
+ // in the statement "select * from MV1" mv1 will have a NORMAL_TABLE
+ // special-type, while in "select * from table(mv_table MV1)" it will
+ // have the MV_TABLE special-type.
- if (isAnMV_)
- {
- switch(qualifiedName_.getSpecialType())
- {
- case ExtendedQualName::GHOST_TABLE:
- qualifiedName_.setSpecialType(ExtendedQualName::GHOST_MV_TABLE);
- break;
- case ExtendedQualName::GHOST_MV_TABLE:
- // Do not change it
- break;
- default:
- qualifiedName_.setSpecialType(ExtendedQualName::MV_TABLE);
- break;
- }
- }
+ if (isAnMV_)
+ {
+ switch(qualifiedName_.getSpecialType())
+ {
+ case ExtendedQualName::GHOST_TABLE:
+ qualifiedName_.setSpecialType(ExtendedQualName::GHOST_MV_TABLE);
+ break;
+ case ExtendedQualName::GHOST_MV_TABLE:
+ // Do not change it
+ break;
+ default:
+ qualifiedName_.setSpecialType(ExtendedQualName::MV_TABLE);
+ break;
+ }
+ }
- // --MV
+ // --MV
- // Initialize the sequence generator fields
- TrafDesc *sequence_desc = table_desc->tableDesc()->sequence_generator_desc;
- if (sequence_desc != NULL) {
- TrafSequenceGeneratorDesc *sg_desc = sequence_desc->sequenceGeneratorDesc();
+ // Initialize the sequence generator fields
+ TrafDesc *sequence_desc = table_desc->tableDesc()->sequence_generator_desc;
+ if (sequence_desc != NULL) {
+ TrafSequenceGeneratorDesc *sg_desc = sequence_desc->sequenceGeneratorDesc();
- if (sg_desc != NULL)
- {
- sgAttributes_ =
- new(heap_) SequenceGeneratorAttributes(
- sg_desc->startValue,
- sg_desc->increment,
- sg_desc->maxValue,
- sg_desc->minValue,
- sg_desc->sgType(),
- (ComSQLDataType)sg_desc->sqlDataType,
- (ComFSDataType)sg_desc->fsDataType,
- sg_desc->cycleOption,
- FALSE,
- sg_desc->objectUID,
- sg_desc->cache,
- sg_desc->nextValue,
- 0,
- sg_desc->redefTime);
- }
- }
+ if (sg_desc != NULL)
+ {
+ sgAttributes_ =
+ new(heap_) SequenceGeneratorAttributes(
+ sg_desc->startValue,
+ sg_desc->increment,
+ sg_desc->maxValue,
+ sg_desc->minValue,
+ sg_desc->sgType(),
+ (ComSQLDataType)sg_desc->sqlDataType,
+ (ComFSDataType)sg_desc->fsDataType,
+ sg_desc->cycleOption,
+ FALSE,
+ sg_desc->objectUID,
+ sg_desc->cache,
+ sg_desc->nextValue,
+ 0,
+ sg_desc->redefTime);
+ }
+ }
#ifndef NDEBUG
- if (getenv("NATABLE_DEBUG"))
- {
- cout << "NATable " << (void*)this << " "
- << qualifiedName_.getQualifiedNameObj().getQualifiedNameAsAnsiString() << " "
- << (Int32)qualifiedName_.getSpecialType() << endl;
- colArray_.print();
- }
+ if (getenv("NATABLE_DEBUG"))
+ {
+ cout << "NATable " << (void*)this << " "
+ << qualifiedName_.getQualifiedNameObj().getQualifiedNameAsAnsiString() << " "
+ << (Int32)qualifiedName_.getSpecialType() << endl;
+ colArray_.print();
+ }
#endif
- //this guy is cacheable
- if((qualifiedName_.isCacheable())&&
- (NOT (isHbaseTable())) &&
- //this object is not on the statement heap (i.e. it is being cached)
- ((heap_ != CmpCommon::statementHeap())||
- (OSIM_runningInCaptureMode())))
- {
- char * nodeName = NULL;
- char * catStr = NULL;
- char * schemaStr = NULL;
- char * fileStr = NULL;
- short nodeNameLen = 0;
- Int32 catStrLen = 0;
- Int32 schemaStrLen = 0;
- Int32 fileStrLen = 0;
+ //this guy is cacheable
+ if((qualifiedName_.isCacheable())&&
+ (NOT (isHbaseTable())) &&
+ //this object is not on the statement heap (i.e. it is being cached)
+ ((heap_ != CmpCommon::statementHeap())||
+ (OSIM_runningInCaptureMode())))
+ {
+ char * nodeName = NULL;
+ char * catStr = NULL;
+ char * schemaStr = NULL;
+ char * fileStr = NULL;
+ short nodeNameLen = 0;
+ Int32 catStrLen = 0;
+ Int32 schemaStrLen = 0;
+ Int32 fileStrLen = 0;
#ifdef NA_64BIT
- // dg64 - match signature
- int_32 primaryNodeNum=0;
+ // dg64 - match signature
+ int_32 primaryNodeNum=0;
#else
- Int32 primaryNodeNum=0;
+ Int32 primaryNodeNum=0;
#endif
- short error = 0;
+ short error = 0;
- //clusteringIndex has physical filename that can be used to check
- //if a catalog operation has been performed on a table.
- //Views don't have clusteringIndex, so we get physical filename
- //from the viewFileName_ datamember.
- if(viewText_)
- {
- //view filename starts with node name
- //filename is in format \<node_name>.$<volume>.<subvolume>.<file>
- //catStr => <volume>
- //schemaStr => <subvolume>
- //fileStr => <file>
- nodeName = viewFileName_;
- catStr = nodeName;
-
- //skip over node name
- //measure node name length
- //get to begining of volume name
- //Measure length of node name
- //skip over node name i.e. \MAYA, \AZTEC, etc
- //and get to volume name
- while((nodeName[nodeNameLen]!='.')&&
- (nodeNameLen < 8)){
- catStr++;
- nodeNameLen++;
- };
-
- //skip over '.' and the '$' in volume name
- catStr=&nodeName[nodeNameLen+2];
- schemaStr=catStr;
-
- //skip over the volume/catalog name
- //while measuring catalog name length
- while((catStr[catStrLen]!='.')&&
- (catStrLen < 8))
- {
- schemaStr++;
- catStrLen++;
- }
-
- //skip over the '.'
- schemaStr++;
- fileStr=schemaStr;
-
- //skip over the subvolume/schema name
- //while measuring schema name length
- while((schemaStr[schemaStrLen]!='.')&&
- (schemaStrLen < 8))
- {
- fileStr++;
- schemaStrLen++;
- }
-
- //skip over the '.'
- fileStr++;
- fileStrLen = str_len(fileStr);
-
- //figure out the node number for the node
- //which has the primary partition.
- primaryNodeNum=0;
-
- if(!OSIM_runningSimulation())
- primaryNodeNum = gpClusterInfo->mapNodeNameToNodeNum(NAString(nodeName));
- }
- else{
- //get qualified name of the clustering index which should
- //be the actual physical file name of the table
- const QualifiedName fileNameObj = getClusteringIndex()->
- getRandomPartition();
- const NAString fileName = fileNameObj.getObjectName();
-
- //get schemaName object
- const SchemaName schemaNameObj = fileNameObj.getSchemaName();
- const NAString schemaName = schemaNameObj.getSchemaName();
-
- //get catalogName object
- //this contains a string in the form \<node_name>.$volume
- const CatalogName catalogNameObj = fileNameObj.getCatalogName();
- const NAString catalogName = catalogNameObj.getCatalogName();
- nodeName = (char*) catalogName.data();
- catStr = nodeName;
-
- //Measure length of node name
- //skip over node name i.e. \MAYA, \AZTEC, etc
- //and get to volume name
- while((nodeName[nodeNameLen]!='.')&&
- (nodeNameLen < 8)){
- catStr++;
- nodeNameLen++;
- };
-
- //get volume/catalog name
- //skip ".$"
- catStr=&nodeName[nodeNameLen+2];
+ //clusteringIndex has physical filename that can be used to check
+ //if a catalog operation has been performed on a table.
+ //Views don't have clusteringIndex, so we get physical filename
+ //from the viewFileName_ datamember.
+ if(viewText_)
+ {
+ //view filename starts with node name
+ //filename is in format \<node_name>.$<volume>.<subvolume>.<file>
+ //catStr => <volume>
+ //schemaStr => <subvolume>
+ //fileStr => <file>
+ nodeName = viewFileName_;
+ catStr = nodeName;
+
+ //skip over node name
+ //measure node name length
+ //get to begining of volume name
+ //Measure length of node name
+ //skip over node name i.e. \MAYA, \AZTEC, etc
+ //and get to volume name
+ while((nodeName[nodeNameLen]!='.')&&
+ (nodeNameLen < 8)){
+ catStr++;
+ nodeNameLen++;
+ };
+
+ //skip over '.' and the '$' in volume name
+ catStr=&nodeName[nodeNameLen+2];
+ schemaStr=catStr;
+
+ //skip over the volume/catalog name
+ //while measuring catalog name length
+ while((catStr[catStrLen]!='.')&&
+ (catStrLen < 8))
+ {
+ schemaStr++;
+ catStrLen++;
+ }
+
+ //skip over the '.'
+ schemaStr++;
+ fileStr=schemaStr;
+
+ //skip over the subvolume/schema name
+ //while measuring schema name length
+ while((schemaStr[schemaStrLen]!='.')&&
+ (schemaStrLen < 8))
+ {
+ fileStr++;
+ schemaStrLen++;
+ }
+
+ //skip over the '.'
+ fileStr++;
+ fileStrLen = str_len(fileStr);
+
+ //figure out the node number for the node
+ //which has the primary partition.
+ primaryNodeNum=0;
+
+ if(!OSIM_runningSimulation())
+ primaryNodeNum = gpClusterInfo->mapNodeNameToNodeNum(NAString(nodeName));
+ }
+ else{
+ //get qualified name of the clustering index which should
+ //be the actual physical file name of the table
+ const QualifiedName fileNameObj = getClusteringIndex()->
+ getRandomPartition();
+ const NAString fileName = fileNameObj.getObjectName();
+
+ //get schemaName object
+ const SchemaName schemaNameObj = fileNameObj.getSchemaName();
+ const NAString schemaName = schemaNameObj.getSchemaName();
+
+ //get catalogName object
+ //this contains a string in the form \<node_name>.$volume
+ const CatalogName catalogNameObj = fileNameObj.getCatalogName();
+ const NAString catalogName = catalogNameObj.getCatalogName();
+ nodeName = (char*) catalogName.data();
+ catStr = nodeName;
+
+ //Measure length of node name
+ //skip over node name i.e. \MAYA, \AZTEC, etc
+ //and get to volume name
+ while((nodeName[nodeNameLen]!='.')&&
+ (nodeNameLen < 8)){
+ catStr++;
+ nodeNameLen++;
+ };
+
+ //get volume/catalog name
+ //skip ".$"
+ catStr=&nodeName[nodeNameLen+2];
#pragma nowarn(1506) // warning elimination
- catStrLen = catalogName.length() - (nodeNameLen+2);
+ catStrLen = catalogName.length() - (nodeNameLen+2);
#pragma warn(1506) // warning elimination
- //get subvolume/schema name
- schemaStr = (char *) schemaName.data();
+ //get subvolume/schema name
+ schemaStr = (char *) schemaName.data();
#pragma nowarn(1506) // warning elimination
- schemaStrLen = schemaName.length();
+ schemaStrLen = schemaName.length();
#pragma warn(1506) // warning elimination
- //get file name
- fileStr = (char *) fileName.data();
+ //get file name
+ fileStr = (char *) fileName.data();
#pragma nowarn(1506) // warning elimination
- fileStrLen = fileName.length();
+ fileStrLen = fileName.length();
#pragma warn(1506) // warning elimination
- //figure out the node number for the node
- //which has the primary partition.
- primaryNodeNum=0;
+ //figure out the node number for the node
+ //which has the primary partition.
+ primaryNodeNum=0;
- primaryNodeNum = gpClusterInfo->mapNodeNameToNodeNum(NAString(nodeName));
+ primaryNodeNum = gpClusterInfo->mapNodeNameToNodeNum(NAString(nodeName));
- }
- }
+ }
+ }
- Lng32 postCreateNATableWarnings = CmpCommon::diags()->getNumber(DgSqlCode::WARNING_);
+ Lng32 postCreateNATableWarnings = CmpCommon::diags()->getNumber(DgSqlCode::WARNING_);
- if(postCreateNATableWarnings != preCreateNATableWarnings)
- tableConstructionHadWarnings_=TRUE;
- const char *lobHdfsServer = CmpCommon::getDefaultString(LOB_HDFS_SERVER);
- Int32 lobHdfsPort = (Lng32)CmpCommon::getDefaultNumeric(LOB_HDFS_PORT);
- if (hasLobColumn())
- {
- // read lob related information from lob metadata
- // setFromStoredDesc(TRUE);
- //
- short *lobNumList = new (heap_) short[getColumnCount()];
- short *lobTypList = new (heap_) short[getColumnCount()];
- char **lobLocList = new (heap_) char*[getColumnCount()];
- char **lobColNameList = new (heap_) char*[getColumnCount()];
- const NAColumnArray &colArray = getNAColumnArray();
- NAColumn *nac = NULL;
-
- Lng32 j = 0;
- for (CollIndex i = 0; i < getColumnCount(); i++)
- {
- nac = colArray.getColumn(i);
-
- if (nac->getType()->getTypeQualifier() == NA_LOB_TYPE)
- {
- lobLocList[j] = new (heap_) char[1024];
- lobColNameList[j] = new (heap_)char[256];
- j++;
- }
- }
-
- NAString schNam;
- schNam = "\"";
- schNam += getTableName().getCatalogName();
- schNam += "\".\"";
- schNam += getTableName().getSchemaName();
- schNam += "\"";
-
- Lng32 numLobs = 0;
- Lng32 cliRC = SQL_EXEC_LOBddlInterface
- (
- (char*)schNam.data(),
- schNam.length(),
- objectUid().castToInt64(),
- numLobs,
- LOB_CLI_SELECT_CURSOR,
- lobNumList,
- lobTypList,
- lobLocList,lobColNameList,(char *)lobHdfsServer,lobHdfsPort,0,FALSE);
-
- if (cliRC == 0)
- {
- for (Lng32 i = 0; i < numLobs; i++)
- {
- nac = colArray.getColumn(lobNumList[i]);
+ if(postCreateNATableWarnings != preCreateNATableWarnings)
+ tableConstructionHadWarnings_=TRUE;
+ const char *lobHdfsServer = CmpCommon::getDefaultString(LOB_HDFS_SERVER);
+ Int32 lobHdfsPort = (Lng32)CmpCommon::getDefaultNumeric(LOB_HDFS_PORT);
+ if (hasLobColumn())
+ {
+ // read lob related information from lob metadata
+ // setFromStoredDesc(TRUE);
+ //
+ short *lobNumList = new (heap_) short[getColumnCount()];
+ short *lobTypList = new (heap_) short[getColumnCount()];
+ char **lobLocList = new (heap_) char*[getColumnCount()];
+ char **lobColNameList = new (heap_) char*[getColumnCount()];
+ const NAColumnArray &colArray = getNAColumnArray();
+ NAColumn *nac = NULL;
+
+ Lng32 j = 0;
+ for (CollIndex i = 0; i < getColumnCount(); i++)
+ {
+ nac = colArray.getColumn(i);
- nac->lobNum() = lobNumList[i];
- nac->lobStorageType() = (LobsStorage)lobTypList[i];
- nac->lobStorageLocation() = lobLocList[i];
- }
- } // if
- } // if
+ if (nac->getType()->getTypeQualifier() == NA_LOB_TYPE)
+ {
+ lobLocList[j] = new (heap_) char[1024];
+ lobColNameList[j] = new (heap_)char[256];
+ j++;
+ }
+ }
+
+ NAString schNam;
+ schNam = "\"";
+ schNam += getTableName().getCatalogName();
+ schNam += "\".\"";
+ schNam += getTableName().getSchemaName();
+ schNam += "\"";
+
+ Lng32 numLobs = 0;
+ Lng32 cliRC = SQL_EXEC_LOBddlInterface
+ (
+ (char*)schNam.data(),
+ schNam.length(),
+ objectUid().castToInt64(),
+ numLobs,
+ LOB_CLI_SELECT_CURSOR,
+ lobNumList,
+ lobTypList,
+ lobLocList,lobColNameList,(char *)lobHdfsServer,lobHdfsPort,0,FALSE);
+
+ if (cliRC == 0)
+ {
+ for (Lng32 i = 0; i < numLobs; i++)
+ {
+ nac = colArray.getColumn(lobNumList[i]);
- // LCOV_EXCL_STOP
- initialSize_ = heap_->getAllocSize();
- MonitorMemoryUsage_Exit((char*)mmPhase.data(), heap_, NULL, TRUE);
+ nac->lobNum() = lobNumList[i];
+ nac->lobStorageType() = (LobsStorage)lobTypList[i];
+ nac->lobStorageLocation() = lobLocList[i];
+ }
+ } // if
+ } // if
+
+ // LCOV_EXCL_STOP
+ initialSize_ = heap_->getAllocSize();
+ MonitorMemoryUsage_Exit((char*)mmPhase.data(), heap_, NULL, TRUE);
} // NATable()
#pragma warn(770) // warning elimination
@@ -5552,810 +5558,852 @@ NATable::NATable(BindWA *bindWA,
const CorrName& corrName,
NAMemory *heap,
struct hive_tbl_desc* htbl)
- //
- // The NATable heap ( i.e. heap_ ) used to come from ContextHeap
- // (i.e. heap) but it creates high memory usage/leakage in Context
- // Heap. Although the NATables are deleted at the end of each statement,
- // the heap_ is returned to heap (i.e. context heap) which caused
- // context heap containing a lot of not used chunk of memory. So it is
- // changed to be from whatever heap is passed in at the call in
- // NATableDB.getNATable.
- //
- // Now NATable objects can be cached.If an object is to be cached (persisted
- // across statements) a NATable heap is allocated for the object
- // and is passed in (this is done in NATableDB::get(CorrName& corrName...).
- // Otherwise a reference to the Statement heap is passed in. When a cached
- // object is to be deleted the object's heap is deleted which wipes out the
- // NATable object all its related stuff. NATable objects that are not cached
- // are wiped out at the end of the statement when the statement heap is deleted.
- //
- : heap_(heap),
- referenceCount_(0),
- refsIncompatibleDP2Halloween_(FALSE),
- isHalloweenTable_(FALSE),
- qualifiedName_(corrName.getExtendedQualNameObj(),heap),
- synonymReferenceName_(heap),
- fileSetName_(corrName.getQualifiedNameObj(),heap), // for now, set equal
- clusteringIndex_(NULL),
- colcount_(0),
- colArray_(heap),
- recordLength_(0),
- indexes_(heap),
- vertParts_(heap),
- colStats_(NULL),
- statsFetched_(FALSE),
- viewFileName_(NULL),
- viewText_(NULL),
- viewTextInNAWchars_(heap),
- viewTextCharSet_(CharInfo::UnknownCharSet),
- viewCheck_(NULL),
- viewColUsages_(NULL),
- flags_(IS_INSERTABLE | IS_UPDATABLE),
- insertMode_(COM_REGULAR_TABLE_INSERT_MODE),
- isSynonymTranslationDone_(FALSE),
- checkConstraints_(heap),
- createTime_(htbl->creationTS_),
- redefTime_(htbl->redeftime()),
- cacheTime_(0),
- statsTime_(0),
- catalogUID_(0),
- schemaUID_(0),
- objectUID_(0),
- objectType_(COM_UNKNOWN_OBJECT),
- partitioningScheme_(COM_UNKNOWN_PARTITIONING),
- uniqueConstraints_(heap),
- refConstraints_(heap),
- isAnMV_(FALSE),
- isAnMVMetaData_(FALSE),
- mvsUsingMe_(heap),
- mvInfo_(NULL),
- accessedInCurrentStatement_(TRUE),
- setupForStatement_(FALSE),
- resetAfterStatement_(FALSE),
- hitCount_(0),
- replacementCounter_(2),
- sizeInCache_(0),
- recentlyUsed_(TRUE),
- tableConstructionHadWarnings_(FALSE),
- isAnMPTableWithAnsiName_(FALSE),
- isUMDTable_(FALSE),
- isSMDTable_(FALSE),
- isMVUMDTable_(FALSE),
-
- // For virtual tables, we set the object schema version
- // to be the current schema version
- osv_(COM_VERS_CURR_SCHEMA),
- ofv_(COM_VERS_CURR_SCHEMA),
- partnsDesc_(NULL),
- colsWithMissingStats_(NULL),
- originalCardinality_(-1.0),
- tableIdList_(heap),
- rcb_(NULL),
- rcbLen_(0),
- keyLength_(0),
- parentTableName_(NULL),
- sgAttributes_(NULL),
- isHive_(TRUE),
- isHbase_(FALSE),
- isHbaseCell_(FALSE),
- isHbaseRow_(FALSE),
- isSeabase_(FALSE),
- isSeabaseMD_(FALSE),
- isSeabasePrivSchemaTable_(FALSE),
- isUserUpdatableSeabaseMD_(FALSE),
- resetHDFSStatsAfterStmt_(FALSE),
- hiveDefaultStringLen_(0),
- hiveTableId_(htbl->tblID_),
- tableDesc_(NULL),
- secKeySet_(heap),
- privInfo_(NULL),
- newColumns_(heap),
- snapshotName_(NULL),
- allColFams_(heap)
+ //
+ // The NATable heap ( i.e. heap_ ) used to come from ContextHeap
+ // (i.e. heap) but it creates high memory usage/leakage in Context
+ // Heap. Although the NATables are deleted at the end of each statement,
+ // the heap_ is returned to heap (i.e. context heap) which caused
+ // context heap containing a lot of not used chunk of memory. So it is
+ // changed to be from whatever heap is passed in at the call in
+ // NATableDB.getNATable.
+ //
+ // Now NATable objects can be cached.If an object is to be cached (persisted
+ // across statements) a NATable heap is allocated for the object
+ // and is passed in (this is done in NATableDB::get(CorrName& corrName...).
+ // Otherwise a reference to the Statement heap is passed in. When a cached
+ // object is to be deleted the object's heap is deleted which wipes out the
+ // NATable object all its related stuff. NATable objects that are not cached
+ // are wiped out at the end of the statement when the statement heap is deleted.
+ //
+ : heap_(heap),
+ referenceCount_(0),
+ refsIncompatibleDP2Halloween_(FALSE),
+ isHalloweenTable_(FALSE),
+ qualifiedName_(corrName.getExtendedQualNameObj(),heap),
+ synonymReferenceName_(heap),
+ fileSetName_(corrName.getQualifiedNameObj(),heap), // for now, set equal
+ clusteringIndex_(NULL),
+ colcount_(0),
+ colArray_(heap),
+ recordLength_(0),
+ indexes_(heap),
+ vertParts_(heap),
+ colStats_(NULL),
+ statsFetched_(FALSE),
+ viewFileName_(NULL),
+ viewText_(NULL),
+ viewTextInNAWchars_(heap),
+ viewTextCharSet_(CharInfo::UnknownCharSet),
+ viewCheck_(NULL),
+ viewColUsages_(NULL),
+ hiveOrigViewText_(NULL),
+ flags_(IS_INSERTABLE | IS_UPDATABLE),
+ insertMode_(COM_REGULAR_TABLE_INSERT_MODE),
+ isSynonymTranslationDone_(FALSE),
+ checkConstraints_(heap),
+ createTime_(htbl->creationTS_),
+ redefTime_(htbl->redeftime()),
+ cacheTime_(0),
+ statsTime_(0),
+ catalogUID_(0),
+ schemaUID_(0),
+ objectUID_(0),
+ objectType_(COM_UNKNOWN_OBJECT),
+ partitioningScheme_(COM_UNKNOWN_PARTITIONING),
+ uniqueConstraints_(heap),
+ refConstraints_(heap),
+ isAnMV_(FALSE),
+ isAnMVMetaData_(FALSE),
+ mvsUsingMe_(heap),
+ mvInfo_(NULL),
+ accessedInCurrentStatement_(TRUE),
+ setupForStatement_(FALSE),
+ resetAfterStatement_(FALSE),
+ hitCount_(0),
+ replacementCounter_(2),
+ sizeInCache_(0),
+ recentlyUsed_(TRUE),
+ tableConstructionHadWarnings_(FALSE),
+ isAnMPTableWithAnsiName_(FALSE),
+ isUMDTable_(FALSE),
+ isSMDTable_(FALSE),
+ isMVUMDTable_(FALSE),
+
+ // For virtual tables, we set the object schema version
+ // to be the current schema version
+ osv_(COM_VERS_CURR_SCHEMA),
+ ofv_(COM_VERS_CURR_SCHEMA),
+ partnsDesc_(NULL),
+ colsWithMissingStats_(NULL),
+ originalCardinality_(-1.0),
+ tableIdList_(heap),
+ rcb_(NULL),
+ rcbLen_(0),
+ keyLength_(0),
+ parentTableName_(NULL),
+ sgAttributes_(NULL),
+ isHive_(TRUE),
+ isHbase_(FALSE),
+ isHbaseCell_(FALSE),
+ isHbaseRow_(FALSE),
+ isSeabase_(FALSE),
+ isSeabaseMD_(FALSE),
+ isSeabasePrivSchemaTable_(FALSE),
+ isUserUpdatableSeabaseMD_(FALSE),
+ resetHDFSStatsAfterStmt_(FALSE),
+ hiveDefaultStringLen_(0),
+ hiveTableId_(htbl->tblID_),
+ tableDesc_(NULL),
+ secKeySet_(heap),
+ privInfo_(NULL),
+ newColumns_(heap),
+ snapshotName_(NULL),
+ allColFams_(heap)
{
- NAString tblName = qualifiedName_.getQualifiedNameObj().getQualifiedNameAsString();
- NAString mmPhase;
-
- Lng32 preCreateNATableWarnings = CmpCommon::diags()->getNumber(DgSqlCode::WARNING_);
-
- //set heap type
- if(heap_ == CmpCommon::statementHeap()){
- heapType_ = STATEMENT;
- mmPhase = "NATable Init (Stmt) - " + tblName;
- }else if (heap_ == CmpCommon::contextHeap()){
- heapType_ = CONTEXT;
- mmPhase = "NATable Init (Cnxt) - " + tblName;
- }else {
- heapType_ = OTHER;
- mmPhase = "NATable Init (Other) - " + tblName;
- }
+ NAString tblName = qualifiedName_.getQualifiedNameObj().getQualifiedNameAsString();
+ NAString mmPhase;
+
+ Lng32 preCreateNATableWarnings = CmpCommon::diags()->getNumber(DgSqlCode::WARNING_);
+
+ //set heap type
+ if(heap_ == CmpCommon::statementHeap()){
+ heapType_ = STATEMENT;
+ mmPhase = "NATable Init (Stmt) - " + tblName;
+ }else if (heap_ == CmpCommon::contextHeap()){
+ heapType_ = CONTEXT;
+ mmPhase = "NATable Init (Cnxt) - " + tblName;
+ }else {
+ heapType_ = OTHER;
+ mmPhase = "NATable Init (Other) - " + tblName;
+ }
- MonitorMemoryUsage_Enter((char*)mmPhase.data(), heap_, TRUE);
+ MonitorMemoryUsage_Enter((char*)mmPhase.data(), heap_, TRUE);
- isTrigTempTable_ = FALSE;
+ isTrigTempTable_ = FALSE;
- insertMode_ =
- COM_MULTISET_TABLE_INSERT_MODE; // allow dup, to check
- //ComInsertMode::COM_MULTISET_TABLE_INSERT_MODE; // allow dup, to check
+ insertMode_ =
+ COM_MULTISET_TABLE_INSERT_MODE; // allow dup, to check
+ //ComInsertMode::COM_MULTISET_TABLE_INSERT_MODE; // allow dup, to check
- //
- // Add timestamp information.
- //
+ //
+ // Add timestamp information.
+ //
- // To get from Hive
- /*
- createTime_ = longArrayToInt64(table_desc->tableDesc()->createtime);
- redefTime_ = longArrayToInt64(table_desc->tableDesc()->redeftime);
- cacheTime_ = longArrayToInt64(table_desc->tableDesc()->cachetime);
- */
+ // To get from Hive
+ /*
+ createTime_ = longArrayToInt64(table_desc->tableDesc()->createtime);
+ redefTime_ = longArrayToInt64(table_desc->tableDesc()->redeftime);
+ cacheTime_ = longArrayToInt64(table_desc->tableDesc()->cachetime);
+ */
+
+ // NATable has a schemaUID column, probably should propogate it.
+ // for now, set to 0.
+ schemaUID_ = 0;
+
+ // Set the objectUID_
+ // If the HIVE table has been registered in Trafodion, get the objectUID
+ // from Trafodion, otherwise, set it to 0.
+ // TBD - does getQualifiedNameObj handle delimited names correctly?
+ if ( !fetchObjectUIDForNativeTable(corrName) )
+ return;
- // NATable has a schemaUID column, probably should propogate it.
- // for now, set to 0.
- schemaUID_ = 0;
+ if ( objectUID_ > 0 )
+ setHasExternalTable(TRUE);
- // Set the objectUID_
- // If the HIVE table has been registered in Trafodion, get the objectUID
- // from Trafodion, otherwise, set it to 0.
- // TBD - does getQualifiedNameObj handle delimited names correctly?
- if ( !fetchObjectUIDForNativeTable(corrName) )
- return;
+ // for HIVE objects, the schema owner and table owner is HIVE_ROLE_ID
+ if (CmpCommon::context()->isAuthorizationEnabled())
+ {
+ owner_ = HIVE_ROLE_ID;
+ schemaOwner_ = HIVE_ROLE_ID;
+ }
+ else
+ {
+ owner_ = SUPER_USER;
+ schemaOwner_ = SUPER_USER;
+ }
- if ( objectUID_ > 0 )
- setHasExternalTable(TRUE);
+ getPrivileges(NULL);
- // for HIVE objects, the schema owner and table owner is HIVE_ROLE_ID
- if (CmpCommon::context()->isAuthorizationEnabled())
- {
- owner_ = HIVE_ROLE_ID;
- schemaOwner_ = HIVE_ROLE_ID;
- }
- else
- {
- owner_ = SUPER_USER;
- schemaOwner_ = SUPER_USER;
- }
+ // TBD - if authorization is enabled and there is no external table to store
+ // privileges, go get privilege information from HIVE metadata ...
- getPrivileges(NULL);
+ // TBD - add a check to verify that the column list coming from HIVE matches
+ // the column list stored in the external table. Maybe some common method
+ // that can be used to compare other things as well...
- // TBD - if authorization is enabled and there is no external table to store
- // privileges, go get privilege information from HIVE metadata ...
+ objectType_ = COM_BASE_TABLE_OBJECT;
- // TBD - add a check to verify that the column list coming from HIVE matches
- // the column list stored in the external table. Maybe some common method
- // that can be used to compare other things as well...
+ // to check
+ partitioningScheme_ = COM_UNKNOWN_PARTITIONING;
- objectType_ = COM_BASE_TABLE_OBJECT;
+ // to check
+ rcb_ = 0;
+ rcbLen_ = 0;
+ keyLength_ = 0;
- // to check
- partitioningScheme_ = COM_UNKNOWN_PARTITIONING;
+ partnsDesc_ = NULL;
- // to check
- rcb_ = 0;
- rcbLen_ = 0;
- keyLength_ = 0;
+ //
+ // Insert a NAColumn in the colArray_ for this NATable for each
+ // columns_desc from the ARK SMD. Returns TRUE if error creating NAColumns.
+ //
- partnsDesc_ = NULL;
+ if (createNAColumns(htbl->getColumns(),
+ this,
+ colArray_ /*OUT*/,
+ heap_))
+ //coverity[leaked_storage]
+ return;
- //
- // Insert a NAColumn in the colArray_ for this NATable for each
- // columns_desc from the ARK SMD. Returns TRUE if error creating NAColumns.
- //
- if (createNAColumns(htbl->getColumns(),
- this,
- colArray_ /*OUT*/,
- heap_))
- //coverity[leaked_storage]
- return;
+ //
+ // Set colcount_ after all possible errors (Binder uses nonzero colcount
+ // as an indicator of valid table definition).
+ //
+ // To set it via the new createNAColumns()
+ colcount_ = colArray_.entries();
- //
- // Set colcount_ after all possible errors (Binder uses nonzero colcount
- // as an indicator of valid table definition).
- //
+ // compute record length from colArray
- // To set it via the new createNAColumns()
- colcount_ = colArray_.entries();
+ Int32 recLen = 0;
+ for ( CollIndex i=0; i<colcount_; i++ ) {
+ recLen += colArray_[i]->getType()->getNominalSize();
+ }
- // compute record length from colArray
+ setRecordLength(recLen);
- Int32 recLen = 0;
- for ( CollIndex i=0; i<colcount_; i++ ) {
- recLen += colArray_[i]->getType()->getNominalSize();
- }
+ //
+ // Add view information, if this is a native hive view
+ //
+ if (htbl->isView())
+ {
+ NAString viewExpandedText(htbl->viewExpandedText_);
- setRecordLength(recLen);
+ // expanded hive view text quotes table and column names with
+ // back single quote (`). It also refers to default hive schema
+ // as `default`.
+ // Convert hive text to traf format.
+ // hive "default" schema is referred as "hive" in traf.
+ // replace `default` with hive and replace ` with "
- if (createNAFileSets(htbl /*IN*/,
- this /*IN*/,
- colArray_ /*IN*/,
- indexes_ /*OUT*/,
- vertParts_ /*OUT*/,
- clusteringIndex_ /*OUT*/,
- tableIdList_ /*OUT*/,
- heap_,
- bindWA
- )) {
- colcount_ = 0; // indicates failure
- return;
- }
+ // replace `default` with "hive"
+ viewExpandedText = replaceAll(viewExpandedText, "`default`", "hive");
- // HIVE-TBD ignore constraint info creation for now
+ // replace ` with "
+ viewExpandedText = replaceAll(viewExpandedText, "`", "");
+
+ NAString createViewStmt("CREATE VIEW ");
+ createViewStmt += htbl->tblName_ + NAString(" AS ") +
+ viewExpandedText + NAString(";");
+
+ Lng32 viewTextLen = createViewStmt.length();
+ viewText_ = new (heap_) char[viewTextLen+ 2];
+ strcpy(viewText_, createViewStmt.data());
+ hiveOrigViewText_ = new (heap_) char[strlen(htbl->viewOriginalText_)+2];
+ strcpy(hiveOrigViewText_, htbl->viewOriginalText_);
+ viewTextCharSet_ = CharInfo::UTF8;
+
+ viewFileName_ = NULL;
+ UInt32 viewFileNameLength = str_len(htbl->tblName_) + 1;
+ viewFileName_ = new (heap_) char[viewFileNameLength];
+ memcpy(viewFileName_, htbl->tblName_, viewFileNameLength);
+
+ setUpdatable(FALSE);
+ setInsertable(FALSE);
+ }
+ else
+ {
+ if (createNAFileSets(htbl /*IN*/,
+ this /*IN*/,
+ colArray_ /*IN*/,
+ indexes_ /*OUT*/,
+ vertParts_ /*OUT*/,
+ clusteringIndex_ /*OUT*/,
+ tableIdList_ /*OUT*/,
+ heap_,
+ bindWA
+ )) {
+ colcount_ = 0; // indicates failure
+ return;
+ }
+ }
+
+ // HIVE-TBD ignore constraint info creation for now
- // If there is a host variable associated with this table, store it
- // for use by the generator to generate late-name resolution information.
- //
- HostVar *hv = corrName.getPrototype();
- prototype_ = hv ? new (heap_) HostVar(*hv) : NULL;
- // MV
- // Initialize the MV support data members
- isAnMV_ = FALSE;
- isAnMVMetaData_ = FALSE;
+ // If there is a host variable associated with this table, store it
+ // for use by the generator to generate late-name resolution information.
+ //
+ HostVar *hv = corrName.getPrototype();
+ prototype_ = hv ? new (heap_) HostVar(*hv) : NULL;
- Lng32 postCreateNATableWarnings = CmpCommon::diags()->getNumber(DgSqlCode::WARNING_);
+ // MV
+ // Initialize the MV support data members
+ isAnMV_ = FALSE;
+ isAnMVMetaData_ = FALSE;
+
+ Lng32 postCreateNATableWarnings = CmpCommon::diags()->getNumber(DgSqlCode::WARNING_);
- if(postCreateNATableWarnings != preCreateNATableWarnings)
- tableConstructionHadWarnings_=TRUE;
+ if(postCreateNATableWarnings != preCreateNATableWarnings)
+ tableConstructionHadWarnings_=TRUE;
- hiveDefaultStringLen_ = CmpCommon::getDefaultLong(HIVE_MAX_STRING_LENGTH);
- Int32 hiveDefaultStringLenInBytes = CmpCommon::getDefaultLong(HIVE_MAX_STRING_LENGTH_IN_BYTES);
- if( hiveDefaultStringLenInBytes != 32000 )
- hiveDefaultStringLen_ = hiveDefaultStringLenInBytes;
+ hiveDefaultStringLen_ = CmpCommon::getDefaultLong(HIVE_MAX_STRING_LENGTH);
+ Int32 hiveDefaultStringLenInBytes = CmpCommon::getDefaultLong(HIVE_MAX_STRING_LENGTH_IN_BYTES);
+ if( hiveDefaultStringLenInBytes != 32000 )
+ hiveDefaultStringLen_ = hiveDefaultStringLenInBytes;
- // LCOV_EXCL_STOP
- initialSize_ = heap_->getAllocSize();
- MonitorMemoryUsage_Exit((char*)mmPhase.data(), heap_, NULL, TRUE);
+ // LCOV_EXCL_STOP
+ initialSize_ = heap_->getAllocSize();
+ MonitorMemoryUsage_Exit((char*)mmPhase.data(), heap_, NULL, TRUE);
} // NATable()
#pragma warn(770) // warning elimination
+NABoolean NATable::doesMissingStatsWarningExist(CollIndexSet & colsSet) const
+{
+ return colsWithMissingStats_->contains(&colsSet);
+}
+
+NABoolean NATable::insertMissingStatsWarning(CollIndexSet colsSet) const
+{
+ CollIndexSet * setOfColsWithMissingStats = new (STMTHEAP) CollIndexSet (colsSet);
+
+ Int32 someVar = 1;
+ CollIndexSet * result = colsWithMissingStats_->insert(setOfColsWithMissingStats, &someVar);
+
+ if (result == NULL)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+// This gets called in the Optimizer phase -- the Binder phase will already have
+// marked columns that were referenced in the query, so that the ustat function
+// below can decide which histograms and histints to leave in the stats list
+// and which to remove.
+//
+StatsList &
+NATable::getStatistics()
+{
+ if (!statsFetched_)
+ {
+ // mark the kind of histograms needed for this table's columns
+ markColumnsForHistograms();
+
+ NAString tblName = qualifiedName_.getQualifiedNameObj().getQualifiedNameAsString();
+ NAString mmPhase = "NATable getStats - " + tblName;
+ MonitorMemoryUsage_Enter((char*)mmPhase.data(), NULL, TRUE);
+
+ //trying to get statistics for a new statement allocate colStats_
+ colStats_ = new (CmpCommon::statementHeap()) StatsList(CmpCommon::statementHeap());
+
+ // Do not create statistics on the fly for the following tables
+ if (isAnMV() || isUMDTable() ||
+ isSMDTable() || isMVUMDTable() ||
+ isTrigTempTable() )
+ CURRSTMT_OPTDEFAULTS->setHistDefaultSampleSize(0);
+
+ CURRCONTEXT_HISTCACHE->getHistograms(*this);
+
+ if ((*colStats_).entries() > 0)
+ originalCardinality_ = (*colStats_)[0]->getRowcount();
+ else
+ originalCardinality_ = ActiveSchemaDB()->getDefaults().getAsDouble(HIST_NO_STATS_ROWCOUNT);
+
+ // -----------------------------------------------------------------------
+ // So now we have read in the contents of the HISTOGRM & HISTINTS
+ // tables from the system catalog. Before we can use them, we need
+ // to massage them into a format we can use. In particular, we need
+ // to make sure that what we read in (which the user may have mucked
+ // about with) matches the histogram classes' internal semantic
+ // requirements. Also, we need to generate the MultiColumnUecList.
+ // ----------------------------------------------------------------------
+
+ // what did the user set as the max number of intervals?
+ NADefaults &defs = ActiveSchemaDB()->getDefaults();
+ CollIndex maxIntervalCount = defs.getAsLong(HIST_MAX_NUMBER_OF_INTERVALS);
+
+ //-----------------------------------------------------------------------------------
+ // Need to flag the MC colStatsDesc so it is only used for the range partitioning task
+ // and not any cardinality calculations tasks. Flagging it also makes the logic
+ // to check fo the presence for this MC easier (at the time we need to create
+ // the range partitioning function)
+ //-----------------------------------------------------------------------------------
+
+ if (CmpCommon::getDefault(HBASE_RANGE_PARTITIONING_MC_SPLIT) == DF_ON &&
+ !(*colStats_).allFakeStats())
+ {
+ CollIndex currentMaxsize = 1;
+ Int32 posMCtoUse = -1;
+
+ NAColumnArray partCols;
+
+ if (getClusteringIndex()->getPartitioningKeyColumns().entries() > 0)
+ partCols = getClusteringIndex()->getPartitioningKeyColumns();
+ else
+ partCols = getClusteringIndex()->getIndexKeyColumns();
+
+ CollIndex partColNum = partCols.entries();
+
+ // look for MC histograms that have multiple intervals and whose columns are a prefix for the
+ // paritition column list. If multiple pick the one with the most matching columns
+ for (Int32 i=0; i < (*colStats_).entries(); i++)
+ {
+ NAColumnArray statsCols = (*colStats_)[i]->getStatColumns();
+ CollIndex colNum = statsCols.entries();
+
+ CollIndex j = 0;
+
+ NABoolean potentialMatch = TRUE;
+ if ((colNum > currentMaxsize) &&
+ (!(*colStats_)[i]->isSingleIntHist()) && // no SIH -- number of histograms is large enough to do splitting
+ (colNum <= partColNum))
+ {
+ while ((j < colNum) && potentialMatch)
+ {
+ j++;
+ NAColumn * col = partCols[j-1];
+ if (statsCols[j-1]->getPosition() != partCols[j-1]->getPosition())
+ {
+ potentialMatch = FALSE;
+ break;
+ }
+ }
+ }
+ else
+ {
+ potentialMatch = FALSE;
+ }
+
+ if (potentialMatch)
+ {
+ currentMaxsize = j;
+ posMCtoUse = i;
+ }
+
+ // we got what we need, just return
+ if (potentialMatch && (currentMaxsize == partColNum))
+ {
+ break;
+ }
+ }
+
+ if (posMCtoUse >= 0)
+ {
+ (*colStats_)[posMCtoUse]->setMCforHbasePartitioning (TRUE);
+ }
+ }
+
+ // *************************************************************************
+ // FIRST: Generate the stats necessary to later create the
+ // MultiColumnUecList; then filter out the multi-column histograms
+ // because later code doesn't know how to handle them
+ // In the same loop, also mark another flag for originally fake histogram
+ // This is to differentiate the cases when the histogram is fake because
+ // it has no statistics and the case where the histogram has been termed
+ // fake by the optimizer because its statistics is no longer reliable.
+ // *************************************************************************
+ CollIndex i ;
+ for ( i = 0 ; i < (*colStats_).entries() ; /* no automatic increment */ )
+ {
+ // the StatsList has two lists which it uses to store the information we
+ // need to fill the MultiColumnUecList with <table-col-list,uec value> pairs:
+ //
+ // LIST(NAColumnArray) groupUecColumns_
+ // LIST(CostScalar) groupUecValues_
+ //
+ // ==> insert the NAColumnArray & uec total values for each
+ // entry in colStats_
+
+ // don't bother storing multicolumnuec info for fake histograms
+ // but do set the originallly fake histogram flag to TRUE
+ if ( (*colStats_)[i]->isFakeHistogram() )
+ (*colStats_)[i]->setOrigFakeHist(TRUE);
+ else
+ {
+ NAColumnArray cols = (*colStats_)[i]->getStatColumns() ;
+ (*colStats_).groupUecColumns_.insert(cols) ;
+
+ CostScalar uecs = (*colStats_)[i]->getTotalUec() ;
+ (*colStats_).groupUecValues_.insert(uecs) ;
+
+ if (CmpCommon::getDefault(USTAT_COLLECT_MC_SKEW_VALUES) == DF_ON)
+ {
+ MCSkewedValueList mcSkewedValueList = (*colStats_)[i]->getMCSkewedValueList() ;
+ (*colStats_).groupMCSkewedValueLists_.insert(mcSkewedValueList) ;
+ }
+ }
+
+ // MCH:
+ // once we've stored the column/uec information, filter out the
+ // multi-column histograms, since our synthesis code doesn't
+ // handle them
+ if (( (*colStats_)[i]->getStatColumns().entries() != 1) &&
+ (!(*colStats_)[i]->isMCforHbasePartitioning()))
+ {
+ (*colStats_).removeAt(i) ;
+ }
+ else
+ {
+ i++ ; // in-place removal from a list is a bother!
+ }
+ }
+
+ // *************************************************************************
+ // SECOND: do some fixup work to make sure the histograms maintain
+ // the semantics we later expect (& enforce)
+ // *************************************************************************
+
+ // -------------------------------------------------------------------------
+ // HISTINT fixup-code : char-string histograms
+ // -------------------------------------------------------------------------
+ // problem arises with HISTINTs that are for char* columns
+ // here's what we can get:
+ //
+ // Rows Uec Value
+ // ---- --- -----
+ // 0 0 "value"
+ // 10 5 "value"
+ //
+ // this is not good! The problem is our (lousy) encoding of
+ // char strings into EncodedValue's
+ //
+ // After much deliberation, here's our current fix:
+ //
+ // Rows Uec Value
+ // ---- --- -----
+ // 0 0 "valu" <-- reduce the min value of 1st interval
+ // 10 5 "value" by a little bit
+ //
+ // When we find two intervals like this where they aren't the
+ // first intervals in the histogram, we simply merge them into
+ // one interval (adding row/uec information) and continue; note
+ // that in this case, we haven't actually lost any information;
+ // we've merely made sense out of (the garbage) what we've got
+ //
+ // -------------------------------------------------------------------------
+ // additional HISTINT fixup-code
+ // -------------------------------------------------------------------------
+ // 1. If there are zero or one HISTINTs, then set the HISTINTs to match
+ // the max/min information contained in the COLSTATS object.
+ //
+ // 2. If there are any HISTINTs whose boundary values are out-of-order,
+ // we abort with an an ERROR message.
+ //
+ // 3. If there is a NULL HISTINT at the end of the Histogram, then we
+ // need to make sure there are *TWO* NULL HISTINTS, to preserve correct
+ // histogram semantics for single-valued intervals.
+ // -------------------------------------------------------------------------
+
+ CollIndex j ;
+ for ( i = 0 ; i < (*colStats_).entries() ; i++ )
+ {
+ // we only worry about histograms on char string columns
+ // correction: it turns out that these semantically-deranged
+ // ---------- histograms were being formed for other, non-char string
+ // columns, so we commented out the code below
+ // if ( colStats_[i]->getStatColumns()[0]->getType()->getTypeQualifier() !=
+ // NA_CHARACTER_TYPE)
+ // continue ; // not a string, skip to next
+
+ ColStatsSharedPtr stats = (*colStats_)[i] ;
+
+ HistogramSharedPtr hist = stats->getHistogramToModify() ;
+ // histograms for key columns of a table that are not
+ // referenced in the query are read in with zero intervals
+ // (to conserve memory); however, internal
+ // histogram-semantic checking code assumes that any
+ // histogram which has zero intervals is FAKE; however
+ // however, MDAM will not be chosen in the case where one of
+ // the histograms for a key column is FAKE. Thus -- we will
+ // avoid this entire issue by creating a single interval for
+ // any Histograms that we read in that are empty.
+ if ( hist->entries() < 2 )
+ {
+ if(stats->getMinValue() > stats->getMaxValue())
+ {
+ *CmpCommon::diags() << DgSqlCode(CATALOG_HISTOGRM_HISTINTS_TABLES_CONTAIN_BAD_VALUE)
+ << DgString0("")
+ << DgString1(stats->getStatColumns()[0]->getFullColRefNameAsAnsiString().data() );
+
+ stats->createFakeHist();
+ continue;
+ }
+
+ stats->setToSingleInterval ( stats->getMinValue(),
+ stats->getMaxValue(),
+ stats->getRowcount(),
+ stats->getTotalUec() ) ;
+ // now we have to undo some of the automatic flag-setting
+ // of ColStats::setToSingleInterval()
+ stats->setMinSetByPred (FALSE) ;
+ stats->setMaxSetByPred (FALSE) ;
+ stats->setShapeChanged (FALSE) ;
+ continue ; // skip to next ColStats
+ }
+
+ // NB: we'll handle the first Interval last
+ for ( j = 1 ; j < hist->entries()-1 ; /* no automatic increment */ )
+ {
+
+ if ( (*hist)[j].getUec() == 0 || (*hist)[j].getCardinality() == 0 )
+ {
+ hist->removeAt(j) ;
+ continue ; // don't increment, loop again
+ }
+ // intervals must be in order!
+ if ( (*hist)[j].getBoundary() > (*hist)[j+1].getBoundary() )
+ {
+ *CmpCommon::diags() <<
+ DgSqlCode(CATALOG_HISTINTS_TABLES_CONTAIN_BAD_VALUES)
+ << DgInt0(j)
+ << DgInt1(j+1)
+ << DgString1(stats->getStatColumns()[0]->getFullColRefNameAsAnsiString().data() );
+
+ stats->createFakeHist();
+ break ; // skip to next ColStats
+ }
-NABoolean NATable::doesMissingStatsWarningExist(CollIndexSet & colsSet) const
-{
- return colsWithMissingStats_->contains(&colsSet);
-}
+ if ( (*hist)[j].getBoundary() == (*hist)[j+1].getBoundary() )
+ {
+ // merge Intervals, if the two consecutive intervals have same
+ // boundaries and these are not single valued (UEC > 1)
+ // If there are more two single valued intervals, then merge
+ // all except the last one.
+ NABoolean mergeIntervals = FALSE;
-NABoolean NATable::insertMissingStatsWarning(CollIndexSet colsSet) const
-{
- CollIndexSet * setOfColsWithMissingStats = new (STMTHEAP) CollIndexSet (colsSet);
+ if (CmpCommon::getDefault(COMP_BOOL_79) == DF_ON)
+ {
+ mergeIntervals = TRUE;
- Int32 someVar = 1;
- CollIndexSet * result = colsWithMissingStats_->insert(setOfColsWithMissingStats, &someVar);
+ if( (j < (hist->entries() - 2)) && ((*hist)[j+1].getUec() == 1) &&
+ ((*hist)[j+1].getBoundary() != (*hist)[j+2].getBoundary())
+ ||
+ (j == (hist->entries() - 2)) && ((*hist)[j+1].getUec() == 1) )
+ mergeIntervals = FALSE;
+ }
+ else
+ {
+ if ( (*hist)[j+1].getUec() > 1)
+ mergeIntervals = TRUE;
+ }
- if (result == NULL)
- return FALSE;
- else
- return TRUE;
-}
+ if ( mergeIntervals )
+ {
+ // if the intervals with same boundary are not SVI, just merge them
+ // together.
+ // Also do the merge, if there are more than one SVIs with same
+ // encoded interval boundary. Example, we want to avoid intervals
+ // such as
+ // boundary inclusive_flag UEC
+ // 12345.00 < 1
+ // 12345.00 < 1
+ // 12345.00 <= 1
+ // These would be changed to
+ // 12345.00 < 2
+ // 12345.00 <= 1
+ CostScalar combinedRows = (*hist)[ j ].getCardinality() +
+ (*hist)[j+1].getCardinality() ;
+ CostScalar combinedUec = (*hist)[ j ].getUec() +
+ (*hist)[j+1].getUec() ;
+ (*hist)[j].setCardAndUec (combinedRows, combinedUec) ;
+ stats->setIsColWithBndryConflict(TRUE);
+ hist->removeAt(j+1) ;
+ }
+ else
+ {
+ // for some reason, some SVI's aren't being
+ // generated correctly!
+ (*hist)[j].setBoundIncl(FALSE) ;
+ (*hist)[j+1].setBoundIncl(TRUE) ;
+ j++;
+ }
+ }
+ else
+ j++ ; // in-place removal from a list is a bother!
+ } // loop over intervals
-// This gets called in the Optimizer phase -- the Binder phase will already have
-// marked columns that were referenced in the query, so that the ustat function
-// below can decide which histograms and histints to leave in the stats list
-// and which to remove.
-//
- StatsList &
-NATable::getStatistics()
-{
- if (!statsFetched_)
- {
- // mark the kind of histograms needed for this table's columns
- markColumnsForHistograms();
-
- NAString tblName = qualifiedName_.getQualifiedNameObj().getQualifiedNameAsString();
- NAString mmPhase = "NATable getStats - " + tblName;
- MonitorMemoryUsage_Enter((char*)mmPhase.data(), NULL, TRUE);
-
- //trying to get statistics for a new statement allocate colStats_
- colStats_ = new (CmpCommon::statementHeap()) StatsList(CmpCommon::statementHeap());
-
- // Do not create statistics on the fly for the following tables
- if (isAnMV() || isUMDTable() ||
- isSMDTable() || isMVUMDTable() ||
- isTrigTempTable() )
- CURRSTMT_OPTDEFAULTS->setHistDefaultSampleSize(0);
-
- CURRCONTEXT_HISTCACHE->getHistograms(*this);
-
- if ((*colStats_).entries() > 0)
- originalCardinality_ = (*colStats_)[0]->getRowcount();
- else
- originalCardinality_ = ActiveSchemaDB()->getDefaults().getAsDouble(HIST_NO_STATS_ROWCOUNT);
-
- // -----------------------------------------------------------------------
- // So now we have read in the contents of the HISTOGRM & HISTINTS
- // tables from the system catalog. Before we can use them, we need
- // to massage them into a format we can use. In particular, we need
- // to make sure that what we read in (which the user may have mucked
- // about with) matches the histogram classes' internal semantic
- // requirements. Also, we need to generate the MultiColumnUecList.
- // ----------------------------------------------------------------------
-
- // what did the user set as the max number of intervals?
- NADefaults &defs = ActiveSchemaDB()->getDefaults();
- CollIndex maxIntervalCount = defs.getAsLong(HIST_MAX_NUMBER_OF_INTERVALS);
-
- //-----------------------------------------------------------------------------------
- // Need to flag the MC colStatsDesc so it is only used for the range partitioning task
- // and not any cardinality calculations tasks. Flagging it also makes the logic
- // to check fo the presence for this MC easier (at the time we need to create
- // the range partitioning function)
- //-----------------------------------------------------------------------------------
-
- if (CmpCommon::getDefault(HBASE_RANGE_PARTITIONING_MC_SPLIT) == DF_ON &&
- !(*colStats_).allFakeStats())
- {
- CollIndex currentMaxsize = 1;
- Int32 posMCtoUse = -1;
+ // ----------------------------------------------------------------------
+ // now we handle the first interval
+ //
+ // first, it must be in order w.r.t. the second interval!
+ if ( (*hist)[0].getBoundary() > (*hist)[1].getBoundary() )
+ {
+ *CmpCommon::diags() <<
+ DgSqlCode(CATALOG_HISTINTS_TABLES_CONTAIN_BAD_VALUES)
+ << DgInt0(0)
+ << DgInt1(1)
+ << DgString1(stats->getStatColumns()[0]->getFullColRefNameAsAnsiString().data() );
+
+ stats->createFakeHist();
+ continue ; // skip to next ColStats
+ }
- NAColumnArray partCols;
+ // second, handle the case where first and second interval are the same
+ if ( hist->entries() > 1 && // avoid the exception! might just be a single NULL
+ // // interval after the loop above
+ (*hist)[0].getBoundary() == (*hist)[1].getBoundary() &&
+ (*hist)[1].getUec() > 1 )
+ {
+ const double KLUDGE_VALUE = 0.0001 ;
+ const double oldVal = (*hist)[0].getBoundary().getDblValue() ;
+ const EncodedValue newVal =
+ EncodedValue(oldVal - (_ABSOLUTE_VALUE_(oldVal) * KLUDGE_VALUE)) ; // kludge alert!
+ //Absolute of oldval due to CR 10-010426-2457
+ (*hist)[0].setBoundary( newVal ) ;
+ (*hist)[0].setBoundIncl( FALSE ) ; // no longer a real boundary!
+ (*colStats_)[i]->setMinValue( newVal ) ; // set aggr info also
+ }
+ // done with first interval
+ // ----------------------------------------------------------------------
- if (getClusteringIndex()->getPartitioningKeyColumns().entries() > 0)
- partCols = getClusteringIndex()->getPartitioningKeyColumns();
- else
- partCols = getClusteringIndex()->getIndexKeyColumns();
+ //
+ // NULL values must only be stored in single-valued intervals
+ // in the histograms ; so, just in case we're only getting
+ // *one* HistInt for the NULL interval, insert a 2nd one
+ //
+ // 0 1 2
+ // | | |
+ // | | | entries() == 3
+ // NULL
+ //
+ // 0 1 2 3
+ // | | | |
+ // | | | | entries() == 4
+ // new NULL
+ // NULL
+ //
+ if ( hist->lastHistInt().isNull() )
+ {
+ CollIndex count = hist->entries() ;
+ if ( !(*hist)[count-2].isNull() )
+ {
+ // insert a 2nd NULL HISTINT, with boundaryIncl value FALSE
+ HistInt secondLast (hist->lastHistInt().getBoundary(), FALSE) ;
+ hist->insertAt(count-1,secondLast) ;
+ // new HISTINT by default has row/uec of 0, which is what we want
+ }
+ }
- CollIndex partColNum = partCols.entries();
+ //
+ // Now, reduce the total number of intervals to be the number
+ // that the user wants. This is used to test the tradeoffs
+ // between compile time & rowcount estimation.
+ //
+ (*colStats_)[i]->setMaxIntervalCount (maxIntervalCount) ;
+ (*colStats_)[i]->reduceToMaxIntervalCount () ;
- // look for MC histograms that have multiple intervals and whose columns are a prefix for the
- // paritition column list. If multiple pick the one with the most matching columns
- for (Int32 i=0; i < (*colStats_).entries(); i++)
- {
- NAColumnArray statsCols = (*colStats_)[i]->getStatColumns();
- CollIndex colNum = statsCols.entries();
-
- CollIndex j = 0;
-
- NABoolean potentialMatch = TRUE;
- if ((colNum > currentMaxsize) &&
- (!(*colStats_)[i]->isSingleIntHist()) && // no SIH -- number of histograms is large enough to do splitting
- (colNum <= partColNum))
- {
- while ((j < colNum) && potentialMatch)
- {
- j++;
- NAColumn * col = partCols[j-1];
- if (statsCols[j-1]->getPosition() != partCols[j-1]->getPosition())
- {
- potentialMatch = FALSE;
- break;
- }
- }
- }
- else
- {
- potentialMatch = FALSE;
- }
-
- if (potentialMatch)
- {
- currentMaxsize = j;
- posMCtoUse = i;
- }
-
- // we got what we need, just return
- if (potentialMatch && (currentMaxsize == partColNum))
- {
- break;
- }
- }
-
- if (posMCtoUse >= 0)
- {
- (*colStats_)[posMCtoUse]->setMCforHbasePartitioning (TRUE);
- }
- }
+ if ((*colStats_)[i]->getRowcount() == (*colStats_)[i]->getTotalUec() )
+ (*colStats_)[i]->setAlmostUnique(TRUE);
- // *************************************************************************
- // FIRST: Generate the stats necessary to later create the
- // MultiColumnUecList; then filter out the multi-column histograms
- // because later code doesn't know how to handle them
- // In the same loop, also mark another flag for originally fake histogram
- // This is to differentiate the cases when the histogram is fake because
- // it has no statistics and the case where the histogram has been termed
- // fake by the optimizer because its statistics is no longer reliable.
- // *************************************************************************
- CollIndex i ;
- for ( i = 0 ; i < (*colStats_).entries() ; /* no automatic increment */ )
- {
- // the StatsList has two lists which it uses to store the information we
- // need to fill the MultiColumnUecList with <table-col-list,uec value> pairs:
- //
- // LIST(NAColumnArray) groupUecColumns_
- // LIST(CostScalar) groupUecValues_
- //
- // ==> insert the NAColumnArray & uec total values for each
- // entry in colStats_
-
- // don't bother storing multicolumnuec info for fake histograms
- // but do set the originallly fake histogram flag to TRUE
- if ( (*colStats_)[i]->isFakeHistogram() )
- (*colStats_)[i]->setOrigFakeHist(TRUE);
- else
- {
- NAColumnArray cols = (*colStats_)[i]->getStatColumns() ;
- (*colStats_).groupUecColumns_.insert(cols) ;
-
- CostScalar uecs = (*colStats_)[i]->getTotalUec() ;
- (*colStats_).groupUecValues_.insert(uecs) ;
-
- if (CmpCommon::getDefault(USTAT_COLLECT_MC_SKEW_VALUES) == DF_ON)
- {
- MCSkewedValueList mcSkewedValueList = (*colStats_)[i]->getMCSkewedValueList() ;
- (*colStats_).groupMCSkewedValueLists_.insert(mcSkewedValueList) ;
- }
- }
-
- // MCH:
- // once we've stored the column/uec information, filter out the
- // multi-column histograms, since our synthesis code doesn't
- // handle them
- if (( (*colStats_)[i]->getStatColumns().entries() != 1) &&
- (!(*colStats_)[i]->isMCforHbasePartitioning()))
- {
- (*colStats_).removeAt(i) ;
- }
- else
- {
- i++ ; // in-place removal from a list is a bother!
- }
- }
+ } // outer for loop -- done with this COLSTATS, continue with next one
+ // ***********************************************************************
- // *************************************************************************
- // SECOND: do some fixup work to make sure the histograms maintain
- // the semantics we later expect (& enforce)
- // *************************************************************************
-
- // -------------------------------------------------------------------------
- // HISTINT fixup-code : char-string histograms
- // -------------------------------------------------------------------------
- // problem arises with HISTINTs that are for char* columns
- // here's what we can get:
- //
- // Rows Uec Value
- // ---- --- -----
- // 0 0 "value"
- // 10 5 "value"
- //
- // this is not good! The problem is our (lousy) encoding of
- // char strings into EncodedValue's
- //
- // After much deliberation, here's our current fix:
- //
- // Rows Uec Value
- // ---- --- -----
- // 0 0 "valu" <-- reduce the min value of 1st interval
- // 10 5 "value" by a little bit
- //
- // When we find two intervals like this where they aren't the
- // first intervals in the histogram, we simply merge them into
- // one interval (adding row/uec information) and continue; note
- // that in this case, we haven't actually lost any information;
- // we've merely made sense out of (the garbage) what we've got
- //
- // -------------------------------------------------------------------------
- // additional HISTINT fixup-code
- // -------------------------------------------------------------------------
- // 1. If there are zero or one HISTINTs, then set the HISTINTs to match
- // the max/min information contained in the COLSTATS object.
- //
- // 2. If there are any HISTINTs whose boundary values are out-of-order,
- // we abort with an an ERROR message.
- //
- // 3. If there is a NULL HISTINT at the end of the Histogram, then we
- // need to make sure there are *TWO* NULL HISTINTS, to preserve correct
- // histogram semantics for single-valued intervals.
- // -------------------------------------------------------------------------
-
- CollIndex j ;
- for ( i = 0 ; i < (*colStats_).entries() ; i++ )
- {
- // we only worry about histograms on char string columns
- // correction: it turns out that these semantically-deranged
- // ---------- histograms were being formed for other, non-char string
- // columns, so we commented out the code below
- // if ( colStats_[i]->getStatColumns()[0]->getType()->getTypeQualifier() !=
- // NA_CHARACTER_TYPE)
- // continue ; // not a string, skip to next
-
- ColStatsSharedPtr stats = (*colStats_)[i] ;
-
- HistogramSharedPtr hist = stats->getHistogramToModify() ;
- // histograms for key columns of a table that are not
- // referenced in the query are read in with zero intervals
- // (to conserve memory); however, internal
- // histogram-semantic checking code assumes that any
- // histogram which has zero intervals is FAKE; however
- // however, MDAM will not be chosen in the case where one of
- // the histograms for a key column is FAKE. Thus -- we will
- // avoid this entire issue by creating a single interval for
- // any Histograms that we read in that are empty.
- if ( hist->entries() < 2 )
- {
- if(stats->getMinValue() > stats->getMaxValue())
- {
- *CmpCommon::diags() << DgSqlCode(CATALOG_HISTOGRM_HISTINTS_TABLES_CONTAIN_BAD_VALUE)
- << DgString0("")
- << DgString1(stats->getStatColumns()[0]->getFullColRefNameAsAnsiString().data() );
-
- stats->createFakeHist();
- continue;
- }
-
- stats->setToSingleInterval ( stats->getMinValue(),
- stats->getMaxValue(),
- stats->getRowcount(),
- stats->getTotalUec() ) ;
- // now we have to undo some of the automatic flag-setting
- // of ColStats::setToSingleInterval()
- stats->setMinSetByPred (FALSE) ;
- stats->setMaxSetByPred (FALSE) ;
- stats->setShapeChanged (FALSE) ;
- continue ; // skip to next ColStats
- }
-
- // NB: we'll handle the first Interval last
- for ( j = 1 ; j < hist->entries()-1 ; /* no automatic increment */ )
- {
+ statsFetched_ = TRUE;
+ MonitorMemoryUsage_Exit((char*)mmPhase.data(), NULL, NULL, TRUE);
+ } // !statsFetched_
- if ( (*hist)[j].getUec() == 0 || (*hist)[j].getCardinality() == 0 )
- {
- hist->removeAt(j) ;
- continue ; // don't increment, loop again
- }
-
- // intervals must be in order!
- if ( (*hist)[j].getBoundary() > (*hist)[j+1].getBoundary() )
- {
- *CmpCommon::diags() <<
- DgSqlCode(CATALOG_HISTINTS_TABLES_CONTAIN_BAD_VALUES)
- << DgInt0(j)
- << DgInt1(j+1)
- << DgString1(stats->getStatColumns()[0]->getFullColRefNameAsAnsiString().data() );
-
- stats->createFakeHist();
- break ; // skip to next ColStats
- }
-
- if ( (*hist)[j].getBoundary() == (*hist)[j+1].getBoundary() )
- {
- // merge Intervals, if the two consecutive intervals have same
- // boundaries and these are not single valued (UEC > 1)
- // If there are more two single valued intervals, then merge
- // all except the last one.
- NABoolean mergeIntervals = FALSE;
-
- if (CmpCommon::getDefault(COMP_BOOL_79) == DF_ON)
- {
- mergeIntervals = TRUE;
-
- if( (j < (hist->entries() - 2)) && ((*hist)[j+1].getUec() == 1) &&
- ((*hist)[j+1].getBoundary() != (*hist)[j+2].getBoundary())
- ||
- (j == (hist->entries() - 2)) && ((*hist)[j+1].getUec() == 1) )
- mergeIntervals = FALSE;
- }
- else
- {
- if ( (*hist)[j+1].getUec() > 1)
- mergeIntervals = TRUE;
- }
-
- if ( mergeIntervals )
- {
- // if the intervals with same boundary are not SVI, just merge them
- // together.
- // Also do the merge, if there are more than one SVIs with same
- // encoded interval boundary. Example, we want to avoid intervals
- // such as
- // boundary inclusive_flag UEC
- // 12345.00 < 1
- // 12345.00 < 1
- // 12345.00 <= 1
- // These would be changed to
- // 12345.00 < 2
- // 12345.00 <= 1
- CostScalar combinedRows = (*hist)[ j ].getCardinality() +
- (*hist)[j+1].getCardinality() ;
- CostScalar combinedUec = (*hist)[ j ].getUec() +
- (*hist)[j+1].getUec() ;
- (*hist)[j].setCardAndUec (combinedRows, combinedUec) ;
- stats->setIsColWithBndryConflict(TRUE);
- hist->removeAt(j+1) ;
- }
- else
- {
- // for some reason, some SVI's aren't being
- // generated correctly!
- (*hist)[j].setBound
<TRUNCATED>