Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

[TRAFODION-3034] Support Oracle Hierarchy Query (Connect By) #1688

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5fb8f21
[TRAFODION-3034] add parser changes
moscowgentalman Jun 1, 2018
b29f4dd
basic work finish
moscowgentalman Jul 17, 2018
88e8b20
fix parser, add loop detection
moscowgentalman Jul 21, 2018
9fb3a59
refactor the code, next need to add CQD and where clause support
moscowgentalman Jul 23, 2018
b875ec3
support where clause, next add CQD to control memory usage
moscowgentalman Jul 25, 2018
1b853c5
support where clause, next add regression test
moscowgentalman Jul 26, 2018
f20b63c
support both where clause and order by, next add test cases
moscowgentalman Jul 27, 2018
5757f25
add test case, next to rebase and try to support is_cycle
moscowgentalman Jul 28, 2018
73a175a
Merge branch 'master' of git://git.apache.org/trafodion into TRAFODIO…
moscowgentalman Jul 28, 2018
1b32b6b
support PATH, next try to support is leaf
moscowgentalman Aug 4, 2018
81ef30d
add ISLEAF support, but need to wait for another enhancement
moscowgentalman Aug 5, 2018
d781d88
finish is leaf
moscowgentalman Aug 7, 2018
cc9057d
Merge branch 'master' of git://git.apache.org/trafodion into TRAFODIO…
moscowgentalman Aug 7, 2018
8ae2ed9
first phase finished
moscowgentalman Aug 10, 2018
26d9b06
fix regression test case and remove some dead code
moscowgentalman Aug 10, 2018
6dd9c8e
handle the null value
moscowgentalman Aug 11, 2018
d6fb419
rework the compiler part, move the processing into binder to support …
moscowgentalman Aug 25, 2018
e1a5911
add support for order by siblyings
moscowgentalman Aug 25, 2018
caed495
fix reduce/shift conflict
moscowgentalman Aug 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/sql/bin/SqlciErrors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,9 @@ $1~String1 --------------------------------
8034 ZZZZZ 99999 ADVANCED MAJOR DBADMIN Column $0~String0 of object $1~string1 does not have a default clause but it is missing in database. This indicates inconsistent data.
8035 ZZZZZ 99999 ADVANCED MAJOR DBADMIN Truncation of hive table failed. $0~String0
8036 ZZZZZ 99999 ADVANCED MINOR LOGONLY Error while creating the error logging file or logging the error row to file $0~String0: Details :$1~String1
8037 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Loop detected in connect by execution.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these three messages, it would help if we could give information specific to the instance when the error occurred. Maybe value of the prior column(s) as the error occurred. For the case of recursion exceeding a certain length or memory being exhausted, more details what level of recursion has been reached or how much memory has been consumed (if that information is readily available) would be helpful. This is an advisory suggestion, and by no means something to be addressed soon.

I would have expected some binder errors for statements where hierarchical constructs are not supported. It is possible though unlikely that all are caught in the parser. For example what happens if a hierarchical function or pseudocolumn is used a regular (non-hierarchical query)

8038 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Exceed max recursive running depth.
8039 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Exceed max connect by memory size.
8100 ZZZZZ 99999 BEGINNER MINOR LOGONLY Define $1~string0 does not exist
8101 23000 99999 BEGINNER MAJOR DBADMIN The operation is prevented by check constraint $0~ConstraintName on table $1~TableName.
8102 23000 99999 BEGINNER MAJOR DBADMIN The operation is prevented by a unique constraint.
Expand Down
7 changes: 6 additions & 1 deletion core/sql/comexe/ComTdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ char *ComTdb::findVTblPtrCom(short classID)
GetVTblPtr(vtblptr,ComTdbCompoundStmt);
break;
}

case ex_CONNECT_BY:
{
GetVTblPtr(vtblptr,ComTdbExeUtilConnectby);
break;
}

case ex_TUPLE:
{
GetVTblPtr(vtblptr,ComTdbTuple);
Expand Down
1 change: 1 addition & 0 deletions core/sql/comexe/ComTdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class ComTdb : public NAVersionedObject
ex_HIVE_TRUNCATE = 153,
ex_LOB_UPDATE_UTIL = 154,
ex_HIVE_QUERY = 155,
ex_CONNECT_BY= 156,
ex_LAST = 9999 // not used
};

Expand Down
56 changes: 56 additions & 0 deletions core/sql/comexe/ComTdbExeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,3 +3028,59 @@ Lng32 ComTdbExeUtilLobInfo::unpack(void * base, void * reallocator)
return -1;
return ComTdbExeUtil::unpack(base, reallocator);
}

