Merge [TRAFODION-2884] PR-1664 Multiple fixes with Name Server enabled logic
diff --git a/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp b/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp
index b489afb..1af8f1e 100644
--- a/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp
@@ -5511,6 +5511,80 @@
, inputParam[4], inputParam[5]
);
break;
+ case SQL_API_SQLCOLUMNPRIVILEGES:
+ convertWildcard(metadataId, TRUE, catalogNm, expCatalogNm);
+ convertWildcardNoEsc(metadataId, TRUE, catalogNm, catalogNmNoEsc);
+ convertWildcard(metadataId, TRUE, schemaNm, expSchemaNm);
+ convertWildcardNoEsc(metadataId, TRUE, schemaNm, schemaNmNoEsc);
+ convertWildcard(metadataId, TRUE, tableNm, expTableNm);
+ convertWildcardNoEsc(metadataId, TRUE, tableNm, tableNmNoEsc);
+ convertWildcard(metadataId, TRUE, columnNm, expColumnNm);
+ convertWildcardNoEsc(metadataId, TRUE, columnNm, columnNmNoEsc);
+ inputParam[0] = catalogNmNoEsc;
+ inputParam[1] = expCatalogNm;
+ inputParam[2] = schemaNmNoEsc;
+ inputParam[3] = expSchemaNm;
+ inputParam[4] = tableNmNoEsc;
+ inputParam[5] = expTableNm;
+ inputParam[6] = columnNmNoEsc;
+ inputParam[7] = expColumnNm;
+ snprintf(CatalogQuery, sizeof(CatalogQuery), "select cast(mob.CATALOG_NAME as varchar(128)) TABLE_CAT,"
+ "cast(mob.SCHEMA_NAME as varchar(128)) TABLE_SCHEM,"
+ "cast(mob.OBJECT_NAME as varchar(128)) TABLE_NAME,"
+ "cast(mco.COLUMN_NAME as varchar(128)) COLUMN_NAME,"
+ "cast(pmcp.GRANTOR_NAME as varchar(128)) GRANTOR,"
+ "cast(pmcp.GRANTEE_NAME as varchar(128)) GRANTEE,"
+ "cast(trim(case pmcp.PRIVILEGES_BITMAP "
+ "when 1 then 'SELECT' "
+ "when 2 then 'INSERT' "
+ "when 3 then 'SELECT,INSERT' "
+ "when 4 then 'DELETE' "
+ "when 5 then 'SELECT,DELETE' "
+ "when 6 then 'INSERT,DELETE' "
+ "when 7 then 'SELECT,INSERT,DELETE' "
+ "when 8 then 'UPDATE' "
+ "when 9 then 'SELECT,UPDATE' "
+ "when 10 then 'INSERT,UPDATE' "
+ "when 11 then 'SELECT,INSERT,UPDATE' "
+ "when 12 then 'DELETE,UPDATE' "
+ "when 13 then 'SELECT,DELETE,UPDATE' "
+ "when 14 then 'INSERT,DELETE,UPDATE' "
+ "when 15 then 'SELECT,INSERT,DELETE,UPDATE' "
+ "when 32 then 'REFERENCES' "
+ "when 33 then 'SELECT,REFERENCES' "
+ "when 34 then 'INSERT,REFERENCES' "
+ "when 35 then 'SELECT,INSERT,REFERENCES' "
+ "when 36 then 'DELETE,REFERENCES' "
+ "when 37 then 'SELECT,DELETE,REFERENCES' "
+ "when 38 then 'INSERT,DELETE,REFERENCES' "
+ "when 39 then 'SELECT,INSERT,DELETE,REFERENCES' "
+ "when 40 then 'UPDATE,REFERENCES' "
+ "when 41 then 'SELECT,UPDATE,REFERENCES' "
+ "when 42 then 'INSERT,UPDATE,REFERENCES' "
+ "when 43 then 'SELECT,INSERT,UPDATE,REFERENCES' "
+ "when 44 then 'DELETE,UPDATE,REFERENCES' "
+ "when 45 then 'SELECT,DELETE,UPDATE,REFERENCES' "
+ "when 46 then 'INSERT,DELETE,UPDATE,REFERENCES' "
+ "when 47 then 'SELECT,INSERT,DELETE,UPDATE,REFERENCES' end) as varchar(128)) PRIVILEGE, "
+ "cast (trim(case pmcp.GRANTABLE_BITMAP "
+ "when 0 then 'NO' else 'YES' "
+ "end) as varchar(128)) IS_GRANTABLE "
+ "from TRAFODION.\"_MD_\".OBJECTS as mob, TRAFODION.\"_MD_\".COLUMNS as mco, TRAFODION.\"_PRIVMGR_MD_\".COLUMN_PRIVILEGES as pmcp "
+ "where pmcp.OBJECT_UID = mob.OBJECT_UID "
+ "and pmcp.OBJECT_UID = mco.OBJECT_UID "
+ "and pmcp.COLUMN_NUMBER = mco.COLUMN_NUMBER "
+ "and mco.COLUMN_NAME <> 'SYSKEY' "
+ "and (mob.CATALOG_NAME = '%s' or trim(mob.CATALOG_NAME) LIKE '%s' ESCAPE '\\') "
+ "and (mob.SCHEMA_NAME = '%s' or trim(mob.SCHEMA_NAME) LIKE '%s' ESCAPE '\\') "
+ "and (mob.OBJECT_NAME = '%s' or trim(mob.OBJECT_NAME) LIKE '%s' ESCAPE '\\') "
+ "and (mco.COLUMN_NAME = '%s' or trim(mco.COLUMN_NAME) LIKE '%s' ESCAPE '\\') "
+ "order by pmcp.COLUMN_NUMBER;",
+ inputParam[0], inputParam[1],
+ inputParam[2], inputParam[3],
+ inputParam[4], inputParam[5],
+ inputParam[6], inputParam[7]);
+
+ break;
default :
exception_->exception_nr = odbc_SQLSvc_GetSQLCatalogs_ParamError_exn_;
exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_UNSUPPORTED_SMD_API_TYPE;
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
index 6b4c5eb..c26fbbb 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
@@ -353,10 +353,6 @@
if (errorMsg)
*errorMsg = '\0';
- //if (targetPrecision < 19)
- if(((SQLDataType == SQLTYPECODE_NUMERIC) && (targetPrecision <= 18)) ||
- ((SQLDataType == SQLTYPECODE_NUMERIC_UNSIGNED) && (targetPrecision <= 9)))
- getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
switch (ODBCDataType)
{
@@ -850,6 +846,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -943,6 +940,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -1539,6 +1537,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -1595,6 +1594,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -1704,6 +1704,7 @@
integralPart = (integralPart < 0)? -integralPart: integralPart;
decimalPart = 0;
leadZeros = 0;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ( integralPart > integralMax )
return IDS_22_003;
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index 2bfbfcb..00ae7b2 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -1028,9 +1028,10 @@
SQLSTATS_DESC_REPLICATOR_STATS = 20,
SQLSTATS_DESC_FAST_EXTRACT_STATS = 21,
SQLSTATS_DESC_REORG_STATS = 22,
+ SQLSTATS_DESC_SE_STATS = 23,
SQLSTATS_DESC_HDFSSCAN_STATS = 23,
- SQLSTATS_DESC_HBASE_ACCESS_STATS = 24,
- SQLSTATS_DESC_PROCESS_STATS = 25
+ SQLSTATS_DESC_HBASE_ACCESS_STATS = 23,
+ SQLSTATS_DESC_PROCESS_STATS = 25,
};
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index 49261a6..435dfb5 100644
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -2128,6 +2128,7 @@
GET_PROCESS_STATS_ENTRY_,
FORMAT_AND_RETURN_PROCESS_STATS_,
GET_HBASE_STATS_ENTRY_,
+ GET_SE_STATS_ENTRY_ = GET_HBASE_STATS_ENTRY_,
DISPLAY_HBASE_STATS_HEADING_,
FORMAT_AND_RETURN_HBASE_STATS_,
GET_HIVE_STATS_ENTRY_,
@@ -2812,6 +2813,8 @@
virtual short work();
virtual ~ExExeUtilLobExtractTcb();
virtual void freeResources();
+ virtual ExOperStats *doAllocateStatsEntry(CollHeap *heap,
+ ComTdb *tdb);
ExExeUtilLobExtractTdb & lobTdb() const
{
@@ -2921,6 +2924,8 @@
virtual short work();
virtual ~ExExeUtilLobUpdateTcb();
virtual void freeResources();
+ virtual ExOperStats *doAllocateStatsEntry(CollHeap *heap,
+ ComTdb *tdb);
ExExeUtilLobUpdateTdb & lobTdb() const
{
return (ExExeUtilLobUpdateTdb &) tdb;
@@ -2997,6 +3002,8 @@
const ex_tcb * child_tcb,
ex_globals * glob = 0);
+ virtual ExOperStats *doAllocateStatsEntry(CollHeap *heap,
+ ComTdb *tdb);
virtual short work();
private:
diff --git a/core/sql/executor/ExExeUtilGetStats.cpp b/core/sql/executor/ExExeUtilGetStats.cpp
index a8a128d..ead8cfd 100644
--- a/core/sql/executor/ExExeUtilGetStats.cpp
+++ b/core/sql/executor/ExExeUtilGetStats.cpp
@@ -1920,12 +1920,9 @@
case SQLSTATS_DESC_UDR_BASE_STATS:
step_ = GET_UDR_BASE_STATS_ENTRY_;
break;
- case SQLSTATS_DESC_HBASE_ACCESS_STATS:
+ case SQLSTATS_DESC_SE_STATS:
step_ = GET_HBASE_STATS_ENTRY_;
break;
- case SQLSTATS_DESC_HDFSSCAN_STATS:
- step_ = GET_HIVE_STATS_ENTRY_;
- break;
default:
step_ = GET_NEXT_STATS_DESC_ENTRY_;
break;
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 960c31f..7c051c4 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -2563,6 +2563,7 @@
if (lobHandle_ and lobName_)
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -2590,6 +2591,23 @@
freeResources();
}
+ExOperStats * ExExeUtilLobExtractTcb::doAllocateStatsEntry(CollHeap *heap,
+ ComTdb *tdb)
+{
+ ExEspStmtGlobals *espGlobals = getGlobals()->castToExExeStmtGlobals()->castToExEspStmtGlobals();
+ StmtStats *ss;
+ if (espGlobals != NULL)
+ ss = espGlobals->getStmtStats();
+ else
+ ss = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals()->getStatement()->getStmtStats();
+ ExHdfsScanStats *hdfsScanStats = new(heap) ExHdfsScanStats(heap,
+ this,
+ tdb);
+ if (ss != NULL)
+ hdfsScanStats->setQueryId(ss->getQueryId(), ss->getQueryIdLen());
+ return hdfsScanStats;
+}
+
short ExExeUtilLobExtractTcb::work()
{
Lng32 cliRC = 0;
@@ -3023,6 +3041,7 @@
if(lobTdb().appendOrCreate())
tgtFlags = Lob_Append_Or_Create;
retcode = ExpLOBInterfaceSelect(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3067,6 +3086,7 @@
{
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3117,6 +3137,7 @@
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3186,6 +3207,7 @@
{
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3334,6 +3356,23 @@
exLobGlobals_ = NULL;
}
+ExOperStats * ExExeUtilLobUpdateTcb::doAllocateStatsEntry(CollHeap *heap,
+ ComTdb *tdb)
+{
+ ExEspStmtGlobals *espGlobals = getGlobals()->castToExExeStmtGlobals()->castToExEspStmtGlobals();
+ StmtStats *ss;
+ if (espGlobals != NULL)
+ ss = espGlobals->getStmtStats();
+ else
+ ss = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals()->getStatement()->getStmtStats();
+ ExHdfsScanStats *hdfsScanStats = new(heap) ExHdfsScanStats(heap,
+ this,
+ tdb);
+ if (ss != NULL)
+ hdfsScanStats->setQueryId(ss->getQueryId(), ss->getQueryIdLen());
+ return hdfsScanStats;
+}
+
short ExExeUtilLobUpdateTcb::work()
{
Lng32 cliRC = 0;
@@ -3467,6 +3506,7 @@
}
}
retcode = ExpLOBInterfaceUpdate(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobTdb().getLobHdfsServer(),
lobTdb().getLobHdfsPort(),
lobName_,
@@ -3550,6 +3590,7 @@
Int32 outHandleLen;
Int64 requestTag = 0;
retcode = ExpLOBInterfaceUpdateAppend(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobTdb().getLobHdfsServer(),
lobTdb().getLobHdfsPort(),
lobName_,
@@ -3635,6 +3676,7 @@
Int64 requestTag = 0;
retcode = ExpLOBInterfaceUpdate(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobTdb().getLobHdfsServer(),
lobTdb().getLobHdfsPort(),
lobName_,
@@ -3735,8 +3777,7 @@
return FALSE;
}
-ExOperStats * ExExeUtilFileExtractTcb::doAllocateStatsEntry(
- CollHeap *heap,
+ExOperStats * ExExeUtilFileExtractTcb::doAllocateStatsEntry(CollHeap *heap,
ComTdb *tdb)
{
ExEspStmtGlobals *espGlobals = getGlobals()->castToExExeStmtGlobals()->castToExEspStmtGlobals();
@@ -3745,7 +3786,6 @@
ss = espGlobals->getStmtStats();
else
ss = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals()->getStatement()->getStmtStats();
-
ExHdfsScanStats *hdfsScanStats = new(heap) ExHdfsScanStats(heap,
this,
tdb);
@@ -3811,6 +3851,7 @@
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3857,6 +3898,7 @@
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3914,6 +3956,7 @@
{
retcode = ExpLOBInterfaceSelectCursor
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -3943,7 +3986,7 @@
break;
}
- step_ = COLLECT_STATS_;
+ step_ = DONE_;
}
break;
@@ -3957,30 +4000,6 @@
}
break;
- case COLLECT_STATS_:
- {
- if (! getStatsEntry())
- {
- step_ = DONE_;
- break;
- }
-
- ExHdfsScanStats * stats =
- getStatsEntry()->castToExHdfsScanStats();
-
- retcode = ExpLOBinterfaceStats
- (lobGlobs,
- stats->lobStats(),
- lobName_,
- lobLoc_,
- lobType_,
- lobTdb().getLobHdfsServer(),
- lobTdb().getLobHdfsPort());
-
- step_ = DONE_;
- }
- break;
-
case DONE_:
{
retcode = handleDone();
@@ -4006,6 +4025,23 @@
{
}
+ExOperStats * ExExeUtilFileLoadTcb::doAllocateStatsEntry(CollHeap *heap,
+ ComTdb *tdb)
+{
+ ExEspStmtGlobals *espGlobals = getGlobals()->castToExExeStmtGlobals()->castToExEspStmtGlobals();
+ StmtStats *ss;
+ if (espGlobals != NULL)
+ ss = espGlobals->getStmtStats();
+ else
+ ss = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals()->getStatement()->getStmtStats();
+ ExHdfsScanStats *hdfsScanStats = new(heap) ExHdfsScanStats(heap,
+ this,
+ tdb);
+ if (ss != NULL)
+ hdfsScanStats->setQueryId(ss->getQueryId(), ss->getQueryIdLen());
+ return hdfsScanStats;
+}
+
short ExExeUtilFileLoadTcb::work()
{
Lng32 cliRC = 0;
@@ -4162,6 +4198,7 @@
Int64 dummy;
retcode = ExpLOBInterfaceInsert
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
@@ -4204,6 +4241,7 @@
{
retcode = ExpLOBinterfaceCloseFile
(lobGlobs,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName_,
lobLoc_,
lobType_,
diff --git a/core/sql/executor/ExFastTransport.cpp b/core/sql/executor/ExFastTransport.cpp
index 7849746..a2eaa94 100644
--- a/core/sql/executor/ExFastTransport.cpp
+++ b/core/sql/executor/ExFastTransport.cpp
@@ -422,7 +422,16 @@
if (statsType == ComTdb::OPERATOR_STATS)
{
- return ex_tcb::doAllocateStatsEntry(heap, tdb);;
+ ExEspStmtGlobals *espGlobals = getGlobals()->castToExExeStmtGlobals()->castToExEspStmtGlobals();
+ StmtStats *ss;
+ if (espGlobals != NULL)
+ ss = espGlobals->getStmtStats();
+ else
+ ss = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals()->getStatement()->getStmtStats();
+ ExHdfsScanStats *hdfsScanStats = new (heap) ExHdfsScanStats(heap, this, tdb);
+ if (ss != NULL)
+ hdfsScanStats->setQueryId(ss->getQueryId(), ss->getQueryIdLen());
+ return hdfsScanStats;
}
else
{
@@ -622,6 +631,7 @@
ExOperStats *stats = NULL;
ExFastExtractStats *feStats = getFastExtractStats();
+ ExHdfsScanStats *hdfsStats = getHdfsScanStats();
while (TRUE)
{
@@ -790,7 +800,7 @@
}
else if (!isSequenceFile() && hdfsClient_ == NULL)
{
- hdfsClient_ = HdfsClient::newInstance((NAHeap *)getHeap(), NULL, hdfsClientRetCode);
+ hdfsClient_ = HdfsClient::newInstance((NAHeap *)getHeap(), (ExHdfsScanStats *)getHdfsScanStats(), hdfsClientRetCode);
if (hdfsClientRetCode != HDFS_CLIENT_OK)
{
createHdfsClientFileError(hdfsClientRetCode);
@@ -978,6 +988,10 @@
{
feStats->incProcessedRowsCount();
}
+ if (hdfsStats != NULL) {
+ hdfsStats->incUsedRows();
+ hdfsStats->incAccessedRows();
+ }
pstate.successRowCount_ ++;
}
else
@@ -986,6 +1000,8 @@
{
feStats->incErrorRowsCount();
}
+ if (hdfsStats != NULL)
+ hdfsStats->incAccessedRows();
pstate.errorRowCount_ ++;
}
if (currBuffer_->bytesLeft_ < (Int32) maxExtractRowLength_)
@@ -1243,7 +1259,6 @@
g->setRowsAffected(privateState.matchCount_);
}
-
//
// Insert into up queue
qParent_.up->insert();
diff --git a/core/sql/executor/ExFastTransport.h b/core/sql/executor/ExFastTransport.h
index 5bf1219..37d7875 100644
--- a/core/sql/executor/ExFastTransport.h
+++ b/core/sql/executor/ExFastTransport.h
@@ -327,6 +327,14 @@
return NULL;
}
+ ExHdfsScanStats * getHdfsScanStats()
+ {
+ if (getStatsEntry())
+ return getStatsEntry()->castToExHdfsScanStats();
+ else
+ return NULL;
+ }
+
protected:
@@ -359,6 +367,7 @@
NABoolean endOfData_;
CollHeap *heap_;
ExFastExtractStats *feStats_;
+ ExHdfsScanStats *hdfsStats_;
time_t tstart_;
diff --git a/core/sql/executor/ExHbaseAccess.h b/core/sql/executor/ExHbaseAccess.h
index 7be1551..071b8c0 100644
--- a/core/sql/executor/ExHbaseAccess.h
+++ b/core/sql/executor/ExHbaseAccess.h
@@ -47,7 +47,6 @@
// Classes referenced in this file
// -----------------------------------------------------------------------
class ex_tcb;
-class ExHbaseAccessStats;
class ExpHbaseInterface;
class ExHbaseAccessSelectTcb;
class ExHbaseAccessUMDTcb;
diff --git a/core/sql/executor/ExHbaseIUD.cpp b/core/sql/executor/ExHbaseIUD.cpp
index 6a52457..bad439d 100644
--- a/core/sql/executor/ExHbaseIUD.cpp
+++ b/core/sql/executor/ExHbaseIUD.cpp
@@ -34,6 +34,7 @@
#include "ExHdfsScan.h"
#include "Context.h"
#include "HdfsClient_JNI.h"
+#include "ExStats.h"
ExHbaseAccessInsertTcb::ExHbaseAccessInsertTcb(
const ExHbaseAccessTdb &hbaseAccessTdb,
@@ -1012,8 +1013,7 @@
break;
}
if (getHbaseAccessStats()) {
- getHbaseAccessStats()->lobStats()->numReadReqs++;
- getHbaseAccessStats()->incUsedRows(numRowsInVsbbBuffer_);
+ getHbaseAccessStats()->incUsedRows((Int64)numRowsInVsbbBuffer_);
}
rowsInserted_ += numRowsInVsbbBuffer_;
if (asyncOperation_) {
@@ -1611,7 +1611,6 @@
if (getHbaseAccessStats())
{
- getHbaseAccessStats()->lobStats()->numReadReqs++;
getHbaseAccessStats()->incUsedRows(numRowsInVsbbBuffer_);
}
@@ -4247,7 +4246,6 @@
break;
}
if (getHbaseAccessStats()) {
- getHbaseAccessStats()->lobStats()->numReadReqs++;
getHbaseAccessStats()->incUsedRows(numRowsInVsbbBuffer_);
}
step_ = RS_CLOSE;
@@ -4271,10 +4269,6 @@
}
step_ = NEXT_ROW;
- if (getHbaseAccessStats())
- {
- getHbaseAccessStats()->lobStats()->numReadReqs++;
- }
}
else
step_ = SETUP_SELECT;
@@ -4345,7 +4339,6 @@
break;
}
if (getHbaseAccessStats()) {
- getHbaseAccessStats()->lobStats()->numReadReqs++;
getHbaseAccessStats()->incUsedRows(numRowsInVsbbBuffer_);
}
step_ = RS_CLOSE;
@@ -4385,7 +4378,6 @@
if (step_ == HANDLE_ERROR)
break;
if (getHbaseAccessStats()) {
- getHbaseAccessStats()->lobStats()->numReadReqs++;
getHbaseAccessStats()->incUsedRows(numRowsInVsbbBuffer_);
}
step_ = RS_CLOSE;
diff --git a/core/sql/executor/ExHdfsScan.cpp b/core/sql/executor/ExHdfsScan.cpp
index 4db5a1d..b09cffd 100644
--- a/core/sql/executor/ExHdfsScan.cpp
+++ b/core/sql/executor/ExHdfsScan.cpp
@@ -771,6 +771,7 @@
openType = 2; // must open
retcode = ExpLOBInterfaceSelectCursor
(lobGlob_,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
hdfsFileName_, //hdfsScanTdb().hdfsFileName_,
NULL, //(char*)"",
(Lng32)Lob_External_HDFS_File,
@@ -830,6 +831,7 @@
retcode = ExpLOBInterfaceSelectCursor
(lobGlob_,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
hdfsFileName_, //hdfsScanTdb().hdfsFileName_,
NULL, //(char*)"",
(Lng32)Lob_External_HDFS_File,
@@ -940,6 +942,7 @@
Int32 hdfsErrorDetail = 0;///this is the errno returned from the underlying hdfs call.
retcode = ExpLOBInterfaceSelectCursor
(lobGlob_,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
hdfsFileName_,
NULL,
(Lng32)Lob_External_HDFS_File,
@@ -1511,6 +1514,7 @@
{
retcode = ExpLOBInterfaceSelectCursor
(lobGlob_,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
hdfsFileName_,
NULL,
(Lng32)Lob_External_HDFS_File,
@@ -1640,29 +1644,6 @@
case CLOSE_FILE:
case ERROR_CLOSE_FILE:
{
- if (getStatsEntry())
- {
- ExHdfsScanStats * stats =
- getStatsEntry()->castToExHdfsScanStats();
-
- if (stats)
- {
- ExLobStats s;
- s.init();
-
- retcode = ExpLOBinterfaceStats
- (lobGlob_,
- &s,
- hdfsFileName_, //hdfsScanTdb().hdfsFileName_,
- NULL, //(char*)"",
- (Lng32)Lob_External_HDFS_File,
- hdfsScanTdb().hostName_,
- hdfsScanTdb().port_);
-
- *stats->lobStats() = *stats->lobStats() + s;
- }
- }
-
// if next file is not same as current file, then close the current file.
bool closeFile = true;
@@ -1679,6 +1660,7 @@
{
retcode = ExpLOBinterfaceCloseFile
(lobGlob_,
+ (getStatsEntry() != NULL ? getStatsEntry()->castToExHdfsScanStats() : NULL),
hdfsFileName_,
NULL,
(Lng32)Lob_External_HDFS_File,
diff --git a/core/sql/executor/ExHdfsScan.h b/core/sql/executor/ExHdfsScan.h
index 371b6b5..a9bd86e 100644
--- a/core/sql/executor/ExHdfsScan.h
+++ b/core/sql/executor/ExHdfsScan.h
@@ -50,7 +50,6 @@
// Classes referenced in this file
// -----------------------------------------------------------------------
class ex_tcb;
-class ExHdfsScanStats;
class SequenceFileReader;
class ExpORCinterface;
diff --git a/core/sql/executor/ExStats.cpp b/core/sql/executor/ExStats.cpp
index 663d2bf..d5aaf9f 100644
--- a/core/sql/executor/ExStats.cpp
+++ b/core/sql/executor/ExStats.cpp
@@ -62,6 +62,7 @@
#include "ComTdbExeUtil.h"
#include "ComTdbHdfsScan.h"
#include "ComTdbHbaseAccess.h"
+#include "ComTdbFastTransport.h"
#include "ex_exe_stmt_globals.h"
#include "exp_clause_derived.h"
#include "Int64.h"
@@ -1314,10 +1315,6 @@
case SQLSTATS_DOP:
sqlStats_item->int64_value = dop_;
break;
- case SQLSTATS_DETAIL:
- if (sqlStats_item->str_value != NULL)
- sqlStats_item->str_ret_len = 0;
- break;
default:
sqlStats_item->error_code = -EXE_STAT_NOT_FOUND;
break;
@@ -1761,11 +1758,8 @@
case BMO_STATS:
merge((ExBMOStats *)other);
break;
- case HBASE_ACCESS_STATS:
- merge((ExHbaseAccessStats *)other);
- break;
- case HDFSSCAN_STATS:
- merge((ExHdfsScanStats *)other);
+ case SE_STATS:
+ merge((ExStorageEngineStats *)other);
break;
default:
// do nothing - This type of stat has no merge data
@@ -1815,11 +1809,11 @@
case 1:
return "OperCpuTime";
case 2:
- return "CpuTime";
+ return "messageBytes";
case 3:
- return "waitTime";
+ return "messageCount";
case 4:
- return "Timestamp";
+ return "memoryAllocated";
}
return NULL;
}
@@ -1831,11 +1825,11 @@
case 1:
return ExOperStats::getNumVal(i);
case 2:
- return cpuTime_ + espCpuTime_;
+ return reqMsgBytes_ + replyMsgBytes_;
case 3:
- return ((ExFragRootOperStats *)this)->getAvgWaitTime();
+ return reqMsgCnt_ + replyMsgCnt_;
case 4:
- return timestamp_;
+ return heapAlloc_+espHeapAlloc_+spaceAlloc_+espSpaceAlloc_;
}
return 0;
}
@@ -1921,24 +1915,7 @@
{
char tmpBuf[100];
Int32 len;
- if (sqlStats_item->statsItem_id == SQLSTATS_DETAIL)
- {
- if (sqlStats_item->str_value != NULL)
- {
- sprintf(tmpBuf, "%ld",
- cpuTime_ + espCpuTime_);
- len = str_len(tmpBuf);
- if (len > sqlStats_item->str_max_len)
- sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
- else
- str_cpy(sqlStats_item->str_value, tmpBuf, len);
- sqlStats_item->str_ret_len = len;
- }
- return 0;
- }
- ExOperStats::getStatsItem(sqlStats_item);
- if(sqlStats_item -> error_code == -EXE_STAT_NOT_FOUND)
- {
+ Lng32 retcode = 0;
sqlStats_item->error_code = 0;
switch (sqlStats_item->statsItem_id)
{
@@ -2020,12 +1997,25 @@
case SQLSTATS_SQL_MAX_WAIT_TIME:
sqlStats_item->int64_value = maxWaitTime_;
break;
+ case SQLSTATS_DETAIL:
+ if (sqlStats_item->str_value != NULL)
+ {
+ sprintf(tmpBuf, "%ld|%ld|%ld|%ld|",
+ cpuTime_ + espCpuTime_, getNumVal(2), getNumVal(3), getNumVal(4));
+ len = strlen(tmpBuf);
+
+ if (len > sqlStats_item->str_max_len)
+ sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
+ else
+ str_cpy(sqlStats_item->str_value, tmpBuf, len);
+ sqlStats_item->str_ret_len = len;
+ }
+ break;
default:
- sqlStats_item->error_code = -EXE_STAT_NOT_FOUND;
- break;
+ retcode = ExOperStats::getStatsItem(sqlStats_item);
+ break;
}
- }
- return 0;
+ return retcode;
}
NABoolean ExFragRootOperStats::filterForCpuStats()
@@ -2045,10 +2035,10 @@
}
//////////////////////////////////////////////////////////////////
-// class ExHdfsScanStats
+// class ExStorageEngineStats
//////////////////////////////////////////////////////////////////
-ExHdfsScanStats::ExHdfsScanStats(NAMemory * heap,
+ExStorageEngineStats::ExStorageEngineStats(NAMemory * heap,
ex_tcb *tcb,
ComTdb * tdb)
: ExOperStats(heap,
@@ -2057,10 +2047,32 @@
tdb)
, timer_(CLOCK_MONOTONIC)
{
- ComTdbHdfsScan *hdfsTdb = (ComTdbHdfsScan *) tdb;
-
+ const char * name;
+ switch (tdb->getNodeType())
+ {
+ case ComTdb::ex_HBASE_ACCESS:
+ {
+ ComTdbHbaseAccess *hbaseTdb = (ComTdbHbaseAccess *) tdb;
+ name = hbaseTdb->getTableName();
+ break;
+ }
+ case ComTdb::ex_HDFS_SCAN:
+ {
+ ComTdbHdfsScan *hdfsTdb = (ComTdbHdfsScan *) tdb;
+ name = hdfsTdb->tableName();
+ break;
+ }
+ case ComTdb::ex_FAST_EXTRACT:
+ {
+ ComTdbFastExtract *feTdb = (ComTdbFastExtract *)tdb;
+ name = feTdb->getTargetName();
+ break;
+ }
+ default:
+ name = "";
+ }
+
// allocate memory and copy the ansi name into the stats entry
- const char * name = hdfsTdb->tableName();
Lng32 len = (Lng32)str_len(name);
tableName_ = (char *)heap_->allocateMemory(len + 1);
sprintf(tableName_, "%s", name);
@@ -2070,9 +2082,9 @@
init(FALSE);
}
-ExHdfsScanStats::ExHdfsScanStats(NAMemory * heap)
+ExStorageEngineStats::ExStorageEngineStats(NAMemory * heap)
: ExOperStats(heap,
- HDFSSCAN_STATS)
+ SE_STATS)
, tableName_(NULL)
, timer_(CLOCK_MONOTONIC)
{
@@ -2081,22 +2093,20 @@
init(FALSE);
}
-void ExHdfsScanStats::init(NABoolean resetDop)
+void ExStorageEngineStats::init(NABoolean resetDop)
{
ExOperStats::init(resetDop);
timer_.reset();
- lobStats_.init();
-
numBytesRead_ = 0;
accessedRows_ = 0;
usedRows_ = 0;
- numHdfsCalls_ = 0;
- maxHdfsIOTime_ = 0;
+ numIOCalls_ = 0;
+ maxIOTime_ = 0;
blockTime_ = 0;
}
-ExHdfsScanStats::~ExHdfsScanStats()
+ExStorageEngineStats::~ExStorageEngineStats()
{
if (tableName_ != NULL)
{
@@ -2110,19 +2120,18 @@
}
}
-UInt32 ExHdfsScanStats::packedLength()
+UInt32 ExStorageEngineStats::packedLength()
{
UInt32 size = ExOperStats::packedLength();
size += sizeof(timer_);
- size += sizeof(lobStats_);
advanceSize2(size, tableName_);
size += sizeof(numBytesRead_);
size += sizeof(accessedRows_);
size += sizeof(usedRows_);
- size += sizeof(numHdfsCalls_);
- size += sizeof(maxHdfsIOTime_);
+ size += sizeof(numIOCalls_);
+ size += sizeof(maxIOTime_);
if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
{
size += sizeof(blockTime_);
@@ -2132,20 +2141,19 @@
return size;
}
-UInt32 ExHdfsScanStats::pack(char *buffer)
+UInt32 ExStorageEngineStats::pack(char *buffer)
{
UInt32 size = ExOperStats::pack(buffer);
buffer += size;
size += packIntoBuffer(buffer, timer_);
- size += packIntoBuffer(buffer, lobStats_);
size += packCharStarIntoBuffer(buffer, tableName_);
size += packIntoBuffer(buffer, numBytesRead_);
size += packIntoBuffer(buffer, accessedRows_);
size += packIntoBuffer(buffer, usedRows_);
- size += packIntoBuffer(buffer, numHdfsCalls_);
- size += packIntoBuffer(buffer, maxHdfsIOTime_);
+ size += packIntoBuffer(buffer, numIOCalls_);
+ size += packIntoBuffer(buffer, maxIOTime_);
if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
{
size += packIntoBuffer(buffer, blockTime_);
@@ -2157,20 +2165,19 @@
return size;
}
-void ExHdfsScanStats::unpack(const char* &buffer)
+void ExStorageEngineStats::unpack(const char* &buffer)
{
ExOperStats::unpack(buffer);
unpackBuffer(buffer, timer_);
- unpackBuffer(buffer, lobStats_);
unpackBuffer(buffer, tableName_, heap_);
unpackBuffer(buffer, numBytesRead_);
unpackBuffer(buffer, accessedRows_);
unpackBuffer(buffer, usedRows_);
- unpackBuffer(buffer, numHdfsCalls_);
- unpackBuffer(buffer, maxHdfsIOTime_);
+ unpackBuffer(buffer, numIOCalls_);
+ unpackBuffer(buffer, maxIOTime_);
if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
{
unpackBuffer(buffer, blockTime_);
@@ -2184,20 +2191,19 @@
}
}
-void ExHdfsScanStats::merge(ExHdfsScanStats *other)
+void ExStorageEngineStats::merge(ExStorageEngineStats *other)
{
ExOperStats::merge(other);
timer_ = timer_ + other->timer_;
- lobStats_ = lobStats_ + other->lobStats_;
numBytesRead_ += other->numBytesRead_;
accessedRows_ += other->accessedRows_;
usedRows_ += other->usedRows_;
- numHdfsCalls_ += other->numHdfsCalls_;
- if (maxHdfsIOTime_ < other->maxHdfsIOTime_) // take the larger value
- maxHdfsIOTime_ = other->maxHdfsIOTime_;
+ numIOCalls_ += other->numIOCalls_;
+ if (maxIOTime_ < other->maxIOTime_) // take the larger value
+ maxIOTime_ = other->maxIOTime_;
}
-void ExHdfsScanStats::copyContents(ExHdfsScanStats *other)
+void ExStorageEngineStats::copyContents(ExStorageEngineStats *other)
{
ExOperStats::copyContents(other);
@@ -2211,12 +2217,11 @@
}
timer_ = other->timer_;
- lobStats_ = other->lobStats_;
numBytesRead_ = other->numBytesRead_;
accessedRows_ = other->accessedRows_;
usedRows_ = other->usedRows_;
- numHdfsCalls_ = other->numHdfsCalls_;
- maxHdfsIOTime_ = other->maxHdfsIOTime_;
+ numIOCalls_ = other->numIOCalls_;
+ maxIOTime_ = other->maxIOTime_;
if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
{
blockTime_ = other->blockTime_;
@@ -2237,9 +2242,9 @@
}
}
-ExOperStats * ExHdfsScanStats::copyOper(NAMemory * heap)
+ExOperStats * ExStorageEngineStats::copyOper(NAMemory * heap)
{
- ExHdfsScanStats *stat = new(heap) ExHdfsScanStats(heap);
+ ExStorageEngineStats *stat = new(heap) ExStorageEngineStats(heap);
stat->copyContents(this);
return stat;
}
@@ -2250,23 +2255,29 @@
return this;
}
-const char *ExHdfsScanStats::getNumValTxt(Int32 i) const
+ExHbaseAccessStats
+*ExHdfsScanStats::castToExHbaseAccessStats()
+{
+ return this;
+}
+
+const char *ExStorageEngineStats::getNumValTxt(Int32 i) const
{
switch (i)
{
case 1:
return "OperCpuTime";
case 2:
- return "BytesRead";
+ return "SE_IO_KBytes";
case 3:
- return "TimeWaitingOnHdfs";
+ return "SE_IO_SumTime";
case 4:
- return "AccessedRows";
+ return "ActRowsAccessed";
}
return NULL;
}
-Int64 ExHdfsScanStats::getNumVal(Int32 i) const
+Int64 ExStorageEngineStats::getNumVal(Int32 i) const
{
switch (i)
{
@@ -2282,7 +2293,7 @@
return 0;
}
-NABoolean ExHdfsScanStats::filterForSEstats(struct timespec currTimespec, Lng32 filter)
+NABoolean ExStorageEngineStats::filterForSEstats(struct timespec currTimespec, Lng32 filter)
{
Int64 sumIOTime;
@@ -2299,7 +2310,7 @@
return FALSE;
}
-void ExHdfsScanStats::getVariableStatsInfo(char * dataBuffer,
+void ExStorageEngineStats::getVariableStatsInfo(char * dataBuffer,
char * dataLen,
Lng32 maxLen)
{
@@ -2315,26 +2326,28 @@
{
ExOperStats::getVariableStatsInfo(dataBuffer, dataLen, maxLen);
buf += *((short *) dataLen);
-
- lobStats()->getVariableStatsInfo(buf, dataLen, maxLen);
- buf += *((short *) dataLen);
}
sprintf (buf,
- "AnsiName: %s MessagesBytes: %ld AccessedRows: %ld UsedRows: %ld HiveIOCalls: %ld HiveSumIOTime: %ld HdfsMaxIOTime: %ld",
+ "AnsiName: %s MessagesBytes: %ld AccessedRows: %ld UsedRows: %ld HiveIOCalls: %ld HiveSumIOTime: %ld HdfsMaxIOTime: %ld "
+ "HbaseSumIOCalls: %ld HbaseSumIOTime: %ld HbaseMaxIOTime: %ld ",
+
(char*)tableName_,
numBytesRead(),
rowsAccessed(),
rowsUsed(),
- numHdfsCalls_,
+ numIOCalls_,
timer_.getTime(),
- maxHdfsIOTime_
+ maxIOTime_,
+ hbaseCalls(),
+ timer_.getTime(),
+ maxHbaseIOTime()
);
buf += str_len(buf);
*(short*)dataLen = (short) (buf - dataBuffer);
}
-Lng32 ExHdfsScanStats::getStatsItem(SQLSTATS_ITEM* sqlStats_item)
+Lng32 ExStorageEngineStats::getStatsItem(SQLSTATS_ITEM* sqlStats_item)
{
sqlStats_item->error_code = 0;
Int32 len;
@@ -2374,409 +2387,20 @@
sqlStats_item->int64_value = usedRows_;
break;
case SQLSTATS_HIVE_IOS:
- sqlStats_item->int64_value = numHdfsCalls_;
+ case SQLSTATS_HBASE_IOS:
+ sqlStats_item->int64_value = numIOCalls_;
break;
case SQLSTATS_HIVE_IO_BYTES:
- sqlStats_item->int64_value = numBytesRead_;
- break;
- case SQLSTATS_HIVE_IO_ELAPSED_TIME:
- sqlStats_item->int64_value = timer_.getTime();
- break;
- case SQLSTATS_HIVE_IO_MAX_TIME:
- sqlStats_item->int64_value = maxHdfsIOTime();
- break;
- case SQLSTATS_DETAIL:
- if (sqlStats_item->str_value != NULL)
- {
- if (tableName_ != NULL)
- {
- len = str_len(tableName_);
- if (len > sqlStats_item->str_max_len)
- {
- sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
- str_cpy_all(sqlStats_item->str_value, tableName_, sqlStats_item->str_max_len);
- }
- else
- str_cpy_all(sqlStats_item->str_value, tableName_, len);
- }
- else
- len = 0;
- sprintf(tmpBuf, "|%ld|%ld", accessedRows_,
- numBytesRead_);
- len1 = str_len(tmpBuf);
- if ((len+len1) > sqlStats_item->str_max_len)
- sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
- else
- str_cpy(sqlStats_item->str_value+len, tmpBuf, len1);
- sqlStats_item->str_ret_len = len+len1;
- }
- break;
- default:
- ExOperStats::getStatsItem(sqlStats_item);
- break;
- }
- return 0;
-}
-
-
-//////////////////////////////////////////////////////////////////
-// class ExHbaseAccessStats
-//////////////////////////////////////////////////////////////////
-
-ExHbaseAccessStats::ExHbaseAccessStats(NAMemory * heap,
- ex_tcb *tcb,
- ComTdb * tdb)
- : ExOperStats(heap,
- HBASE_ACCESS_STATS,
- tcb,
- tdb)
- , timer_(CLOCK_MONOTONIC)
-{
- ComTdbHbaseAccess *hbaseTdb = (ComTdbHbaseAccess *) tdb;
-
- if (hbaseTdb->getTableName())
- {
- // allocate memory and copy the ansi name into the stats entry
- const char * name = hbaseTdb->getTableName();
- Lng32 len = (Lng32)str_len(name);
- tableName_ = (char *)heap_->allocateMemory(len + 1);
- sprintf(tableName_, "%s", name);
- }
- else
- {
- tableName_ = NULL;
- }
- queryId_ = NULL;
- queryIdLen_ = 0;
- init(FALSE);
-}
-
-ExHbaseAccessStats::ExHbaseAccessStats(NAMemory * heap)
- : ExOperStats(heap,
- HBASE_ACCESS_STATS)
- , tableName_(NULL)
- , timer_(CLOCK_MONOTONIC)
-{
- queryId_ = NULL;
- queryIdLen_ = 0;
- init(FALSE);
-}
-
-void ExHbaseAccessStats::init(NABoolean resetDop)
-{
- ExOperStats::init(resetDop);
- timer_.reset();
-
- lobStats_.init();
-
- numBytesRead_ = 0;
- accessedRows_ = 0;
- usedRows_ = 0;
- numHbaseCalls_ = 0;
- maxHbaseIOTime_ = 0;
- blockTime_ = 0;
-}
-
-ExHbaseAccessStats::~ExHbaseAccessStats()
-{
- if (tableName_ != NULL)
- {
- NADELETEBASIC(tableName_,getHeap());
- tableName_ = NULL;
- }
- if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS && queryId_ != NULL)
- {
- NADELETEBASIC(queryId_, getHeap());
- queryId_ = NULL;
- }
-}
-
-UInt32 ExHbaseAccessStats::packedLength()
-{
- UInt32 size = ExOperStats::packedLength();
- size += sizeof(timer_);
- size += sizeof(lobStats_);
-
- advanceSize2(size, tableName_);
-
- size += sizeof(numBytesRead_);
- size += sizeof(accessedRows_);
- size += sizeof(usedRows_);
- size += sizeof(numHbaseCalls_);
- size += sizeof(maxHbaseIOTime_);
- if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
- {
- size += sizeof(blockTime_);
- size += sizeof(queryIdLen_);
- size += queryIdLen_;
- }
- return size;
-}
-
-UInt32 ExHbaseAccessStats::pack(char *buffer)
-{
- UInt32 size = ExOperStats::pack(buffer);
- buffer += size;
- size += packIntoBuffer(buffer, timer_);
- size += packIntoBuffer(buffer, lobStats_);
-
- size += packCharStarIntoBuffer(buffer, tableName_);
-
- size += packIntoBuffer(buffer, numBytesRead_);
- size += packIntoBuffer(buffer, accessedRows_);
- size += packIntoBuffer(buffer, usedRows_);
- size += packIntoBuffer(buffer, numHbaseCalls_);
- size += packIntoBuffer(buffer, maxHbaseIOTime_);
- if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
- {
- size += packIntoBuffer(buffer, blockTime_);
- size += packIntoBuffer(buffer, queryIdLen_);
- if (queryIdLen_ != 0 && queryId_ != NULL)
- size += packStrIntoBuffer(buffer, queryId_, queryIdLen_);
- }
-
- return size;
-}
-
-void ExHbaseAccessStats::unpack(const char* &buffer)
-{
- ExOperStats::unpack(buffer);
-
- unpackBuffer(buffer, timer_);
- unpackBuffer(buffer, lobStats_);
-
- unpackBuffer(buffer, tableName_, heap_);
-
- unpackBuffer(buffer, numBytesRead_);
- unpackBuffer(buffer, accessedRows_);
- unpackBuffer(buffer, usedRows_);
- unpackBuffer(buffer, numHbaseCalls_);
- unpackBuffer(buffer, maxHbaseIOTime_);
- if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
- {
- unpackBuffer(buffer, blockTime_);
- unpackBuffer(buffer, queryIdLen_);
- if (queryIdLen_ != 0)
- {
- queryId_ = new ((NAHeap *)(getHeap())) char[queryIdLen_+1];
- unpackStrFromBuffer(buffer, queryId_, queryIdLen_);
- queryId_[queryIdLen_] = '\0';
- }
- }
-}
-
-void ExHbaseAccessStats::merge(ExHbaseAccessStats *other)
-{
- ExOperStats::merge(other);
- timer_ = timer_ + other->timer_;
- lobStats_ = lobStats_ + other->lobStats_;
- numBytesRead_ += other->numBytesRead_;
- accessedRows_ += other->accessedRows_;
- usedRows_ += other->usedRows_;
- numHbaseCalls_ += other->numHbaseCalls_;
- if (maxHbaseIOTime_ < other->maxHbaseIOTime_) // take the larger value
- maxHbaseIOTime_ = other->maxHbaseIOTime_;
-}
-
-void ExHbaseAccessStats::copyContents(ExHbaseAccessStats *other)
-{
- ExOperStats::copyContents(other);
-
- // copy names only if we don't have one
- if (tableName_ == NULL && other->tableName_)
- {
- Lng32 len = (Lng32)str_len(other->tableName_);
- tableName_ = (char *)heap_->allocateMemory(len + 1);
- str_cpy_all(tableName_, other->tableName_, len);
- tableName_[len] = 0;
- }
-
- timer_ = other->timer_;
- lobStats_ = other->lobStats_;
- numBytesRead_ = other->numBytesRead_;
- accessedRows_ = other->accessedRows_;
- usedRows_ = other->usedRows_;
- numHbaseCalls_ = other->numHbaseCalls_;
- maxHbaseIOTime_ = other->maxHbaseIOTime_;
- if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
- {
- blockTime_ = other->blockTime_;
- queryIdLen_ = other->queryIdLen_;
- if (queryIdLen_ != 0)
- {
- queryId_ = new ((NAHeap *)(getHeap())) char[queryIdLen_+1];
- str_cpy_all(queryId_, other->queryId_, queryIdLen_);
- queryId_[queryIdLen_] = '\0';
- }
- else
- queryId_ = NULL;
- }
- else
- {
- queryId_ = other->queryId_;
- queryIdLen_ = other->queryIdLen_;
- }
-}
-
-ExOperStats * ExHbaseAccessStats::copyOper(NAMemory * heap)
-{
- ExHbaseAccessStats *stat = new(heap) ExHbaseAccessStats(heap);
- stat->copyContents(this);
- return stat;
-}
-
-ExHbaseAccessStats
-*ExHbaseAccessStats::castToExHbaseAccessStats()
-{
- return this;
-}
-
-const char *ExHbaseAccessStats::getNumValTxt(Int32 i) const
-{
- switch (i)
- {
- case 1:
- return "OperCpuTime";
- case 2:
- return "BytesRead";
- case 3:
- return "TimeWaitingOnHbase";
- case 4:
- return "AccessedRows";
- case 5:
- return "UsedRows";
- case 6:
- return "NumHbaseCalls";
- case 7:
- return "MaxHbaseIOTime";
- }
- return NULL;
-}
-
-Int64 ExHbaseAccessStats::getNumVal(Int32 i) const
-{
- switch (i)
- {
- case 1:
- return ExOperStats::getNumVal(i);
- case 2:
- return numBytesRead_;
- case 3:
- return timer_.getTime();
- case 4:
- return accessedRows_;
- case 5:
- return usedRows_;
- case 6:
- return numHbaseCalls_;
- case 7:
- return maxHbaseIOTime_;
- }
- return 0;
-}
-
-NABoolean ExHbaseAccessStats::filterForSEstats(struct timespec currTimespec, Lng32 filter)
-{
- Int64 sumIOTime;
- if (filter > 0) {
- blockTime_ = timer_.filterForSEstats(currTimespec);
- if (blockTime_ >= filter)
- return TRUE;
- }
- else
- if (queryId_ != NULL && (sumIOTime = timer_.getTime()) > 0 && (sumIOTime = sumIOTime /(1000000LL)) >= -filter) {
- blockTime_ = sumIOTime;
- return TRUE;
- }
- return FALSE;
-}
-
-
-void ExHbaseAccessStats::getVariableStatsInfo(char * dataBuffer,
- char * dataLen,
- Lng32 maxLen)
-{
- char *buf = dataBuffer;
- if ((Int32)getCollectStatsType() == SQLCLI_SE_OFFENDER_STATS)
- {
- sprintf(buf, "statsRowType: %d Qid: %s blockedFor: %d ",
- statType(),
- ((queryId_ != NULL) ? queryId_ : "NULL"), blockTime_);
- buf += str_len(buf);
- }
- else
- {
- ExOperStats::getVariableStatsInfo(dataBuffer, dataLen, maxLen);
- buf += *((short *) dataLen);
-
- lobStats()->getVariableStatsInfo(buf, dataLen, maxLen);
- buf += *((short *) dataLen);
- }
- sprintf (buf,
- "AnsiName: %s MessagesBytes: %ld AccessedRows: %ld UsedRows: %ld HbaseSumIOCalls: %ld HbaseSumIOTime: %ld HbaseMaxIOTime: %ld",
- (char*)tableName_,
- numBytesRead(),
- rowsAccessed(),
- rowsUsed(),
- hbaseCalls(),
- timer_.getTime(),
- maxHbaseIOTime()
- );
- buf += str_len(buf);
-
- *(short*)dataLen = (short) (buf - dataBuffer);
-}
-
-Lng32 ExHbaseAccessStats::getStatsItem(SQLSTATS_ITEM* sqlStats_item)
-{
- sqlStats_item->error_code = 0;
- Int32 len;
- Int32 len1;
- const char *tableName;
- char tmpBuf[100];
-
- switch (sqlStats_item->statsItem_id)
- {
- case SQLSTATS_TABLE_ANSI_NAME:
- if (sqlStats_item->str_value != NULL)
- {
- if (tableName_ != NULL)
- tableName = tableName_;
- else
- tableName = "NO_NAME_YET";
- len = str_len(tableName);
- if (len > sqlStats_item->str_max_len)
- {
- len = sqlStats_item->str_max_len;
- sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
- }
- str_cpy(sqlStats_item->str_value, tableName, len);
- sqlStats_item->str_ret_len = len;
- }
- break;
- case SQLSTATS_EST_ROWS_ACCESSED:
- sqlStats_item->double_value = getEstRowsAccessed();
- break;
- case SQLSTATS_EST_ROWS_USED:
- sqlStats_item->double_value = getEstRowsUsed();
- break;
- case SQLSTATS_ACT_ROWS_ACCESSED:
- sqlStats_item->int64_value = accessedRows_;
- break;
- case SQLSTATS_ACT_ROWS_USED:
- sqlStats_item->int64_value = usedRows_;
- break;
- case SQLSTATS_HBASE_IOS:
- sqlStats_item->int64_value = numHbaseCalls_;
- break;
case SQLSTATS_HBASE_IO_BYTES:
sqlStats_item->int64_value = numBytesRead_;
break;
+ case SQLSTATS_HIVE_IO_ELAPSED_TIME:
case SQLSTATS_HBASE_IO_ELAPSED_TIME:
sqlStats_item->int64_value = timer_.getTime();
break;
+ case SQLSTATS_HIVE_IO_MAX_TIME:
case SQLSTATS_HBASE_IO_MAX_TIME:
- sqlStats_item->int64_value = maxHbaseIOTime_;
+ sqlStats_item->int64_value = maxIOTime_;
break;
case SQLSTATS_DETAIL:
if (sqlStats_item->str_value != NULL)
@@ -2794,8 +2418,8 @@
}
else
len = 0;
- sprintf(tmpBuf, "|%ld|%ld", accessedRows_,
- numBytesRead_);
+
+ sprintf(tmpBuf, "|%ld|%ld|%ld", getNumVal(2), getNumVal(3), getNumVal(4));
len1 = str_len(tmpBuf);
if ((len+len1) > sqlStats_item->str_max_len)
sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
@@ -2810,7 +2434,7 @@
}
return 0;
}
-
+
//////////////////////////////////////////////////////////////////
// class ExProbeCacheStats
//////////////////////////////////////////////////////////////////
@@ -4783,7 +4407,7 @@
topN_ = other->topN_;
}
-void ExMeasStats::merge(ExHdfsScanStats* other)
+void ExMeasStats::merge(ExStorageEngineStats* other)
{
exeSEStats()->incAccessedRows(other->rowsAccessed());
exeSEStats()->incUsedRows(other->rowsUsed());
@@ -4792,15 +4416,6 @@
exeSEStats()->incMaxIOTime(other->maxHdfsIOTime());
}
-void ExMeasStats::merge(ExHbaseAccessStats* other)
-{
- exeSEStats()->incAccessedRows(other->rowsAccessed());
- exeSEStats()->incUsedRows(other->rowsUsed());
- exeSEStats()->incNumIOCalls(other->hbaseCalls());
- exeSEStats()->incNumIOBytes(other->numBytesRead());
- exeSEStats()->incMaxIOTime(other->maxHbaseIOTime());
-}
-
void ExMeasStats::merge(ExMeasStats* other)
{
ExMeasBaseStats::merge(other);
@@ -4866,11 +4481,9 @@
case BMO_STATS:
merge((ExBMOStats *)other);
break;
- case HDFSSCAN_STATS:
- merge((ExHdfsScanStats *)other);
+ case SE_STATS:
+ merge((ExStorageEngineStats *)other);
break;
- case HBASE_ACCESS_STATS:
- merge((ExHbaseAccessStats *)other);
break;
default:
// do nothing - This type of stat has no merge data
@@ -5475,11 +5088,8 @@
case ExOperStats::UDR_BASE_STATS:
NADELETE((ExUDRBaseStats *)stat, ExUDRBaseStats, heap_);
break;
- case ExOperStats::HDFSSCAN_STATS:
- NADELETE((ExHdfsScanStats *)stat, ExHdfsScanStats, heap_);
- break;
- case ExOperStats::HBASE_ACCESS_STATS:
- NADELETE((ExHbaseAccessStats *)stat, ExHbaseAccessStats, heap_);
+ case ExOperStats::SE_STATS:
+ NADELETE((ExStorageEngineStats *)stat, ExStorageEngineStats, heap_);
break;
default:
NADELETE(stat, ExOperStats, heap_);
@@ -5588,19 +5198,11 @@
return TRUE;
}
break;
- case ExOperStats::HDFSSCAN_STATS:
- if (stat->statType() == ExOperStats::HDFSSCAN_STATS
+ case ExOperStats::SE_STATS:
+ if (stat->statType() == ExOperStats::SE_STATS
&& stat->getPertableStatsId() == other->getPertableStatsId())
{
- ((ExHdfsScanStats *)stat)->merge((ExHdfsScanStats *)other);
- return TRUE;
- }
- break;
- case ExOperStats::HBASE_ACCESS_STATS:
- if (stat->statType() == ExOperStats::HBASE_ACCESS_STATS
- && stat->getPertableStatsId() == other->getPertableStatsId())
- {
- ((ExHbaseAccessStats *)stat)->merge((ExHbaseAccessStats *)other);
+ ((ExStorageEngineStats *)stat)->merge((ExStorageEngineStats *)other);
return TRUE;
}
break;
@@ -5644,11 +5246,8 @@
case ExOperStats::UDR_BASE_STATS:
((ExUDRBaseStats *)stat)->merge((ExUDRBaseStats *)other);
break;
- case ExOperStats::HDFSSCAN_STATS:
- ((ExHdfsScanStats*)stat)->merge((ExHdfsScanStats*)other);
- break;
- case ExOperStats::HBASE_ACCESS_STATS:
- ((ExHbaseAccessStats*)stat)->merge((ExHbaseAccessStats*)other);
+ case ExOperStats::SE_STATS:
+ ((ExStorageEngineStats*)stat)->merge((ExStorageEngineStats*)other);
break;
default:
ex_assert(FALSE, "Merging unknown operator statistics type");
@@ -5764,22 +5363,11 @@
insert(newStat);
}
break;
-
- case ExOperStats::HDFSSCAN_STATS:
+ case ExOperStats::SE_STATS:
{
- newStat = new(heap_) ExHdfsScanStats(heap_);
+ newStat = new(heap_) ExStorageEngineStats(heap_);
newStat->setCollectStatsType(tempStatsMergeType);
- ((ExHdfsScanStats *)newStat)->copyContents((ExHdfsScanStats *)stat);
- newStat->setCollectStatsType(tempStatsMergeType);
- insert(newStat);
- }
- break;
-
- case ExOperStats::HBASE_ACCESS_STATS:
- {
- newStat = new(heap_) ExHbaseAccessStats(heap_);
- newStat->setCollectStatsType(tempStatsMergeType);
- ((ExHbaseAccessStats *)newStat)->copyContents((ExHbaseAccessStats *)stat);
+ ((ExStorageEngineStats *)newStat)->copyContents((ExStorageEngineStats *)stat);
newStat->setCollectStatsType(tempStatsMergeType);
insert(newStat);
}
@@ -5827,16 +5415,9 @@
insert(newStat);
break;
- case ExOperStats::HDFSSCAN_STATS:
- newStat = new(heap_) ExHdfsScanStats(heap_);
- ((ExHdfsScanStats *)newStat)->copyContents((ExHdfsScanStats *)stat);
- newStat->setCollectStatsType(tempStatsMergeType);
- insert(newStat);
- break;
-
- case ExOperStats::HBASE_ACCESS_STATS:
- newStat = new(heap_) ExHbaseAccessStats(heap_);
- ((ExHbaseAccessStats *)newStat)->copyContents((ExHbaseAccessStats *)stat);
+ case ExOperStats::SE_STATS:
+ newStat = new(heap_) ExStorageEngineStats(heap_);
+ ((ExStorageEngineStats *)newStat)->copyContents((ExStorageEngineStats *)stat);
newStat->setCollectStatsType(tempStatsMergeType);
insert(newStat);
break;
@@ -5950,18 +5531,10 @@
insert(newStat);
break;
- case ExOperStats::HDFSSCAN_STATS:
- newStat = new(heap_)ExHdfsScanStats(heap_);
- ((ExHdfsScanStats *)newStat)->
- copyContents((ExHdfsScanStats *)stat);
- newStat->setCollectStatsType(tempStatsMergeType);
- insert(newStat);
- break;
-
- case ExOperStats::HBASE_ACCESS_STATS:
- newStat = new(heap_)ExHbaseAccessStats(heap_);
- ((ExHbaseAccessStats *)newStat)->
- copyContents((ExHbaseAccessStats *)stat);
+ case ExOperStats::SE_STATS:
+ newStat = new(heap_)ExStorageEngineStats(heap_);
+ ((ExStorageEngineStats *)newStat)->
+ copyContents((ExStorageEngineStats *)stat);
newStat->setCollectStatsType(tempStatsMergeType);
insert(newStat);
break;
@@ -6398,12 +5971,9 @@
case ExOperStats::PROCESS_STATS:
stat = new(heap_) ExProcessStats((NAHeap *)heap_);
break;
- case ExOperStats::HDFSSCAN_STATS:
- stat = new(heap_) ExHdfsScanStats((NAHeap *)heap_);
+ case ExOperStats::SE_STATS:
+ stat = new(heap_) ExStorageEngineStats((NAHeap *)heap_);
break;
- case ExOperStats::HBASE_ACCESS_STATS:
- stat = new(heap_) ExHbaseAccessStats((NAHeap *)heap_);
- break;
default:
FAILURE ;
}
@@ -6536,6 +6106,7 @@
ExPartitionAccessStats* partitionAccessStats = NULL;
ExProbeCacheStats* probeCacheStats = NULL;
ExFastExtractStats* fastExtractStats = NULL;
+ ExStorageEngineStats *seStats = NULL;
ExHdfsScanStats* hdfsScanStats = NULL;
ExHbaseAccessStats* hbaseAccessStats = NULL;
ExSortStats* sortStats = NULL;
@@ -6669,19 +6240,11 @@
else
tempRetcode = -EXE_STAT_NOT_FOUND;
break;
- case ExOperStats::HDFSSCAN_STATS:
- if (hdfsScanStats == NULL)
- hdfsScanStats = (ExHdfsScanStats*)get(ExOperStats::HDFSSCAN_STATS, sqlStats_items[i].tdb_id);
- if (hdfsScanStats != NULL)
- tempRetcode = hdfsScanStats->getStatsItem(&sqlStats_items[i]);
- else
- tempRetcode = -EXE_STAT_NOT_FOUND;
- break;
- case ExOperStats::HBASE_ACCESS_STATS:
- if (hbaseAccessStats == NULL)
- hbaseAccessStats = (ExHbaseAccessStats*)get(ExOperStats::HBASE_ACCESS_STATS, sqlStats_items[i].tdb_id);
- if (hbaseAccessStats != NULL)
- tempRetcode = hbaseAccessStats->getStatsItem(&sqlStats_items[i]);
+ case ExOperStats::SE_STATS:
+ if (seStats == NULL)
+ seStats = (ExStorageEngineStats*)get(ExOperStats::HDFSSCAN_STATS, sqlStats_items[i].tdb_id);
+ if (seStats != NULL)
+ tempRetcode = seStats->getStatsItem(&sqlStats_items[i]);
else
tempRetcode = -EXE_STAT_NOT_FOUND;
break;
@@ -7026,8 +6589,9 @@
ExUDRBaseStats *udrBaseStats;
ExMasterStats *masterStats;
ExProcessStats *processStats;
- ExHbaseAccessStats *hbaseAccessStats;
+ ExStorageEngineStats *seStats;
ExHdfsScanStats *hdfsScanStats;
+ ExHbaseAccessStats *hbaseAccessStats;
NABoolean retcode = FALSE;
ExOperStats::StatType statType;
ExOperStats *stat1;
@@ -7172,26 +6736,16 @@
retcode = TRUE;
}
break;
- case ExOperStats::HDFSSCAN_STATS:
+ case ExOperStats::SE_STATS:
if (detailLevel_ == stat->getTdbId())
{
- hdfsScanStats = new (getHeap()) ExHdfsScanStats(getHeap());
- hdfsScanStats->setCollectStatsType(getCollectStatsType());
- hdfsScanStats->copyContents((ExHdfsScanStats *)stat);
- insert(hdfsScanStats);
+ seStats = new (getHeap()) ExStorageEngineStats(getHeap());
+ seStats->setCollectStatsType(getCollectStatsType());
+ seStats->copyContents((ExHdfsScanStats *)stat);
+ insert(seStats);
retcode = TRUE;
}
break;
- case ExOperStats::HBASE_ACCESS_STATS:
- if (detailLevel_ == stat->getTdbId())
- {
- hbaseAccessStats = new (getHeap()) ExHbaseAccessStats(getHeap());
- hbaseAccessStats->setCollectStatsType(getCollectStatsType());
- hbaseAccessStats->copyContents((ExHbaseAccessStats *)stat);
- insert(hbaseAccessStats);
- retcode = TRUE;
- }
- break;
default:
break;
} // StatType case
@@ -10529,9 +10083,9 @@
case 1:
return "OperCpuTime";
case 2:
- return "scrIORead";
+ return "scrIOCount";
case 3:
- return "scrIOWritten";
+ return "bmoHeapAllocated";
case 4:
return "scrFileCount";
}
@@ -10545,9 +10099,9 @@
case 1:
return ExOperStats::getNumVal(i);
case 2:
- return scratchReadCount_;
+ return scratchReadCount_+scratchWriteCount_;
case 3:
- return scratchWriteCount_;
+ return bmoHeapAlloc_;
case 4:
return scratchFileCount_;
}
@@ -10718,10 +10272,8 @@
case SQLSTATS_DETAIL:
if (sqlStats_item->str_value != NULL)
{
- sprintf(tmpBuf, "%d|%d|%d",
- scratchBufferBlockRead_,
- scratchBufferBlockWritten_,
- scratchFileCount_);
+ char* buf = tmpBuf;
+ sprintf(buf, "%ld|%ld|%ld|", getNumVal(2), getNumVal(3), getNumVal(4));
len = str_len(tmpBuf);
if (len > sqlStats_item->str_max_len)
sqlStats_item->error_code = EXE_ERROR_IN_STAT_ITEM;
diff --git a/core/sql/executor/ExStats.h b/core/sql/executor/ExStats.h
index e244b4d..6fd10e0 100644
--- a/core/sql/executor/ExStats.h
+++ b/core/sql/executor/ExStats.h
@@ -42,6 +42,7 @@
#include "Int64.h"
#include "ComTdb.h"
+#include "ex_stdh.h"
#include "ExScheduler.h"
#include "ComTdbStats.h"
#include "ComTdbUdr.h"
@@ -85,8 +86,10 @@
class ExBMOStats;
class ExUDRBaseStats;
class ExFastExtractStats;
-class ExHdfsScanStats;
-class ExHbaseAccessStats;
+class ExStorageEngineStats;
+
+typedef ExStorageEngineStats ExHbaseAccessStats;
+typedef ExStorageEngineStats ExHdfsScanStats;
//////////////////////////////////////////////////////////////////
// forward classes
@@ -434,8 +437,7 @@
UInt32 pack(char * buffer);
void merge(ExeSEStats * other);
- void merge(ExHbaseAccessStats * other);
- void merge(ExHdfsScanStats * other);
+ void merge(ExStorageEngineStats * other);
void unpack(const char* &buffer);
@@ -566,8 +568,9 @@
REPLICATOR_STATS = SQLSTATS_DESC_REPLICATOR_STATS,
FAST_EXTRACT_STATS = SQLSTATS_DESC_FAST_EXTRACT_STATS,
REORG_STATS = SQLSTATS_DESC_REORG_STATS,
- HDFSSCAN_STATS = SQLSTATS_DESC_HDFSSCAN_STATS,
- HBASE_ACCESS_STATS = SQLSTATS_DESC_HBASE_ACCESS_STATS,
+ SE_STATS = SQLSTATS_DESC_SE_STATS,
+ HDFSSCAN_STATS = SQLSTATS_DESC_SE_STATS,
+ HBASE_ACCESS_STATS = SQLSTATS_DESC_SE_STATS,
PROCESS_STATS = SQLSTATS_DESC_PROCESS_STATS
};
@@ -1795,24 +1798,24 @@
};
/////////////////////////////////////////////////////////////////
-//// class ExHdfsScanStats
+//// class ExStorageEngineStats
///////////////////////////////////////////////////////////////////
-class ExHdfsScanStats : public ExOperStats {
+class ExStorageEngineStats : public ExOperStats {
public:
- ExHdfsScanStats(NAMemory * heap,
+ ExStorageEngineStats(NAMemory * heap,
ex_tcb *tcb,
ComTdb * tdb); // tbd - other, specific params?
- ExHdfsScanStats(NAMemory * heap);
+ ExStorageEngineStats(NAMemory * heap);
- ~ExHdfsScanStats();
+ ~ExStorageEngineStats();
void init(NABoolean resetDop);
- void merge(ExHdfsScanStats* other);
+ void merge(ExStorageEngineStats* other);
- void copyContents(ExHdfsScanStats* other);
+ void copyContents(ExStorageEngineStats* other);
ExOperStats * copyOper(NAMemory * heap);
@@ -1831,24 +1834,32 @@
char * tableName() const {return tableName_;}
ExTimeStats &getHdfsTimer() { return timer_; }
+ ExTimeStats &getHbaseTimer() { return timer_; }
+
inline void incBytesRead(Int64 bytesRead) {numBytesRead_ += bytesRead;}
inline void incAccessedRows() {++accessedRows_;}
+ inline void incAccessedRows(Int64 v) {accessedRows_ += v;}
inline void incUsedRows() {++usedRows_;}
+ inline void incUsedRows(Int64 v) {usedRows_ += v;}
- inline void incMaxHdfsIOTime(Int64 v) {maxHdfsIOTime_ += v;}
+ inline void incMaxHdfsIOTime(Int64 v) {maxIOTime_ += v;}
+ inline void incMaxHbaseIOTime(Int64 v) {maxIOTime_ += v;}
+
Int64 numBytesRead() const {return numBytesRead_;}
-
Int64 rowsAccessed() const {return accessedRows_;}
-
Int64 rowsUsed() const {return usedRows_;}
NABoolean filterForSEstats(struct timespec currTimespec, Lng32 filter);
- Int64 maxHdfsIOTime() const {return maxHdfsIOTime_;}
+
+ Int64 maxHdfsIOTime() const {return maxIOTime_;}
+ Int64 maxHbaseIOTime() const {return maxIOTime_;}
ExHdfsScanStats * castToExHdfsScanStats();
+ ExHbaseAccessStats * castToExHbaseAccessStats();
+
virtual const char * getNumValTxt(Int32 i) const;
virtual Int64 getNumVal(Int32 i) const;
@@ -1859,125 +1870,27 @@
Lng32 getStatsItem(SQLSTATS_ITEM* sqlStats_item);
- ExLobStats * lobStats() { return &lobStats_;}
void setQueryId(char *queryId, Lng32 queryIdLen)
{queryId_ = queryId;
queryIdLen_ = queryIdLen;}
char *getQueryId() { return queryId_; }
Lng32 getQueryIdLen() { return queryIdLen_; }
- inline void incHdfsCalls() {++numHdfsCalls_;}
- Int64 hdfsCalls() const {return numHdfsCalls_;}
+
+ inline void incHdfsCalls() {++numIOCalls_;}
+ inline void incHbaseCalls() {++numIOCalls_;}
+
+ Int64 hdfsCalls() const {return numIOCalls_;}
+ Int64 hbaseCalls() const {return numIOCalls_;}
private:
ExTimeStats timer_;
- ExLobStats lobStats_;
-
char * tableName_;
-
Int64 numBytesRead_;
Int64 accessedRows_;
Int64 usedRows_;
- Int64 numHdfsCalls_;
- Int64 maxHdfsIOTime_;
- char *queryId_;
- Lng32 queryIdLen_;
- Lng32 blockTime_;
-};
-
-/////////////////////////////////////////////////////////////////
-//// class ExHbaseAccessStats
-///////////////////////////////////////////////////////////////////
-
-class ExHbaseAccessStats : public ExOperStats {
- public:
- ExHbaseAccessStats(NAMemory * heap,
- ex_tcb *tcb,
- ComTdb * tdb); // tbd - other, specific params?
-
- ExHbaseAccessStats(NAMemory * heap);
-
- ~ExHbaseAccessStats();
-
- void init(NABoolean resetDop);
-
- void merge(ExHbaseAccessStats* other);
-
- void copyContents(ExHbaseAccessStats* other);
-
- ExOperStats * copyOper(NAMemory * heap);
-
- UInt32 packedLength();
-
- //////////////////////////////////////////////////////////////////
- //// packs 'this' into a message. Converts pointers to offsets.
- ////////////////////////////////////////////////////////////////////
- UInt32 pack(char * buffer);
-
- void unpack(const char* &buffer);
-
- /////////////////////////////////////////////////////////////////
- //// accessors, mutators
- ///////////////////////////////////////////////////////////////////
- char * tableName() const {return tableName_;}
-
- ExTimeStats &getHbaseTimer() { return timer_; }
- inline void incBytesRead(Int64 bytesRead) {numBytesRead_ += bytesRead;}
-
- inline void incAccessedRows() {++accessedRows_;}
- inline void incAccessedRows(Int64 v) {accessedRows_ += v;}
-
- inline void incUsedRows() {++usedRows_;}
- inline void incUsedRows(Int64 v) {usedRows_ += v;}
-
- inline void incHbaseCalls() {++numHbaseCalls_;}
-
- inline void incMaxHbaseIOTime(Int64 v) {maxHbaseIOTime_ += v;}
-
- Int64 numBytesRead() const {return numBytesRead_;}
-
- Int64 rowsAccessed() const {return accessedRows_;}
-
- Int64 rowsUsed() const {return usedRows_;}
-
- Int64 hbaseCalls() const {return numHbaseCalls_;}
-
- Int64 maxHbaseIOTime() const {return maxHbaseIOTime_;}
-
- NABoolean filterForSEstats(struct timespec currTimespec, Lng32 filter);
-
- ExHbaseAccessStats * castToExHbaseAccessStats();
-
- virtual const char * getNumValTxt(Int32 i) const;
-
- virtual Int64 getNumVal(Int32 i) const;
-
- virtual void getVariableStatsInfo(char * dataBuffer,
- char * datalen,
- Lng32 maxLen);
- Lng32 getStatsItem(SQLSTATS_ITEM* sqlStats_item);
-
- ExLobStats * lobStats() { return &lobStats_;}
-
- // ExHbaseStats * hbaseStats() { return &hbaseStats_;}
- void setQueryId(char *queryId, Lng32 queryIdLen)
- {queryId_ = queryId;
- queryIdLen_ = queryIdLen;}
- char *getQueryId() { return queryId_; }
- Lng32 getQueryIdLen() { return queryIdLen_; }
-
- private:
-
- ExTimeStats timer_;
- ExLobStats lobStats_;
-
- char * tableName_;
-
- Int64 numBytesRead_;
- Int64 accessedRows_;
- Int64 usedRows_;
- Int64 numHbaseCalls_;
- Int64 maxHbaseIOTime_;
+ Int64 numIOCalls_;
+ Int64 maxIOTime_;
char *queryId_;
Lng32 queryIdLen_;
Lng32 blockTime_;
@@ -2087,8 +2000,7 @@
void merge(ExFragRootOperStats* other);
void merge(ExUDRBaseStats * other);
void merge(ExBMOStats * other);
- void merge(ExHdfsScanStats * other);
- void merge(ExHbaseAccessStats * other);
+ void merge(ExStorageEngineStats * other);
ExOperStats * copyOper(NAMemory * heap);
diff --git a/core/sql/executor/HBaseClient_JNI.h b/core/sql/executor/HBaseClient_JNI.h
index c89146a..eb339aa 100644
--- a/core/sql/executor/HBaseClient_JNI.h
+++ b/core/sql/executor/HBaseClient_JNI.h
@@ -29,23 +29,19 @@
#include "Platform.h"
#include "Collections.h"
#include "NABasicObject.h"
-
+#include "ExStats.h"
#include "JavaObjectInterface.h"
#include "Hbase_types.h"
#include "ExpHbaseDefs.h"
#include "NAMemory.h"
#include "org_trafodion_sql_HTableClient.h"
-// forward declare
-class ExHbaseAccessStats;
-
using namespace apache::hadoop::hbase::thrift;
namespace {
typedef std::vector<Text> TextVec;
}
-
class ContextCli;
class HBulkLoadClient_JNI;
diff --git a/core/sql/executor/HdfsClient_JNI.cpp b/core/sql/executor/HdfsClient_JNI.cpp
index d5b5043..65c83cd 100644
--- a/core/sql/executor/HdfsClient_JNI.cpp
+++ b/core/sql/executor/HdfsClient_JNI.cpp
@@ -288,6 +288,8 @@
short retArrayLen = jenv_->GetArrayLength(j_retArray);
ex_assert(retArrayLen == arrayLen, "HdfsScan::trafHdfsRead() InternalError: retArrayLen != arrayLen");
jenv_->GetIntArrayRegion(j_retArray, 0, 4, retArray);
+ if (hdfsStats_ != NULL)
+ hdfsStats_->incBytesRead(retArray[ExHdfsScanTcb::BYTES_COMPLETED]);
return HDFS_SCAN_OK;
}
@@ -666,6 +668,7 @@
if (hdfsStats_ != NULL) {
hdfsStats_->incMaxHdfsIOTime(hdfsStats_->getHdfsTimer().stop());
hdfsStats_->incHdfsCalls();
+ hdfsStats_->incBytesRead(writeLen);
}
if (jenv_->ExceptionCheck())
{
@@ -724,6 +727,7 @@
if (hdfsStats_ != NULL) {
hdfsStats_->incMaxHdfsIOTime(hdfsStats_->getHdfsTimer().stop());
hdfsStats_->incHdfsCalls();
+ hdfsStats_->incBytesRead(writeLen);
}
if (jenv_->ExceptionCheck())
{
@@ -765,6 +769,7 @@
if (hdfsStats_ != NULL) {
hdfsStats_->incMaxHdfsIOTime(hdfsStats_->getHdfsTimer().stop());
hdfsStats_->incHdfsCalls();
+ hdfsStats_->incBytesRead(bytesRead);
}
if (jenv_->ExceptionCheck())
{
diff --git a/core/sql/executor/OrcFileReader.h b/core/sql/executor/OrcFileReader.h
index 536235a..2c7d7b8 100644
--- a/core/sql/executor/OrcFileReader.h
+++ b/core/sql/executor/OrcFileReader.h
@@ -24,6 +24,7 @@
#define ORC_FILE_READER_H
#include "JavaObjectInterface.h"
+#include "ExStats.h"
// ===========================================================================
// ===== The OrcFileReader class implements access to th Java
diff --git a/core/sql/executor/log4cpp.hdfs.config b/core/sql/executor/log4cpp.hdfs.config
deleted file mode 100644
index d27650b..0000000
--- a/core/sql/executor/log4cpp.hdfs.config
+++ /dev/null
@@ -1,37 +0,0 @@
-# log4cxx configuration for HDFS access via JNI
-
-# @@@ START COPYRIGHT @@@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-# @@@ END COPYRIGHT @@@
-
-log4j.rootLogger=INFO, rootAppender
-
-log4j.appender.rootAppender=org.apache.log4j.RollingFileAppender
-log4j.appender.rootAppender.fileName=hdfs.log
-log4j.appender.rootAppender.maxFileSize=100000000
-log4j.appender.rootAppender.maxBackupIndex=1
-log4j.appender.rootAppender.addPid=false
-log4j.appender.rootAppender.layout=org.apache.log4j.PatternLayout
-log4j.appender.rootAppender.layout.ConversionPattern=%d, %p, %c, %m%n
-
-log4j.logger.JniTop=ERROR
-log4j.logger.SeqFileReader=ERROR
-log4j.logger.SeqFileWriter=ERROR
-log4j.logger.HBase=ERROR
diff --git a/core/sql/executor/log4j.hdfs.config b/core/sql/executor/log4j.hdfs.config
deleted file mode 100644
index 6b8f9fe..0000000
--- a/core/sql/executor/log4j.hdfs.config
+++ /dev/null
@@ -1,50 +0,0 @@
-# Define some default values that can be overridden by system properties
-
-# @@@ START COPYRIGHT @@@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-# @@@ END COPYRIGHT @@@
-
-hbase.root.logger=INFO,hbaseclient
-hbase.log.dir=.
-hbase.log.file=hdfs.java.log
-
-# Define the root logger to the system property "hbase.root.logger".
-log4j.rootLogger=${hbase.root.logger}
-
-# Logging Threshold
-log4j.threshhold=ALL
-
-#
-# Daily Rolling File Appender
-#
-log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.hbaseclient=org.apache.log4j.RollingFileAppender
-log4j.appender.hbaseclient.file=hdfs.java.log
-log4j.appender.hbaseclient.layout=org.apache.log4j.PatternLayout
-log4j.appender.hbaseclient.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
-log4j.appender.hbaseclient.immediateFlush=true
-
-# Custom Logging levels
-
-log4j.logger.org.apache.zookeeper=ERROR
-log4j.logger.org.apache.hadoop.hbase=ERROR
-log4j.logger.com.tandem.sqlmx=ERROR
-
-#log4j.logger.org.apache.hadoop.hbase=DEBUG
diff --git a/core/sql/exp/ExpHbaseInterface.h b/core/sql/exp/ExpHbaseInterface.h
index c9583e5..a7eee97 100644
--- a/core/sql/exp/ExpHbaseInterface.h
+++ b/core/sql/exp/ExpHbaseInterface.h
@@ -60,7 +60,6 @@
class ex_globals;
class CliGlobals;
-class ExHbaseAccessStats;
Int64 getTransactionIDFromContext();
diff --git a/core/sql/exp/ExpLOB.cpp b/core/sql/exp/ExpLOB.cpp
index 5fb0fc2..914861b 100644
--- a/core/sql/exp/ExpLOB.cpp
+++ b/core/sql/exp/ExpLOB.cpp
@@ -833,6 +833,7 @@
rc = ExpLOBInterfaceInsertSelect
(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
getLobHdfsServer(), getLobHdfsPort(),
tgtLobName,
so,
@@ -845,6 +846,7 @@
else
rc = ExpLOBInterfaceInsert
(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
tgtLobName,
lobStorageLocation(),
lobStorageType(),
@@ -992,6 +994,7 @@
rc = ExpLOBInterfaceInsert(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
tgtLobName,
lobStorageLocation(),
lobType,
@@ -1160,6 +1163,7 @@
rc = ExpLOBInterfaceDelete
(
getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
getLobHdfsServer(),
getLobHdfsPort(),
lobName,
@@ -1439,6 +1443,7 @@
{
rc = ExpLOBInterfaceUpdateAppend
(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
getLobHdfsServer(),
getLobHdfsPort(),
tgtLobName,
@@ -1462,6 +1467,7 @@
{
rc = ExpLOBInterfaceUpdate
(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
getLobHdfsServer(),
getLobHdfsPort(),
tgtLobName,
@@ -1636,6 +1642,7 @@
so = Lob_File;
tgtFileName = tgtFileName_;
rc = ExpLOBInterfaceSelect(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName,
lobStorageLocation(),
lobType,
@@ -1661,6 +1668,7 @@
lobLen = getConvertSize();
lobData = new(h) char[(Lng32)lobLen];
rc = ExpLOBInterfaceSelect(getExeGlobals()->getExLobGlobal(),
+ (getTcb()->getStatsEntry() != NULL ? getTcb()->getStatsEntry()->castToExHdfsScanStats() : NULL),
lobName,
lobStorageLocation(),
lobType,
diff --git a/core/sql/exp/ExpLOBaccess.cpp b/core/sql/exp/ExpLOBaccess.cpp
index a24018a..bb9b580 100644
--- a/core/sql/exp/ExpLOBaccess.cpp
+++ b/core/sql/exp/ExpLOBaccess.cpp
@@ -77,7 +77,7 @@
// short LobServerFNum;
SB_Phandle_Type serverPhandle;
-ExLob::ExLob(NAHeap * heap) :
+ExLob::ExLob(NAHeap * heap, ExHdfsScanStats *hdfsAccessStats) :
lobDataFile_(heap),
storage_(Lob_Invalid_Storage),
lobStorageLocation_(string()),
@@ -85,6 +85,7 @@
fs_(NULL),
fdData_(NULL),
openFlags_(0),
+ stats_(hdfsAccessStats),
lobTrace_(FALSE),
useLibHdfs_(FALSE),
hdfsClient_(NULL)
@@ -149,8 +150,6 @@
storage_ = storage;
}
- stats_.init();
-
hdfsServer_ = hdfsServer;
hdfsPort_ = hdfsPort;
// lobLocation_ = lobLocation;
@@ -165,7 +164,7 @@
hdfsClient_ = NULL;
}
else {
- hdfsClient_ = HdfsClient::newInstance(lobGlobalHeap_, NULL, hdfsClientRetcode);
+ hdfsClient_ = HdfsClient::newInstance(lobGlobalHeap_, stats_, hdfsClientRetcode);
fs_ = NULL;
if (hdfsClient_ == NULL)
return LOB_HDFS_CONNECT_ERROR;
@@ -181,7 +180,6 @@
nsecs += NUM_NSECS_IN_SEC;
}
totalnsecs = (secs * NUM_NSECS_IN_SEC) + nsecs;
- stats_.hdfsConnectionTime += totalnsecs;
if (! useLibHdfs_) {
if (mode == EX_LOB_CREATE) {
@@ -2192,7 +2190,6 @@
nsecs += NUM_NSECS_IN_SEC;
}
Int64 totalnsecs = (secs * NUM_NSECS_IN_SEC) + nsecs;
- stats_.CumulativeReadTime += totalnsecs;
} // useLibHdfs
if (bytesRead == -1) {
return LOB_DATA_READ_ERROR;
@@ -2603,20 +2600,19 @@
Ex_Lob_Error ExLob::readStats(char *statsBuffer)
{
- memcpy(statsBuffer, (char *)&stats_, sizeof(stats_));
+ stats_ = (ExHdfsScanStats *)statsBuffer;
return LOB_OPER_OK;
}
Ex_Lob_Error ExLob::initStats()
{
- stats_.init();
return LOB_OPER_OK;
}
//Main driver of any LOB related operation
Ex_Lob_Error ExLobsOper (
char *lobName, // lob name
-
+ ExHdfsScanStats *hdfsAccessStats,
char *handleIn, // input handle (for cli calls)
Int32 handleInLen, // input handle len
@@ -2709,7 +2705,7 @@
if (it == lobMap->end())
{
- lobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap());
+ lobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap(), hdfsAccessStats);
if (lobPtr == NULL)
return LOB_ALLOC_ERROR;
@@ -2802,7 +2798,7 @@
if (it2 == lobMap->end())
{
- srcLobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap());
+ srcLobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap(), hdfsAccessStats);
if (srcLobPtr == NULL)
return LOB_ALLOC_ERROR;
@@ -3019,11 +3015,6 @@
lobDebugInfo("purgeLob failed ",err,__LINE__,lobGlobals->lobTrace_);
break;
- case Lob_Stats:
- err = lobPtr->readStats(source);
- lobPtr->initStats(); // because file may remain open across cursors
- break;
-
case Lob_Empty_Directory:
err = lobPtr->emptyDirectory(lobStorageLocation, lobGlobals);
@@ -3090,7 +3081,6 @@
*/
clock_gettime(CLOCK_MONOTONIC, &endTime);
-
secs = endTime.tv_sec - startTime.tv_sec;
nsecs = endTime.tv_nsec - startTime.tv_nsec;
if (nsecs < 0) {
@@ -3098,9 +3088,10 @@
nsecs += NUM_NSECS_IN_SEC;
}
totalnsecs = (secs * NUM_NSECS_IN_SEC) + nsecs;
+/*
if (lobPtr && lobPtr->getStats())
lobPtr->getStats()->hdfsAccessLayerTime += totalnsecs;
-
+*/
return err;
}
@@ -3209,15 +3200,15 @@
buf->bytesUsed_ += bytesToCopy;
buf->bytesRemaining_ -= bytesToCopy;
}
- stats_.bytesPrefetched += bytesToCopy;
+ //stats_.bytesPrefetched += bytesToCopy;
operLen += bytesToCopy;
}
-
+/*
// update stats
stats_.bytesRead += operLen;
stats_.bytesToRead += tgtSize;
stats_.numReadReqs++;
-
+*/
return LOB_OPER_OK;
}
@@ -3262,7 +3253,7 @@
nsecs += NUM_NSECS_IN_SEC;
}
Int64 totalnsecs = (secs * NUM_NSECS_IN_SEC) + nsecs;
- stats_.cursorElapsedTime += totalnsecs;
+ //stats_.cursorElapsedTime += totalnsecs;
return LOB_OPER_OK;
}
@@ -3317,7 +3308,7 @@
cursor->lock_.unlock();
buf = new (getHeap()) ExLobCursorBuffer();
buf->data_ = (char *) (getHeap())->allocateMemory( cursor->bufMaxSize_);
- lobPtr->stats_.buffersUsed++;
+ //lobPtr->stats_.buffersUsed++;
}
size = min(cursor->bufMaxSize_, (cursor->maxBytes_ - cursor->bytesRead_));
if (buf->data_) {
@@ -3418,7 +3409,7 @@
// bytesRead = hdfsPread(fs_, fdData_, offset, tgt, bytesToCopy);
bytesRead = hdfsRead(fs_, fdData_, tgt, bytesToCopy);
- stats_.numHdfsReqs++;
+ //stats_.numHdfsReqs++;
if (bytesRead == -1) {
return LOB_DATA_READ_ERROR;
@@ -3441,10 +3432,11 @@
}
Int64 totalnsecs = (secs * NUM_NSECS_IN_SEC) + nsecs;
- stats_.CumulativeReadTime += totalnsecs;
+ //stats_.CumulativeReadTime += totalnsecs;
return LOB_OPER_OK;
}
+
void ExLobCursor::emptyPrefetchList(ExLobGlobals *lobGlobals)
{
ExLobCursor::bufferList_t::iterator c_it;
diff --git a/core/sql/exp/ExpLOBaccess.h b/core/sql/exp/ExpLOBaccess.h
index 416c3cc..4097d62 100644
--- a/core/sql/exp/ExpLOBaccess.h
+++ b/core/sql/exp/ExpLOBaccess.h
@@ -49,6 +49,8 @@
#include "Globals.h"
#include <seabed/ms.h>
#include <seabed/fs.h>
+#include "ex_stdh.h"
+#include "ExStats.h"
#ifdef LOB_DEBUG_STANDALONE
#define Int64 long long
#define Lng32 long
@@ -56,18 +58,10 @@
#endif
#define SQ_USE_HDFS 1
-
-
-
#include "hdfs.h"
-
-
-
-
using namespace std;
-
class ExLobGlobals;
// This class defines the request used to construct the message to send over
// to the mxlobsrvr process. It's currently not used. All lob functionailty is
@@ -149,6 +143,7 @@
Ex_Lob_Error ExLobsOper (
char *lobName, // lob name
+ ExHdfsScanStats *hdfsAccessStats, // Statistics for Lob access
char *handleIn, // input handle (for cli calls)
Int32 handleInLen, // input handle len
char *hdfsServer, // server where hdfs fs resides
@@ -394,7 +389,7 @@
{
public:
- ExLob(NAHeap * heap); // default constructor
+ ExLob(NAHeap * heap, ExHdfsScanStats *hdfsAccessStats); // default constructor
virtual ~ExLob(); // default desctructor
void setUseLibHdfs(NABoolean useLibHdfs)
@@ -490,7 +485,7 @@
Ex_Lob_Error emptyDirectory(char* dirPath, ExLobGlobals* lobGlobals);
- ExLobStats *getStats() { return &stats_; }
+ ExHdfsScanStats *getStats() { return stats_; }
NAHeap *getLobGlobalHeap() { return lobGlobalHeap_;}
Ex_Lob_Error getLength(char *handleIn, Int32 handleInLen,Int64 &outLobLen,LobsSubOper so, Int64 transId);
Ex_Lob_Error getOffset(char *handleIn, Int32 handleInLen,Int64 &outOffset,LobsSubOper so, Int64 transId);
@@ -515,7 +510,7 @@
hdfsFS fs_;
hdfsFile fdData_;
int openFlags_;
- ExLobStats stats_;
+ ExHdfsScanStats *stats_;
bool prefetchQueued_;
NAHeap *lobGlobalHeap_;
NABoolean lobTrace_;
diff --git a/core/sql/exp/ExpLOBenums.h b/core/sql/exp/ExpLOBenums.h
index 9729cbc..4d140a2 100644
--- a/core/sql/exp/ExpLOBenums.h
+++ b/core/sql/exp/ExpLOBenums.h
@@ -249,8 +249,6 @@
Lob_Drop,
Lob_Check_Status,
- Lob_Stats,
-
Lob_Print, // debugging purposes
Lob_Empty_Directory,
diff --git a/core/sql/exp/ExpLOBinterface.cpp b/core/sql/exp/ExpLOBinterface.cpp
index 93035ed..3320a83 100644
--- a/core/sql/exp/ExpLOBinterface.cpp
+++ b/core/sql/exp/ExpLOBinterface.cpp
@@ -47,6 +47,7 @@
Int32 dummyParam2 = 0;
err = ExLobsOper((char*)"dummy",
+ NULL,
NULL, 0,
NULL, 0,
NULL, dummyParam2, 0, dummyParam,
@@ -104,6 +105,7 @@
Int64 cliError = -1;
Int32 dummyParam2 = 0;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL, 0,
hdfsServer, hdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -132,6 +134,7 @@
Int64 cliError = -1;
Int32 dummyParam2 = 0;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL, 0,
hdfsServer, hdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -159,6 +162,7 @@
Int64 cliError = -1;
Int32 dummyParam2 = 0;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL, 0,
hdfsServer, hdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -186,6 +190,7 @@
Int64 cliError = -1;
Int32 dummyParam2 = 0;
err = ExLobsOper((char *)"dummy",
+ NULL, // ExHdfsScanStats *
NULL, 0,
NULL, 0,
NULL, dummyParam2, 0, dummyParam,
@@ -224,6 +229,7 @@
Int64 cliError = -1;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL, 0,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -279,6 +285,7 @@
*(Lng32*)&blackBox[sizeof(modTS)+sizeof(numOfPartLevels)] = failedLocBufLen;
failedModTS = -1;
err = ExLobsOper((char*)"",
+ NULL, // ExHdfsScanStats *
NULL, 0,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2,
@@ -338,6 +345,7 @@
Int64 cliError = -1;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL, 0,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -371,6 +379,7 @@
Int64 cliError = -1;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL, 0,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -403,6 +412,7 @@
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
NULL,0,
NULL, 0,
NULL, dummyParam2, 0, dummyParam,
@@ -424,6 +434,7 @@
}
Lng32 ExpLOBinterfaceCloseFile(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobName,
char * lobLoc,
Lng32 lobType,
@@ -440,6 +451,7 @@
LobsStorage ls = (LobsStorage)lobType;
err = ExLobsOper(lobName,
+ hdfsAccessStats,
NULL, 0,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2, 0, dummyParam,
@@ -463,6 +475,7 @@
Lng32 ExpLOBInterfaceInsert(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * tgtLobName,
char * lobStorageLocation,
Lng32 lobType,
@@ -518,6 +531,7 @@
// Int64 lobLen = (tgtLobLen ? *tgtLobLen : 0);
err = ExLobsOper(tgtLobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
outLobHandle, *outHandleLen,
@@ -560,6 +574,7 @@
}
Lng32 ExpLOBInterfaceInsertSelect(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort ,
char * tgtLobName,
@@ -594,6 +609,7 @@
LobsStorage ls = (LobsStorage)lobType;
err = ExLobsOper(tgtLobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
outLobHandle, *outHandleLen,
@@ -627,6 +643,7 @@
}
Lng32 ExpLOBInterfaceUpdateAppend(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort ,
char * tgtLobName,
@@ -640,7 +657,6 @@
Lng32 checkStatus,
Lng32 waitedOp,
LobsSubOper so,
-
Int64 &tgtDescSyskey,
Int64 tgtLobLen,
char * srcLobData,
@@ -667,6 +683,7 @@
else if ((so == Lob_Buffer) || (so == Lob_Memory))
srcLen = tgtLobLen;
err = ExLobsOper(tgtLobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort, // hdfs server/port
outLobHandle, *outHandleLen,
@@ -697,9 +714,9 @@
}
Lng32 ExpLOBInterfaceUpdate(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort,
-
char * tgtLobName,
char * lobStorageLocation,
Lng32 handleLen,
@@ -711,7 +728,6 @@
Lng32 checkStatus,
Lng32 waitedOp,
LobsSubOper so,
-
Int64 &tgtDescSyskey,
Int64 tgtLobLen,
char * srcLobData,
@@ -738,6 +754,7 @@
sourceLen = tgtLobLen;
err = ExLobsOper(tgtLobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort, // hdfs server/port
outLobHandle, *outHandleLen,
@@ -770,10 +787,11 @@
}
Lng32 ExpLOBInterfaceDelete(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort ,
char * lobName,
- char * lobLoc,
+ char * lobLoc,
Lng32 handleLen,
char * lobHandle,
Int64 &requestTag,
@@ -799,6 +817,7 @@
}
err = ExLobsOper(lobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort, // hdfs server/port
NULL, dummyParam2,
@@ -829,12 +848,12 @@
}
Lng32 ExpLOBInterfaceSelect(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobName,
char * lobLoc,
Lng32 lobType,
char * lobHdfsServer,
Lng32 lobHdfsPort,
-
Lng32 handleLen,
char * lobHandle,
Int64 &requestTag,
@@ -871,6 +890,7 @@
LobsStorage ls = (LobsStorage)lobType;
err = ExLobsOper(lobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2,
@@ -906,6 +926,7 @@
}
Lng32 ExpLOBInterfaceSelectCursor(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobName,
char * lobLoc,
Lng32 lobType,
@@ -971,6 +992,7 @@
LobsStorage ls = (LobsStorage)lobType;
err = ExLobsOper(lobName,
+ hdfsAccessStats,
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2,
@@ -1026,6 +1048,7 @@
else
so = Lob_Buffer;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2,
@@ -1084,6 +1107,7 @@
else
so = Lob_Buffer;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2,
@@ -1139,6 +1163,7 @@
else
so = Lob_Buffer;
err = ExLobsOper(lobName,
+ NULL, // ExHdfsScanStats *
lobHandle, handleLen,
lobHdfsServer, lobHdfsPort,
NULL, dummyParam2,
@@ -1166,41 +1191,6 @@
return LOB_ACCESS_SUCCESS;
}
-Lng32 ExpLOBinterfaceStats(
- ExLobGlobals * exLobGlob,
- ExLobStats * lobStats,
- char * lobName, char * lobLoc,
- Lng32 lobType,
- char * lobHdfsServer,
- Lng32 lobHdfsPort)
-{
- Ex_Lob_Error err;
-
- Int64 dummyParam= 0;
- Int32 dummyParam2 = 0;
- Ex_Lob_Error status;
- Int64 cliError = -1;
-
- err = ExLobsOper(lobName,
- NULL, 0,
- lobHdfsServer, lobHdfsPort,
- NULL, dummyParam2, 0, dummyParam,
- dummyParam, 0, dummyParam, status, cliError,
- lobLoc, (LobsStorage)lobType,
- (char*)lobStats, 0,
- 0,NULL,
- Lob_Stats,
- Lob_None,
- 1, // waited op
- exLobGlob,
- 0, NULL, 0
- );
-
- if (err != LOB_OPER_OK)
- return -err;
- else
- return 0;
-}
char * getLobErrStr(Lng32 errEnum)
{
diff --git a/core/sql/exp/ExpLOBinterface.h b/core/sql/exp/ExpLOBinterface.h
index 54435a3..32ae777 100644
--- a/core/sql/exp/ExpLOBinterface.h
+++ b/core/sql/exp/ExpLOBinterface.h
@@ -26,6 +26,8 @@
#include "NAVersionedObject.h"
#include "ComQueue.h"
#include "ex_globals.h"
+#include "ExStats.h"
+
class HdfsFileInfo
{
public:
@@ -116,12 +118,15 @@
char * lobLoc);
Lng32 ExpLOBinterfaceCloseFile(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobName,
char * lobLoc,
Lng32 lobType,
char * lobHdfsServer ,
Lng32 lobHdfsPort );
+
Lng32 ExpLOBInterfaceInsertSelect(ExLobGlobals * exLobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort ,
char * tgtLobName,
@@ -146,6 +151,7 @@
);
Lng32 ExpLOBInterfaceInsert(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * tgtLobName,
char * lobLocation,
Lng32 lobType,
@@ -182,6 +188,7 @@
);
Lng32 ExpLOBInterfaceUpdate(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort,
char * tgtLobName,
@@ -212,6 +219,7 @@
Int64 lobGCLimit = 0);
Lng32 ExpLOBInterfaceUpdateAppend(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort ,
char * tgtLobName,
@@ -243,6 +251,7 @@
);
Lng32 ExpLOBInterfaceDelete(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobHdfsServer ,
Lng32 lobHdfsPort ,
char * lobName,
@@ -256,6 +265,7 @@
Lng32 waitedOp);
Lng32 ExpLOBInterfaceSelect(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobName,
char * lobLoc,
Lng32 lobType,
@@ -276,6 +286,7 @@
Int32 inputFlags=0);
Lng32 ExpLOBInterfaceSelectCursor(ExLobGlobals * lobGlob,
+ ExHdfsScanStats *hdfsAccessStats,
char * lobName,
char * lobLoc,
Lng32 lobType,
@@ -299,14 +310,6 @@
Int32 *hdfsDetailError = NULL
);
-Lng32 ExpLOBinterfaceStats(ExLobGlobals * lobGlob,
- ExLobStats * lobStats,
- char * lobName,
- char * lobLoc,
- Lng32 lobType = (Lng32)Lob_HDFS_File,
- char * lobHdfsServer = (char *)"default",
- Lng32 lobHdfsPort = 0);
-
char * getLobErrStr(Lng32 errEnum);
Lng32 ExpLOBinterfacePerformGC(ExLobGlobals *& lobGlob, char *lobName,void *descChunksArray, Int32 numEntries, char *hdfsServer, Int32 hdfsPort,char *LOBlOC,Int64 lobMaxChunkMemSize);
diff --git a/core/sql/exp/ExpLOBprocess.cpp b/core/sql/exp/ExpLOBprocess.cpp
index e117160..190be7e 100644
--- a/core/sql/exp/ExpLOBprocess.cpp
+++ b/core/sql/exp/ExpLOBprocess.cpp
@@ -485,10 +485,6 @@
return LOB_OPER_OK;
}
-
-
-
-
Ex_Lob_Error ExLobGlobals::getLobPtr(char *lobName, ExLob *& lobPtr)
{
Ex_Lob_Error err;
@@ -500,7 +496,7 @@
if (it == lobMap->end())
{
- lobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap());
+ lobPtr = new (lobGlobals->getHeap())ExLob(lobGlobals->getHeap(),NULL);
if (lobPtr == NULL)
return LOB_ALLOC_ERROR;
diff --git a/core/sql/exp/exp_clause.h b/core/sql/exp/exp_clause.h
index ad51e4f..3f785ef 100644
--- a/core/sql/exp/exp_clause.h
+++ b/core/sql/exp/exp_clause.h
@@ -542,6 +542,11 @@
globals_ = glob;
}
+ void setTcb(const ex_tcb *tcb)
+ {
+ tcb_ = (ex_tcb *)tcb;
+ }
+
Int16 getInstrArrayIndex() { return instrArrayIndex_; }
void setInstrArrayIndex(Int16 index) { instrArrayIndex_ = index; }
@@ -550,6 +555,11 @@
{
return globals_;
}
+
+ ex_tcb *getTcb()
+ {
+ return tcb_;
+ }
private:
ExClausePtr nextClause_; // 00-07
@@ -585,13 +595,14 @@
// Not valid for EID expressions.
// Only used for SQ.
ExGlobalsPtr globals_; // 40-47
-
+
+ ex_tcb *tcb_; // 48-55
// ---------------------------------------------------------------------
// Fillers for potential future extensions without changing class size.
// When a new member is added, size of this filler should be reduced so
// that the size of the object remains the same (and is modulo 8).
// ---------------------------------------------------------------------
- char fillers_[16]; // 52-63
+ char fillers_[8]; // 56-63
};
diff --git a/core/sql/exp/exp_fixup.cpp b/core/sql/exp/exp_fixup.cpp
index 479ff44..c2cb36c 100644
--- a/core/sql/exp/exp_fixup.cpp
+++ b/core/sql/exp/exp_fixup.cpp
@@ -228,7 +228,7 @@
return retcode;
clause->setExeGlobals(glob);
-
+ clause->setTcb(tcb);
clause = clause->getNextClause();
}
diff --git a/core/sql/generator/GenExplain.cpp b/core/sql/generator/GenExplain.cpp
index f766873..da9e873 100644
--- a/core/sql/generator/GenExplain.cpp
+++ b/core/sql/generator/GenExplain.cpp
@@ -958,60 +958,60 @@
description += "small_scanner: " ;
description += "ON " ;
}
- size_t BUFFER_SIZE=512;
- char buf[BUFFER_SIZE];
+ size_t TMP_BUFFER_SIZE=512;
+ char buf[TMP_BUFFER_SIZE];
if ((((ComTdbHbaseAccess *)tdb)->getHbasePerfAttributes()->dopParallelScanner())>0.0) {
description += "parallel_scanner: " ;
- snprintf(buf, BUFFER_SIZE, "%g ", ((ComTdbHbaseAccess *)tdb)->getHbasePerfAttributes()->dopParallelScanner());
+ snprintf(buf, TMP_BUFFER_SIZE, "%g ", ((ComTdbHbaseAccess *)tdb)->getHbasePerfAttributes()->dopParallelScanner());
description += buf;
}
if ( getProbes().getValue() > 0.0 ) {
description += "probes: "; // total number of probes
- snprintf(buf, BUFFER_SIZE, "%g ", getProbes().getValue());
+ snprintf(buf, TMP_BUFFER_SIZE, "%g ", getProbes().getValue());
description += buf;
}
if ( getSuccessfulProbes().getValue() > 0.0 ) {
description += "successful_probes: "; // # of probes returning data
- snprintf(buf, BUFFER_SIZE, "%g ", getSuccessfulProbes().getValue());
+ snprintf(buf, TMP_BUFFER_SIZE, "%g ", getSuccessfulProbes().getValue());
description += buf;
}
if ( getUniqueProbes().getValue() > 0.0 ) {
description += "unique_probes: "; // # of probes returning 1 row
- snprintf(buf, BUFFER_SIZE, "%g ", getUniqueProbes().getValue());
+ snprintf(buf, TMP_BUFFER_SIZE, "%g ", getUniqueProbes().getValue());
description += buf;
}
if ( getDuplicatedSuccProbes().getValue() > 0.0 ) {
description += "duplicated_succ_probes: "; // # of succ probes returning
- snprintf(buf, BUFFER_SIZE, "%g ", getDuplicatedSuccProbes().getValue()); // more than 1 row
+ snprintf(buf, TMP_BUFFER_SIZE, "%g ", getDuplicatedSuccProbes().getValue()); // more than 1 row
description += buf;
}
if ( getEstRowsAccessed().getValue() ) {
description += "rows_accessed: "; // # rows accessed
- snprintf(buf, BUFFER_SIZE, "%g ", getEstRowsAccessed().getValue());
+ snprintf(buf, TMP_BUFFER_SIZE, "%g ", getEstRowsAccessed().getValue());
description += buf;
}
if (((ComTdbHbaseAccess *)tdb)->getHbaseSnapshotScanAttributes()->getUseSnapshotScan())
{
description += "use_snapshot_scan: ";
- snprintf(buf, BUFFER_SIZE, "%s ", "TRUE" );
+ snprintf(buf, TMP_BUFFER_SIZE, "%s ", "TRUE" );
description += buf;
description += "full_table_name: ";
- snprintf(buf, BUFFER_SIZE, "%s ", ((ComTdbHbaseAccess *)tdb)->getTableName());
+ snprintf(buf, TMP_BUFFER_SIZE, "%s ", ((ComTdbHbaseAccess *)tdb)->getTableName());
description += buf;
description += "snapshot_name: ";
- snprintf(buf, BUFFER_SIZE, "%s ", ((ComTdbHbaseAccess *)tdb)->getHbaseSnapshotScanAttributes()->getSnapshotName());
+ snprintf(buf, TMP_BUFFER_SIZE, "%s ", ((ComTdbHbaseAccess *)tdb)->getHbaseSnapshotScanAttributes()->getSnapshotName());
description += buf;
description += "snapshot_temp_location: ";
- snprintf(buf, BUFFER_SIZE, "%s ", ((ComTdbHbaseAccess *)tdb)->getHbaseSnapshotScanAttributes()->getSnapScanTmpLocation());
+ snprintf(buf, TMP_BUFFER_SIZE, "%s ", ((ComTdbHbaseAccess *)tdb)->getHbaseSnapshotScanAttributes()->getSnapScanTmpLocation());
description += buf;
}
@@ -1036,7 +1036,7 @@
// now get columns_retrieved
description += "columns_retrieved: ";
//sprintf(buf, "%d ", retrievedCols().entries());
- snprintf(buf, BUFFER_SIZE, "%d ", getIndexDesc()->getIndexColumns().entries());
+ snprintf(buf, TMP_BUFFER_SIZE, "%d ", getIndexDesc()->getIndexColumns().entries());
description += buf;
*/
diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp
index 6968b96..88edc4b 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -12370,3 +12370,39 @@
// Done.
return this;
}
+
+ItemExpr * SplitPart::preCodeGen(Generator *generator)
+{
+ if (nodeIsPreCodeGenned())
+ return this;
+
+ child(0) = child(0)->preCodeGen(generator);
+ if (! child(0).getPtr())
+ return NULL;
+
+ child(1) = child(1)->preCodeGen(generator);
+ if (! child(1).getPtr())
+ return NULL;
+
+ for (Int32 i = 2; i < getArity(); i++)
+ {
+ if (child(i))
+ {
+ const NAType &typ1 = child(i)->getValueId().getType();
+
+ //Insert a cast node to convert child to an INT.
+ child(i) = new (generator->wHeap())
+ Cast(child(i), new (generator->wHeap()) SQLInt(generator->wHeap(), TRUE,
+ typ1.supportsSQLnullLogical()));
+
+ child(i)->bindNode(generator->getBindWA());
+ child(i) = child(i)->preCodeGen(generator);
+ if (! child(i).getPtr())
+ return NULL;
+
+ }
+ }
+
+ markAsPreCodeGenned();
+ return this;
+}
diff --git a/core/sql/optimizer/EncodedValue.cpp b/core/sql/optimizer/EncodedValue.cpp
index f05297a..f8c6b7b 100644
--- a/core/sql/optimizer/EncodedValue.cpp
+++ b/core/sql/optimizer/EncodedValue.cpp
@@ -648,8 +648,62 @@
void
EncodedValue::constructorFunction (const NAWchar * theValue,
const NAColumnArray &columns,
+ NABoolean okToReportErrors,
ConstValue* cvPtrs[])
{
+ // Some notes about error reporting for this function:
+ //
+ // The error reporting for this function is a little strange
+ // and should be re-engineered when we can imagine a better
+ // design for it.
+ //
+ // This function is called from two very different contexts.
+ //
+ // One is from the constructors of global objects, to provide
+ // convenient encoded constants. Being global objects, this
+ // call is made as a result of global constructor calls before
+ // the C++ main for the process is invoked. As such, we cannot
+ // depend on other global objects being constructed. So, for
+ // example, we cannot depend on CmpCommon::diags() being
+ // initialized, as C++ makes no guarantees about the order in
+ // which global objects are created. Too, it does no good to
+ // throw a C++ exception as there would be nothing to catch it
+ // and process it. So, if an error happens in this code path,
+ // we'll simply assert.
+ //
+ // The other is in the course of histogram processing. Histograms
+ // have been read in, and now we want to encode the boundary
+ // values in the histogram. These might be stale or corrupted
+ // so that condition has to be detected. When detected, this
+ // routine raises a warning in CmpCommon::diags(), and then
+ // throws a C++ exception.
+ //
+ // This warning processing has to be done carefully. The way
+ // it works is that lower level routines report errors into
+ // CmpCommon::diags(). This routine checks for such errors and
+ // if it sees any, it throws them away, replacing them with
+ // a warning in CmpCommon::diags(). It then throws a C++
+ // exception which is typically caught by HSHistogrmCursor::fetch
+ // (ustat/hs_read.cpp). We use default histograms in that case.
+ //
+ // Why do we throw away the errors? We do this because of the
+ // way the Normalizer handles CmpCommon::diags(). During
+ // synthesise logical properties processing, histograms may
+ // be read and processed. (Note: They can be read and processed
+ // from other phases as well, such as table analysis.) The
+ // Normalizer checks for errors in CmpCommon::diags(), and if
+ // found, retries compilation. On the retry, CmpCommon::diags()
+ // will be cleared, and the histograms code will simply use
+ // a default histogram. So, if there is any error in
+ // CmpCommon::diags(), we will lose the histogram warnings
+ // generated in this method.
+ //
+ // Note that if there is already an error in CmpCommon::diags()
+ // when this method is called, we'll lose the histogram warnings
+ // anyway. Sigh.
+
+ Lng32 mark = okToReportErrors ? CmpCommon::diags()->mark() : -1;
+
// Find the first non-blank char.
const NAWchar *item = theValue;
while (*item == L' ')
@@ -657,10 +711,17 @@
if ( *item != L'(' ) // must be '('
{
- *CmpCommon::diags() << DgSqlCode(CATALOG_HISTOGRM_HISTINTS_TABLES_CONTAIN_BAD_VALUE)
+ if (okToReportErrors)
+ {
+ *CmpCommon::diags() << DgSqlCode(CATALOG_HISTOGRM_HISTINTS_TABLES_CONTAIN_BAD_VALUE)
<< DgWString0(theValue)
<< DgString1(columns[0]->getFullColRefNameAsAnsiString());
- CmpInternalException("Bad Interval Boundary", __FILE__ , __LINE__).throwException();
+ CmpInternalException("Bad Interval Boundary", __FILE__ , __LINE__).throwException();
+ }
+ else
+ {
+ CMPASSERT(FALSE); // developer needs to fix the bug
+ }
}
item++;
@@ -766,11 +827,19 @@
if ( next == NULL ) // should never happen!
{
- *CmpCommon::diags()
+ if (okToReportErrors)
+ {
+ CmpCommon::diags()->rewind(mark,TRUE); // get rid of any diags we may have added
+ *CmpCommon::diags()
<< DgSqlCode(CATALOG_HISTOGRM_HISTINTS_TABLES_CONTAIN_BAD_VALUE)
<< DgWString0(theValue)
<< DgString1(columns[i]->getFullColRefNameAsAnsiString());
- CmpInternalException("Bad Interval Boundary", __FILE__ , __LINE__).throwException();
+ CmpInternalException("Bad Interval Boundary", __FILE__ , __LINE__).throwException();
+ }
+ else
+ {
+ CMPASSERT(FALSE); // developer needs to fix the bug
+ }
}
Lng32 len = BOUNDARY_LEN;
@@ -803,6 +872,10 @@
break;
}
+ // Parser assumes CmpCommon::diags() is initialized and available
+ // so okToReportErrors better be true in this code path.
+ CMPASSERT(okToReportErrors);
+
// invoke parser to parse the char string and generate a ConstValue
Parser parser(CmpCommon::context());
@@ -863,9 +936,7 @@
(entries == 1 &&
constVal->getType()->getTypeQualifier() != colType->getTypeQualifier()))
{
- if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_))
- CmpCommon::diags()->deleteError(0);
-
+ CmpCommon::diags()->rewind(mark,TRUE); // get rid of any diags parser may have added
*CmpCommon::diags()
<< DgSqlCode(CATALOG_HISTOGRM_HISTINTS_TABLES_CONTAIN_BAD_VALUE)
<< DgWString0(theValue)
diff --git a/core/sql/optimizer/EncodedValue.h b/core/sql/optimizer/EncodedValue.h
index 961adeb..4bc5e84 100644
--- a/core/sql/optimizer/EncodedValue.h
+++ b/core/sql/optimizer/EncodedValue.h
@@ -165,24 +165,27 @@
// construct a multi-attribute value given a string representation
// of the multi-attribute value, and a description of the columns
+
+ // Note: This constructor is used to construct global objects, so
+ // it cannot report errors.
EncodedValue (const NAWchar *theValue)
: valueList_(NULL), heap_(HISTHEAP)
{
const NAColumnArray empty ((CollHeap*) 0 /* NULL CollHeap* */) ;
- constructorFunction (theValue, empty) ;
+ constructorFunction (theValue, empty, FALSE) ;
}
EncodedValue (const wchar_t *theValue, const NAColumnArray &columns,
ConstValue* cvPtrs[] = NULL)
: valueList_(NULL), heap_(HISTHEAP)
- { constructorFunction (theValue, columns, cvPtrs) ; }
+ { constructorFunction (theValue, columns, TRUE, cvPtrs) ; }
EncodedValue (const NAWchar *theValue, const NAColumn * column)
: valueList_(NULL), heap_(HISTHEAP)
{
NAColumnArray columns ;
columns.insertAt (0,(NAColumn*)(column)) ;
- constructorFunction (theValue, columns) ;
+ constructorFunction (theValue, columns, TRUE) ;
}
EncodedValue (const EncodedValue & other, NAMemory * h = 0);
@@ -192,7 +195,7 @@
// thing, I've created a non-ctor function that both of them
// call. Sooner or later we can stop using the ctor that takes
// a NAColumnArray as its parameter ...
- void constructorFunction (const wchar_t * theValue, const NAColumnArray & columns, ConstValue** cvPtr = NULL) ;
+ void constructorFunction (const wchar_t * theValue, const NAColumnArray & columns, NABoolean okToReportErrors, ConstValue** cvPtr = NULL) ;
public:
// construct a single-attribute value from a constant or list of constants
diff --git a/core/sql/optimizer/ItemFunc.h b/core/sql/optimizer/ItemFunc.h
index 0dd901e..249c09b 100644
--- a/core/sql/optimizer/ItemFunc.h
+++ b/core/sql/optimizer/ItemFunc.h
@@ -5859,6 +5859,7 @@
virtual ItemExpr * copyTopNode(ItemExpr *derivedNode = NULL,
CollHeap *outheap = 0);
+ virtual ItemExpr * preCodeGen(Generator*);
}; //class SplitPart
#endif /* ITEMFUNC_H */
diff --git a/core/sql/pom.xml b/core/sql/pom.xml
index 7b143d9..6059d81 100644
--- a/core/sql/pom.xml
+++ b/core/sql/pom.xml
@@ -24,6 +24,10 @@
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
+ <repository>
+ <id>central</id>
+ <url>http://central.maven.org/maven2/</url>
+ </repository>
</repositories>
<properties>
diff --git a/core/sql/regress/core/EXPECTED038.LINUX b/core/sql/regress/core/EXPECTED038.LINUX
index aceb087..6fcb4e6 100644
--- a/core/sql/regress/core/EXPECTED038.LINUX
+++ b/core/sql/regress/core/EXPECTED038.LINUX
@@ -4723,6 +4723,11 @@
--- 4 row(s) selected.
+>>select split_part('sa:sbl:sc', ':', -4) from t038sf;
+
+*** ERROR[8691] Field position must be greater than zero, currently is -4.
+
+--- 0 row(s) selected.
>>
>>insert into T038sf values(110, 'a/b/c', 'sa/dsd/s');
diff --git a/core/sql/regress/core/FILTERRTS b/core/sql/regress/core/FILTERRTS
index 3832ed8..336b16a 100755
--- a/core/sql/regress/core/FILTERRTS
+++ b/core/sql/regress/core/FILTERRTS
@@ -113,4 +113,5 @@
/pertableStats/{N
s/pertableStats\n[0-9 ,]*/@pertableStats@/
}
+s/pertableStats[0-9 ,()|a-z]*/@pertableStats@/
" $fil
diff --git a/core/sql/regress/core/TEST038 b/core/sql/regress/core/TEST038
index 593822e..cad203e 100755
--- a/core/sql/regress/core/TEST038
+++ b/core/sql/regress/core/TEST038
@@ -1148,6 +1148,7 @@
-- **EMPTY RESULT**
select split_part('sa:sbl:sc', ':', 0) from t038sf;
select split_part('sa:sbl:sc', ':', 4) from t038sf;
+select split_part('sa:sbl:sc', ':', -4) from t038sf;
insert into T038sf values(110, 'a/b/c', 'sa/dsd/s');
insert into T038sf values(111, 'sasd', 'dsa:/~sd');
diff --git a/core/sql/regress/seabase/EXPECTED012 b/core/sql/regress/seabase/EXPECTED012
index 5206fd8..c6acec1 100644
--- a/core/sql/regress/seabase/EXPECTED012
+++ b/core/sql/regress/seabase/EXPECTED012
@@ -433,7 +433,6 @@
TRAFODION.ZSCHEMA1.V
TRAFODION.ZSCHEMA2.T
-
=======================
3 row(s) returned
diff --git a/core/sql/regress/seabase/EXPECTED024 b/core/sql/regress/seabase/EXPECTED024
index 82212b8..25556ae 100644
--- a/core/sql/regress/seabase/EXPECTED024
+++ b/core/sql/regress/seabase/EXPECTED024
@@ -181,6 +181,9 @@
TEST024SEQ6
TEST024SEQ7
+=======================
+ 7 row(s) returned
+
--- SQL operation complete.
>>set schema seqsch;
diff --git a/core/sql/regress/seabase/EXPECTED027 b/core/sql/regress/seabase/EXPECTED027
index 67bcfd9..0972679 100644
--- a/core/sql/regress/seabase/EXPECTED027
+++ b/core/sql/regress/seabase/EXPECTED027
@@ -1176,6 +1176,9 @@
TRAFODION.SCH027.T027V1
+=======================
+ 1 row(s) returned
+
--- SQL operation complete.
>>invoke t027v1;
@@ -1249,6 +1252,9 @@
TRAFODION.SCH027.T027V1
+=======================
+ 1 row(s) returned
+
--- SQL operation complete.
>>
>>-- tests for alter column rename
@@ -1434,6 +1440,9 @@
TRAFODION.SCH027.T027V12
TRAFODION.SCH027.T027V122
+=======================
+ 5 row(s) returned
+
--- SQL operation complete.
>>alter table t027t7 alter column a varchar(20);
@@ -1449,6 +1458,9 @@
TRAFODION.SCH027.T027V12
TRAFODION.SCH027.T027V122
+=======================
+ 5 row(s) returned
+
--- SQL operation complete.
>>
>>-- some alter operations cannot be performed within a user xn
diff --git a/core/sql/ustat/hs_globals.cpp b/core/sql/ustat/hs_globals.cpp
index b033e65..d6069e8 100644
--- a/core/sql/ustat/hs_globals.cpp
+++ b/core/sql/ustat/hs_globals.cpp
@@ -3186,38 +3186,13 @@
DeleteHSContext(contID_);
}
+
// -----------------------------------------------------------------------
-//
+// Initialize stats schema for Hive or native HBase tables if needed
// -----------------------------------------------------------------------
-Lng32 HSGlobalsClass::Initialize()
+Lng32 HSGlobalsClass::InitializeStatsSchema()
{
Lng32 retcode = 0;
- NAString query;
- HSCursor cursor;
- Int64 xSampleSet = 0;
- char intStr[30], intStr2[30];
- Int64 inserts, deletes, updates;
- HSLogMan *LM = HSLogMan::Instance();
- HSGlobalsClass *hs_globals = GetHSContext();
-
- // Seed the random number generator used in quicksort().
- srand(time(NULL));
- // Set the default catalog names for Hive and HBase.
- if (defaultHiveCatName == NULL)
- defaultHiveCatName = new (GetCliGlobals()->exCollHeap()) NAString("");
- else
- (*defaultHiveCatName) = "";
-
- CmpCommon::getDefault(HIVE_CATALOG, (*defaultHiveCatName), FALSE);
- (*defaultHiveCatName).toUpper();
-
- if (defaultHbaseCatName == NULL)
- defaultHbaseCatName = new (GetCliGlobals()->exCollHeap()) NAString("");
- else
- (*defaultHbaseCatName) = "";
-
- CmpCommon::getDefault(HBASE_CATALOG, (*defaultHbaseCatName), FALSE);
- (*defaultHbaseCatName).toUpper();
/*==============================*/
/* CREATE HIVE STATS SCHEMA */
@@ -3260,6 +3235,47 @@
retcode = CreateHistTables(this);
HSHandleError(retcode);
+ return retcode;
+ }
+
+
+
+// -----------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------
+Lng32 HSGlobalsClass::Initialize()
+ {
+ Lng32 retcode = 0;
+ NAString query;
+ HSCursor cursor;
+ Int64 xSampleSet = 0;
+ char intStr[30], intStr2[30];
+ Int64 inserts, deletes, updates;
+ HSLogMan *LM = HSLogMan::Instance();
+ HSGlobalsClass *hs_globals = GetHSContext();
+
+ // Seed the random number generator used in quicksort().
+ srand(time(NULL));
+ // Set the default catalog names for Hive and HBase.
+ if (defaultHiveCatName == NULL)
+ defaultHiveCatName = new (GetCliGlobals()->exCollHeap()) NAString("");
+ else
+ (*defaultHiveCatName) = "";
+
+ CmpCommon::getDefault(HIVE_CATALOG, (*defaultHiveCatName), FALSE);
+ (*defaultHiveCatName).toUpper();
+
+ if (defaultHbaseCatName == NULL)
+ defaultHbaseCatName = new (GetCliGlobals()->exCollHeap()) NAString("");
+ else
+ (*defaultHbaseCatName) = "";
+
+ CmpCommon::getDefault(HBASE_CATALOG, (*defaultHbaseCatName), FALSE);
+ (*defaultHbaseCatName).toUpper();
+
+ // initialize stats schema if this is a Hive or native HBase table
+ retcode = InitializeStatsSchema();
+ HSHandleError(retcode);
/*==============================*/
/* CREATE UNDOCUMENTED VIEW */
@@ -15973,6 +15989,10 @@
if (!hs_globals) retcode = -1;
else
{
+ // initialize stats schema if our object is a Hive or native HBase table
+ retcode = hs_globals->InitializeStatsSchema();
+ HSHandleError(retcode);
+
NAString table;
Int64 sampleRows, tableRows;
NABoolean isEstimate = FALSE;
diff --git a/core/sql/ustat/hs_globals.h b/core/sql/ustat/hs_globals.h
index ac05497..2f8f4f9 100644
--- a/core/sql/ustat/hs_globals.h
+++ b/core/sql/ustat/hs_globals.h
@@ -1472,6 +1472,9 @@
HSGlobalsClass(ComDiagsArea &diags);
~HSGlobalsClass();
+ // Intialize stats schema on demand
+ Lng32 InitializeStatsSchema();
+
//Process USTAT options
Lng32 Initialize();
diff --git a/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc b/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc
index b1bed39..adba842 100644
--- a/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc
+++ b/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc
@@ -7069,7 +7069,7 @@
image::grouping-by-three-rollup-columns.jpg[700,700]
+
-** First-level: the rows marked in *blue* are the total revenue for each year (_2016_ and _2017_), each region (_A_ and _B_) and each product (_Dress_ and _Pullover_), they are caculated by GROUP BY instead of ROLLUP.
+** First-level: the rows marked in *blue* are the total revenue for each year (_2016_ and _2017_), each region (_A_ and _B_) and each product (_Dress_ and _Pullover_), they are calculated by GROUP BY instead of ROLLUP.
+
** Second-level: the rows marked in *red* provide the total revenue for the given _delivery_year_ and _region_ by _product_.
@@ -9066,13 +9066,220 @@
TO_CHAR(character-expression [,format-string])
```
+[[to_char_syntax]]
+=== Syntax Description of TO_CHAR
+
* `_character-expression_`
+
is an expression that gives a datetime value.
* `_format-string_`
+
-is one of the following character string literals:
+.Details of `_format-string_`
+[cols="3*.^"]
+|===
+^| *Supported* `_character-expression_`
+^| *`_format-string_`*
+^| *Description*
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'CC'
+| Two-digit century.
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'D'
+| Day of week (1-7), where 1 is Sunday, 6 is Saturday. +
+This is not configurable.
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'DD'
+| Day of month (01-31).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'DDD'
+| Day of year (001-366).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'DY'
+a| Name of day, which is a three-letter abbreviation for the day in uppercase. +
+
+The following values are returned: +
+
+* MON +
+
+* TUE +
+
+* WED +
+
+* THU +
+
+* FRI +
+
+* SAT +
+
+* SUN
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'DAY'
+a| Name of day, which is full uppercase day name padded with blanks to the length of 9 characters. +
+
+The following values are returned: +
+
+* MONDAY +
+
+* TUESDAY +
+
+* WEDSDAY +
+
+* THURSDAY +
+
+* FRIDAY +
+
+* SATURDAY +
+
+* SUNDAY
+
+a| * `_datetime-expression_`
+** TIME
+** TIMESTAMP
+| 'HH'
+| Hour of day in 24-hour format (00-23). +
+'HH' behaves the same as 'HH24'.
+
+a| * `_datetime-expression_`
+** TIME
+** TIMESTAMP
+| 'HH12'
+| Hour of day in 12-hour format (01-12).
+
+a| * `_datetime-expression_`
+** TIME
+** TIMESTAMP
+| 'HH24'
+| Hour of day in 24-hour format (00-23). +
+'HH24' behaves the same as 'HH'.
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'J'
+| Julian date (that is, number of days since January 1, 4713 BC).
+
+a| * `_datetime-expression_`
+** TIME
+** TIMESTAMP
+| 'MI'
+| Minute (00-59).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'MM'
+| Month (01-12).
+
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'MON'
+a| Month, which is a three-letter abbreviation for the month in uppercase. +
+
+The following values are returned: +
+
+* JAN +
+
+* FEB +
+
+* MAR +
+
+* APR +
+
+* MAY +
+
+* JUN +
+
+* JUL +
+
+* AUG +
+
+* SEP +
+
+* OCT +
+
+* NOV +
+
+* DEC
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'Q'
+| Quarter (1-4).
+
+a| * `_datetime-expression_`
+** TIME
+** TIMESTAMP
+| 'SS'
+| Second (00-59).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'W'
+| Week of month.
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'WW'
+a| Week of year. +
+
+* The value 1 is returned for a datetime that occurs in the first 7 days of the year if the year begins on Sunday. +
+Otherwise, the value 1 is returned for a datetime that occurs in the partial week before the start of the first Sunday.
+
+* The value *53* is returned for a datetime that occurs in the last full or partial week of the year.
+
+* The value *54* is returned for a datetime that occurs in the last full or partial week of the leap year where begins on Saturday.
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'Y'
+| Last digit of year (0-9).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'YY'
+| Last two digits of year (00-99).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'YYY'
+| Last three digits of year (000-999).
+
+a| * `_datetime-expression_`
+** DATE
+** TIMESTAMP
+| 'YYYY'
+| Four-digit year (0001-9999).
+|===
+
++
+Besides the `_format-string_` listed above, the following character string literals are also valid:
** 'YYYY-MM-DD'
** 'MM/DD/YYYY'
@@ -9098,30 +9305,606 @@
** 'MM/DD/YYYY HH24:MI:SS'
** 'DD-MON-YYYY HH:MI:SS'
** 'MONTH DD, YYYY, HH:MI'
-** 'DD.MM.YYYY HH24.MI.SS'
+** 'DD.MM.YYYY HH24.MI.SS'
-Here, YYYY refers to a 4-digit year. YY refers to a two-digit year. MM refers to a two-digit month. MON refers to
-a three-letter abbreviation for month ('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP',
-'OCT', 'NOV' or 'DEC'). MONTH refers to the month spelled out. In the output value, the month abbreviation or month
++
+Here:
+
+*** YYYY refers to a four-digit year.
+*** YY refers to a two-digit year.
+*** MM refers to a two-digit month.
+*** MON refers to a three-letter abbreviation for month ('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP',
+'OCT', 'NOV' or 'DEC').
+*** MONTH refers to the month spelled out. In the output value, the month abbreviation or month
will appear in upper case.
-
-HH and HH24 refer to a 2-digit hour field. MI refers to a two-digit minutes field. SS refers to a 2-digit seconds field.
-
-If the _format-string_ argument is omitted, 'YYYY-MM-DD' is used as the
+*** HH and HH24 refer to a two-digit hour field.
+*** MI refers to a two-digit minutes field.
+*** SS refers to a two-digit seconds field.
+*** If the `_format-string_` argument is omitted, 'YYYY-MM-DD' is used as the
default for date and timestamp values, and 'HH:MI:SS' is used for time values.
[[considerations_for_to_char]]
=== Considerations for TO_CHAR
-If the _format-string_ contains only hour, minute or seconds fields, the input data type must be time or timestamp.
+If the `_format-string_` contains only hour, minute or seconds fields, the input data type must be time or timestamp.
-If the _format-string_ contains only year, month or day fields, the input data type must be date or timestamp.
+If the `_format-string_` contains only year, month or day fields, the input data type must be date or timestamp.
-If the _format-string_ contains all fields, and the input data type is date, the hour, minute and second fields in the result will be filled with zeroes.
+If the `_format-string_` contains all fields, and the input data type is date, the hour, minute and second fields in the result will be filled with zeroes.
[[examples_of_to_char]]
=== Examples of TO_CHAR
+[[examples_of_to_char_cc]]
+==== Examples of TO_CHAR (CC)
+
+* This example converts the `_DATE_` value to the character value of century.
++
+```
+SQL>SELECT TO_CHAR (DATE '0001-11-02','CC') FROM DUAL;
+
+(EXPR)
+------
+01
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of century.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '9899-12-31 23:59:59','CC') FROM DUAL;
+
+(EXPR)
+------
+99
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_d]]
+==== Examples of TO_CHAR (D)
+
+* This example converts the `_DATE_` value to the character value of day of week.
++
+```
+SQL>SELECT TO_CHAR (DATE '2018-01-01','D') FROM DUAL;
+
+(EXPR)
+------
+2
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of day of week.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2018-04-01 23:59:59','D') FROM DUAL;
+
+(EXPR)
+------
+1
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_dd]]
+==== Examples of TO_CHAR (DD)
+
+* This example converts the `_DATE_` value to the character value of day of month.
++
+```
+SQL>SELECT TO_CHAR (DATE '2018-01-01','DD') FROM DUAL;
+
+(EXPR)
+------
+01
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of day of month.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2018-12-31 23:59:59','DD') FROM DUAL;
+
+(EXPR)
+------
+31
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_ddd]]
+==== Examples of TO_CHAR (DDD)
+
+* This example converts the `_DATE_` value to the character value of day of year.
++
+```
+SQL>SELECT TO_CHAR (DATE '2018-01-01','DDD') FROM DUAL;
+
+(EXPR)
+------
+001
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of day of year.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2020-12-31 23:59:59','DDD') FROM DUAL;
+
+(EXPR)
+------
+366
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_dy]]
+==== Examples of TO_CHAR (DY)
+
+* This example converts the `_DATE_` value to the character value of name of day (abbreviation).
++
+```
+SQL>SELECT TO_CHAR (DATE '2018-12-31','DY') FROM DUAL;
+
+(EXPR)
+------
+MON
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of name of day (abbreviation).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-02-14 23:59:59','DY') FROM DUAL;
+
+(EXPR)
+------
+THU
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_day]]
+==== Examples of TO_CHAR (DAY)
+
+* This example converts the `_DATE_` value to the character value of name of day.
++
+```
+SQL>SELECT TO_CHAR (DATE '2019-05-12','DAY') FROM DUAL;
+
+(EXPR)
+---------
+SUNDAY
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of name of day.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-12-24 23:59:59','DAY') FROM DUAL;
+
+(EXPR)
+---------
+TUESDAY
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_hh]]
+==== Examples of TO_CHAR (HH)
+
+* This example converts the `_TIME_` value to the character value of hour (24-hour format).
++
+```
+SQL>SELECT TO_CHAR (TIME '00:00:01','HH') FROM DUAL;
+
+(EXPR)
+------
+00
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of hour (24-hour format).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-01-01 23:59:59','HH') FROM DUAL;
+
+(EXPR)
+------
+23
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_hh12]]
+==== Examples of TO_CHAR (HH12)
+
+* This example converts the `_TIME_` value to the character value of hour (12-hour format).
++
+```
+SQL>SELECT TO_CHAR (TIME '01:00:00','HH12') FROM DUAL;
+
+(EXPR)
+------
+01
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of hour (12-hour format).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-01-01 12:59:59','HH12') FROM DUAL;
+
+(EXPR)
+------
+12
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_hh24]]
+==== Examples of TO_CHAR (HH24)
+
+* This example converts the `_TIME_` value to the character value of hour (24-hour format).
++
+```
+SQL>SELECT TO_CHAR (TIME '00:00:01','HH24') FROM DUAL;
+
+(EXPR)
+------
+00
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of hour (24-hour format).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-01-01 23:59:59','HH24') FROM DUAL;
+
+(EXPR)
+------
+23
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_j]]
+==== Examples of TO_CHAR (J)
+
+* This example calculates the number of days since the beginning of the Julian epoch and converts the `_DATE_` value to the character value.
++
+```
+SQL>SELECT TO_CHAR (DATE '0001-01-01','J') FROM DUAL;
+
+(EXPR)
+-------
+1721426
+
+--- 1 row(s) selected.
+```
+
+* This example calculates the number of days since the beginning of the Julian epoch and converts the `_TIMESTAMP_` value to the character value.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2018-11-02 23:59:59','J') FROM DUAL;;
+
+(EXPR)
+-------
+2458425
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_mi]]
+==== Examples of TO_CHAR (MI)
+
+* This example converts the `_TIME_` value to the character value of minute.
++
+```
+SQL>SELECT TO_CHAR (TIME '01:00:02','MI') FROM DUAL;
+
+(EXPR)
+------
+00
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of minute.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-01-01 23:59:01','MI') FROM DUAL;
+
+(EXPR)
+------
+59
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_mm]]
+==== Examples of TO_CHAR (MM)
+
+* This example converts the `_DATE_` value to the character value of month.
++
+```
+SQL>SELECT TO_CHAR (DATE '0001-01-01','MM') FROM DUAL;
+
+(EXPR)
+------
+01
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of month.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-01-01 23:59:59','MM') FROM DUAL;
+
+(EXPR)
+------
+12
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_mon]]
+==== Examples of TO_CHAR (MON)
+
+* This example converts the `_DATE_` value to the character value of month.
++
+```
+SQL>SELECT TO_CHAR (DATE '0001-01-01','MON') FROM DUAL;
+
+(EXPR)
+------
+JAN
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of month.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2018-11-02 23:59:59','MON') FROM DUAL;
+
+(EXPR)
+------
+NOV
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_quarter]]
+==== Examples of TO_CHAR (QUARTER)
+
+* This example converts the `_DATE_` value to the character value of quarter.
++
+```
+SQL>SELECT TO_CHAR (DATE '0001-01-01','Q') FROM DUAL;
+
+(EXPR)
+------
+1
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of quarter.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2018-11-02 23:59:59','Q') FROM DUAL;
+
+(EXPR)
+------
+4
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_ss]]
+==== Examples of TO_CHAR (SS)
+
+* This example converts the `_TIME_` value to the character value of second.
++
+```
+SQL>SELECT TO_CHAR (TIME '01:02:00','SS') FROM DUAL;
+
+(EXPR)
+------
+00
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of second.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2019-01-01 23:01:59','SS') FROM DUAL;
+
+(EXPR)
+------
+59
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_w]]
+==== Examples of TO_CHAR (W)
+
+* This example converts the `_DATE_` value to the character value of week of month.
++
+```
+SQL>SELECT TO_CHAR (DATE '2019-01-01','W') FROM DUAL;
+
+(EXPR)
+------
+1
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of week of month.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2018-04-30 23:59:59','W') FROM DUAL;
+
+(EXPR)
+------
+5
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_ww]]
+==== Examples of TO_CHAR (WW)
+
+* This example converts the `_DATE_` value to the character value of week of year.
++
+```
+SQL>SELECT TO_CHAR (DATE '2016-01-03','WW') FROM DUAL;
+
+(EXPR)
+------
+02
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of week of year.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '2000-12-31 23:59:59','WW') FROM DUAL;
+
+(EXPR)
+------
+54
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_y]]
+==== Examples of TO_CHAR (Y)
+
+* This example converts the `_DATE_` value to the character value of week of year (last digit).
++
+```
+SQL>SELECT TO_CHAR (DATE '1000-01-01','Y') FROM DUAL;
+
+(EXPR)
+------
+0
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of week of year (last digit).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '9999-12-31 23:59:59','Y') FROM DUAL;
+
+(EXPR)
+------
+9
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_yy]]
+==== Examples of TO_CHAR (YY)
+
+* This example converts the `_DATE_` value to the character value of week of year (last two digits).
++
+```
+SQL>SELECT TO_CHAR (DATE '1000-01-01','YY') FROM DUAL;
+
+(EXPR)
+------
+00
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of week of year (last two digits).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '9999-12-31 23:59:59','YY') FROM DUAL;
+
+(EXPR)
+------
+99
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_yyy]]
+==== Examples of TO_CHAR (YYY)
+
+* This example converts the `_DATE_` value to the character value of week of year (last three digits).
++
+```
+SQL>SELECT TO_CHAR (DATE '1000-01-01','YYY') FROM DUAL;
+
+(EXPR)
+------
+000
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of week of year (last three digits).
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '9999-12-31 23:59:59','YYY') FROM DUAL;
+
+(EXPR)
+------
+999
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_yyyy]]
+==== Examples of TO_CHAR (YYYY)
+
+* This example converts the `_DATE_` value to the character value of week of year.
++
+```
+SQL>SELECT TO_CHAR (DATE '0001-01-01','YYYY') FROM DUAL;
+
+(EXPR)
+------
+0001
+
+--- 1 row(s) selected.
+```
+
+* This example converts the `_TIMESTAMP_` value to the character value of week of year.
++
+```
+SQL>SELECT TO_CHAR (TIMESTAMP '9999-12-31 23:59:59','YYYY') FROM DUAL;
+
+(EXPR)
+------
+9999
+
+--- 1 row(s) selected.
+```
+
+[[examples_of_to_char_other]]
+==== Examples of TO_CHAR (Other)
+
* This function returns the character value '01MAR2016':
+
```
diff --git a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
index 1d338b6..e603708 100644
--- a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
@@ -288,10 +288,6 @@
return SQL_SUCCESS;
}
- //if (targetPrecision < 19)
- if (((SQLDataType == SQLTYPECODE_NUMERIC) && (targetPrecision <= 18)) ||
- ((SQLDataType == SQLTYPECODE_NUMERIC_UNSIGNED) && (targetPrecision <= 9)))
- getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
switch (ODBCDataType)
{
@@ -756,6 +752,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -848,6 +845,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -1435,6 +1433,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -1490,6 +1489,7 @@
}
if(negative && targetUnsigned)
return IDS_22_003_02;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ((integralPart < 0) || (integralPart > integralMax))
return IDS_22_003;
decimalDigits = 0;
@@ -1598,6 +1598,7 @@
integralPart = (integralPart < 0)? -integralPart: integralPart;
decimalPart = 0;
leadZeros = 0;
+ getMaxNum(targetPrecision, targetScale, integralMax, decimalMax);
if ( integralPart > integralMax )
return IDS_22_003;