ComTdbExeUtilConnectby::ComTdbExeUtilConnectby(char * query,
ULng32 querylen,
Int16 querycharset,
char * tableName,
char * stmtName,
ex_expr * input_expr,
ULng32 input_rowlen,
ex_expr * output_expr,
ULng32 output_rowlen,
ex_expr * scan_expr,
ex_cri_desc * work_cri_desc,
const unsigned short work_atp_index,
Lng32 colDescSize,
Lng32 outputRowSize,
ex_cri_desc * given_cri_desc,
ex_cri_desc * returned_cri_desc,
queue_index down,
queue_index up,
Lng32 num_buffers,
ULng32 buffer_size,
ExCriDescPtr workCriDesc
)
: ComTdbExeUtil(ComTdbExeUtil::CONNECT_BY_,
query, querylen, querycharset,
tableName, strlen(tableName),
input_expr, input_rowlen,
output_expr, output_rowlen,
scan_expr,
work_cri_desc, work_atp_index,
given_cri_desc, returned_cri_desc,
down, up,
num_buffers, buffer_size),
flags_(0),
myWorkCriDesc_(workCriDesc),
tupleLen_(outputRowSize)
{
setNodeType(ComTdb::ex_CONNECT_BY);
connTableName_ = tableName;
maxDeep_ = 200; //by default, max deep of a tree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two literals could be consts to improve readability. It looks like there are cqds defined to make these configurable, which is excellent.

maxSize_ = 100000; //by default, the max number of rows to return for hierachy query
hasPath_ = FALSE;
hasIsLeaf_ = FALSE;
}

Long ComTdbExeUtilConnectby::pack(void * space)
{
myWorkCriDesc_.pack(space);
return ComTdbExeUtil::pack(space);
}

Lng32 ComTdbExeUtilConnectby::unpack(void * base, void * reallocator)
{
if(myWorkCriDesc_.unpack(base, reallocator)) return -1;
return ComTdbExeUtil::unpack(base, reallocator);
}
76 changes: 74 additions & 2 deletions core/sql/comexe/ComTdbExeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class ComTdbExeUtil : public ComTdbGenericUtil
GET_QID_ = 35,
HIVE_TRUNCATE_ = 36,
LOB_UPDATE_UTIL_ = 37,
HIVE_QUERY_ = 38
HIVE_QUERY_ = 38,
CONNECT_BY_ = 39
};

ComTdbExeUtil()
Expand Down Expand Up @@ -4016,7 +4017,78 @@ class ComTdbExeUtilLobInfo : public ComTdbExeUtil
NABoolean tableFormat_;

};
#endif


class ComTdbExeUtilConnectby : public ComTdbExeUtil
{
friend class ExExeUtilConnectbyTcb;

public:
ComTdbExeUtilConnectby(char * query,
ULng32 querylen,
Int16 querycharset,
char * tableName,
char * stmtName,
ex_expr * input_expr,
ULng32 input_rowlen,
ex_expr * output_expr,
ULng32 output_rowlen,
ex_expr * scan_expr,
ex_cri_desc * work_cri_desc,
const unsigned short work_atp_index,
Lng32 colDescSize,
Lng32 outputRowSize,
ex_cri_desc * given_cri_desc,
ex_cri_desc * returned_cri_desc,
queue_index down,
queue_index up,
Lng32 num_buffers,
ULng32 buffer_size,
ExCriDescPtr workCriDesc
);

ComTdbExeUtilConnectby()
: ComTdbExeUtil() { hasStartWith_ = TRUE; noCycle_ = FALSE; }

Long pack(void *);
Lng32 unpack(void *, void * reallocator);

virtual short getClassSize() {return (short)sizeof(ComTdbExeUtilConnectby);}

virtual const char *getNodeName() const
{
return "CONNECT_BY";
};
UInt16 sourceDataTuppIndex_;
NAString parentColName_;
NAString childColName_;
NAString connTableName_;
NAString startWithExprString_;
NABoolean hasStartWith_;
NABoolean noCycle_;
Int32 maxDeep_;
Int32 maxSize_;
NABoolean hasPath_;
NABoolean hasIsLeaf_;
NAString pathColName_;
NAString delimiter_;
NAString orderSiblingsByCol_;
private:
ExCriDescPtr myWorkCriDesc_;
Int32 flags_;
Int32 tupleLen_;
};

class ExExeUtilConnectbyTdb : public ComTdbExeUtilConnectby
{
public:
ExExeUtilConnectbyTdb()
{}
virtual ~ExExeUtilConnectbyTdb()
{}

virtual ex_tcb *build(ex_globals *globals);

};

#endif
2 changes: 1 addition & 1 deletion core/sql/common/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ enum UnparseFormatEnum { USER_FORMAT, EXPLAIN_FORMAT, FILE_FORMAT,
USER_FORMAT_DELUXE, ERROR_MSG_FORMAT,
MVINFO_FORMAT, MV_SHOWDDL_FORMAT,
QUERY_FORMAT, COMPUTED_COLUMN_FORMAT,
HIVE_MD_FORMAT };
HIVE_MD_FORMAT, CONNECT_BY_FORMAT };

// -----------------------------------------------------------------------
// Used to display optimizer statistics, and other debugging statements
Expand Down
4 changes: 4 additions & 0 deletions core/sql/common/OperTypeEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ enum OperatorTypeEnum {
ITM_GREATEST = 2385,
ITM_LEAST = 2386,

ITM_CONNECT_BY = 2387,

ITM_UNIQUE_EXECUTE_ID = 2391,
ITM_GET_TRIGGERS_STATUS = 2392,
ITM_GET_BIT_VALUE_AT = 2393,
Expand Down Expand Up @@ -813,6 +815,8 @@ enum OperatorTypeEnum {
ITM_AES_ENCRYPT = 2641,
ITM_AES_DECRYPT = 2642,

ITM_SYS_CONNECT_BY_PATH = 2643,

// Items for needed for Translating to UCS2 output strings
ITM_DATEFMT = 2990,
ITM_CURRNT_USER = 2991,
Expand Down
7 changes: 7 additions & 0 deletions core/sql/executor/ExComTdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ case ex_LOB_INFO:
break;
}

case ex_CONNECT_BY:
{
GetVTblPtr(vtblptr,ExExeUtilConnectbyTdb);

break;
}

default:
ex_assert(0, "findVTblPtrExe(): Cannot find entry of this ClassId");
break;
Expand Down
109 changes: 109 additions & 0 deletions core/sql/executor/ExExeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -4138,6 +4138,7 @@ class ExExeUtilLobInfoTableTcb : public ExExeUtilTcb
DONE_
};
Step step_;
char * data_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a change in a Lob class?


protected:
Int64 getEmbeddedNumValue(char* &sep, char endChar,
Expand Down Expand Up @@ -4172,6 +4173,48 @@ class ExExeUtilLobInfoPrivateState : public ex_tcb_private_state
protected:
};

class connectByStackItem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is unusual in the executor to have classes that do not have a base class. How about memory management for this class. I might understand more as I see how these classes are used.

{
public:
connectByStackItem()
{
seedValue = NULL;
pathItem = NULL;
pathLen = 0;
len = 0;
level = 0;
type = 0;
parentId = 0;
}
~connectByStackItem() {}
char * seedValue;
char * pathItem;
int len;
int level;
int type;
int pathLen;
int parentId;
};
class connectByOneRow {

public:
connectByOneRow()
{
data_ = NULL;
len = 0;
type = 0;
}
~connectByOneRow() {}
char * data_;
int len;
int type;
};

#define CONNECT_BY_DEFAULT_BATCH_SIZE 100
#define CONNECT_BY_MAX_LEVEL_SIZE 200
#define CONNECT_BY_MAX_SQL_TEXT_SIZE 2048
#define CONNECT_BY_MAX_PATH_SIZE 3000

////////////////////////////////////////////////////////////////////////////
class ExExeUtilLobInfoTablePrivateState : public ex_tcb_private_state
{
Expand All @@ -4183,6 +4226,72 @@ class ExExeUtilLobInfoTablePrivateState : public ex_tcb_private_state
protected:
};

class ExExeUtilConnectbyTcb : public ExExeUtilTcb
{
friend class ExExeUtilConnectbyTdb;

public:
ExExeUtilConnectbyTcb(const ComTdbExeUtilConnectby &exe_util_tdb,
ex_globals * glob = 0);

virtual ~ExExeUtilConnectbyTcb()
{}

virtual short work();
virtual ex_tcb_private_state * allocatePstates(
Lng32 &numElems, // inout, desired/actual elements
Lng32 &pstateLength); // out, length of one element
enum Step
{
INITIAL_,
EVAL_INPUT_,
EVAL_START_WITH_,
DO_CONNECT_BY_,
EVAL_OUTPUT_EXPR_,
NEXT_LEVEL_,
NEXT_ROOT_,
ERROR_,
DONE_
};
Step step_;
ExExeUtilConnectbyTdb& exeUtilTdb() const
{return (ExExeUtilConnectbyTdb&) tdb;};

short emitRow(ExpTupleDesc * tDesc, int level, int isleaf, int iscycle, connectByStackItem *it) ;
short emitPrevRow(ExpTupleDesc * tDesc, int level, int isleaf, int iscycle, Queue* q, int index) ;

Queue *currArray[200];
Queue * getCurrentQueue(int level) { if(level <0 || level >200) abort(); return currArray[level];}
short checkDuplicate(connectByStackItem *it,int len, int level);
int currLevel_;
Int64 resultSize_;
Queue *currQueue_;
Queue *seedQueue_;
Queue *thisQueue_;
Queue *prevQueue_;
Queue *tmpPrevQueue_;
Int32 currRootId_;
Int32 connBatchSize_ ;

protected:
ExExeUtilConnectbyTcb *tcb_;

private:
tupp tuppData_;
char * data_;
};

class ExExeUtilConnectbyTdbState : public ex_tcb_private_state
{
friend class ExExeUtilConnectbyTcb;

public:
ExExeUtilConnectbyTdbState();
~ExExeUtilConnectbyTdbState();
protected:
ExExeUtilConnectbyTcb::Step step_;
};

#endif


Expand Down
Loading