Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Schema names optional for Table Valued Functions #981

Merged
merged 76 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c90557b
commit for new added test
soham-bentley Sep 18, 2024
f919765
commit 2
soham-bentley Sep 20, 2024
31847a4
update
soham-bentley Sep 24, 2024
6ba6b4c
Fixed all the issues related to filtering of data in Virtual Table
soham-bentley Sep 25, 2024
c96e44b
Binder Type enhancement
soham-bentley Sep 25, 2024
7fab42d
trying to fix BestIndex
soham-bentley Sep 27, 2024
898b779
Fixed the single column issue in VT
soham-bentley Sep 30, 2024
9cd676e
Performance Tests Added
soham-bentley Sep 30, 2024
0ead317
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Sep 30, 2024
a1e8080
ValueExp_Issue_Id_Change due to conflicts while merging with main
soham-bentley Sep 30, 2024
83ef505
Added flag for binder info to check whether the binder is for a param…
soham-bentley Oct 3, 2024
66ea5c3
Tests Added
soham-bentley Oct 3, 2024
0bc2fb1
Crash for following expression stopped by providing null checks
soham-bentley Oct 3, 2024
cea7858
Merge branch 'main' into Soham/Virtual_Table
khanaffan Oct 3, 2024
c9da214
Kepping concurrentQueryImpl as close to as it was with minimal changes
soham-bentley Oct 4, 2024
386b11e
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 4, 2024
da37f1e
Merge remote-tracking branch 'origin/Soham/Virtual_Table' into Soham/…
soham-bentley Oct 4, 2024
cfc8683
schema name changed to ECVLib and also file name changed
soham-bentley Oct 4, 2024
a7c2c6b
cleanup
soham-bentley Oct 4, 2024
b73ccf6
more cleanup
soham-bentley Oct 4, 2024
f484fe9
Performanvce Tests Updated
soham-bentley Oct 4, 2024
855013c
some comments resolved
soham-bentley Oct 4, 2024
c676b3a
Comments regarding constant name of IdSet table resolved
soham-bentley Oct 4, 2024
a04462c
binderInfo refactoring
soham-bentley Oct 5, 2024
59b1662
added flag to call _onbeforefirststep() once in PragmaECSQLStatement …
soham-bentley Oct 5, 2024
69d337c
changes as per suggestions by Affan
soham-bentley Oct 5, 2024
cc7dd6c
Performance test updated
soham-bentley Oct 7, 2024
7e7c044
Tests updated to prevent failure in pipeline
soham-bentley Oct 7, 2024
5c159b4
tests updated
soham-bentley Oct 7, 2024
70d7121
update in logic in IModelJsNative.cpp and concurrentquery
soham-bentley Oct 7, 2024
9d4d08d
performance tests indentation updated
soham-bentley Oct 7, 2024
3cc80e6
final update
soham-bentley Oct 8, 2024
73c07d4
OnBeforeFirstStep() logic updated by using m_isFirstStep flag
soham-bentley Oct 8, 2024
bc46d55
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 8, 2024
05c4108
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 14, 2024
f43afa7
Commit for schema names optional in table valued functions
soham-bentley Oct 14, 2024
4b33a80
More Tests added
soham-bentley Oct 17, 2024
8ae15d0
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 17, 2024
2df5e37
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 18, 2024
0b95c05
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 18, 2024
e2e99b6
Merge remote-tracking branch 'origin/Soham/Virtual_Table' into Soham/…
soham-bentley Oct 18, 2024
593f42c
issue reporter update
soham-bentley Oct 18, 2024
4891f05
Added flag checking to m_isFirstStep flag so that when actually flag …
soham-bentley Oct 21, 2024
9d348fa
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 21, 2024
2b1796e
Merge remote-tracking branch 'origin/Soham/Virtual_Table' into Soham/…
soham-bentley Oct 21, 2024
196f91e
logic update
soham-bentley Oct 21, 2024
d471856
update
soham-bentley Oct 21, 2024
0e26b7c
update
soham-bentley Oct 21, 2024
b461c51
commiting update
soham-bentley Oct 21, 2024
b6a31e4
comment added
soham-bentley Oct 21, 2024
218cce0
comment added
soham-bentley Oct 21, 2024
48047cc
Tests added and updated
soham-bentley Oct 21, 2024
0755553
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 24, 2024
8d1a2cc
removing m_isFirstStep and identifying first step using statement state
soham-bentley Oct 24, 2024
d3d17ae
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Oct 25, 2024
3c1ab06
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Jan 6, 2025
7a06777
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Jan 15, 2025
cde738e
Comment updated
soham-bentley Jan 16, 2025
4eb8b7a
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Jan 16, 2025
a7aa217
Fixed the issue with the query SELECT e.i FROM aps.TestElement e INNE…
soham-bentley Jan 17, 2025
e09dd7c
More tests added
soham-bentley Jan 20, 2025
9d37a1f
More Performance Tests added
soham-bentley Jan 20, 2025
df39db1
indentation issue solved
soham-bentley Jan 22, 2025
dc82b4a
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Jan 22, 2025
7863982
Update in logic to get statement state
soham-bentley Jan 22, 2025
00060aa
Changelog updated
soham-bentley Jan 22, 2025
ebf1713
comments updated
soham-bentley Jan 23, 2025
302d7f7
Merge remote-tracking branch 'origin/main' into Soham/Virtual_Table
soham-bentley Jan 23, 2025
0607b86
Merge remote-tracking branch 'origin/Soham/Virtual_Table' into Soham/…
soham-bentley Jan 24, 2025
d1e88f5
Merge remote-tracking branch 'origin/main' into Soham/VirtualTable_part2
soham-bentley Jan 29, 2025
ba90e6c
Updates in code
soham-bentley Jan 29, 2025
6561af6
Tests added
soham-bentley Jan 29, 2025
bdc3333
ECSql version updated
soham-bentley Jan 29, 2025
2d16983
Merge remote-tracking branch 'origin/main' into Soham/VirtualTable_part2
soham-bentley Jan 29, 2025
ee31e14
Colin's comment resolved and appropriate tests added
soham-bentley Jan 30, 2025
de2658e
Merge remote-tracking branch 'origin/main' into Soham/VirtualTable_part2
soham-bentley Jan 30, 2025
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
10 changes: 9 additions & 1 deletion iModelCore/ECDb/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ This document including important changes to syntax or file format.
| Module | Version |
| ------- | --------- |
| Profile | `4.0.0.5` |
| ECSQL | `2.0.1.1` |
| ECSQL | `2.0.2.0` |

## ## `01/29/2025`: Made schema names optional for table valued functions
* ECSql version change `2.0.1.1` -> `2.0.2.0`.
* Made schema names optional for table valued functions
* Table valued functions will now work with and without schema names. Example :- `SELECT * FROM json_each(:json_param)` &
`SELECT * FROM json1.json_each(:json_param)` both are now valid queries from ECSQL perspective.
* Example: `Select test.str_prop, test.int_prop, v.id from ts.A test RIGHT OUTER JOIN IdSet(:idSet_param) v on test.ECInstanceId = v.id`,
`SELECT * FROM json_each(:json_param)`.

## ## `01/22/2025`: Added IdSet Virtual Table in ECSQL
* ECSql version change `2.0.1.0` -> `2.0.1.1`.
Expand Down
26 changes: 20 additions & 6 deletions iModelCore/ECDb/ECDb/ECSql/ClassRefExp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,31 @@ Exp::FinalizeParseStatus TableValuedFunctionExp::_FinalizeParsing(ECSqlParseCont
if (FinalizeParseMode::BeforeFinalizingChildren == mode) {
const auto& vsm = ctx.GetECDb().Schemas().Main().GetVirtualSchemaManager();
const auto classValuedFunc = GetFunctionExp()->GetFunctionName();
const auto tableViewClassP = vsm.GetClass(m_schemaName, classValuedFunc);
size_t numberOfClasses = 0; // The numberOfClasses variable gives us the exact number of classes found which is used for more personalized error message
const auto tableViewClassP = m_schemaName.EqualsI("") ? vsm.FindClass(classValuedFunc, numberOfClasses) : vsm.GetClass(m_schemaName, classValuedFunc);
if (tableViewClassP == nullptr) {
ctx.Issues().ReportV(
if(numberOfClasses == 0)
{
ctx.Issues().ReportV(
IssueSeverity::Error,
IssueCategory::BusinessProperties,
IssueType::ECDbIssue,
ECDbIssueId::ECDb_0451,
"TableValuedFunction %s.%s() has no ECClass describing its output.",
m_schemaName.c_str(),
classValuedFunc.c_str()
);
"TableValuedFunction %s() has no ECClass describing its output.",
m_schemaName.EqualsIAscii("") ? classValuedFunc.c_str() : m_schemaName.append(".").append(classValuedFunc).c_str()
);
}
else if(numberOfClasses > 1)
{
ctx.Issues().ReportV(
IssueSeverity::Error,
IssueCategory::BusinessProperties,
IssueType::ECDbIssue,
ECDbIssueId::ECDb_0738,
"TableValuedFunction %s() has more than one ECClass describing its output. Unable to understand ambiguous reference",
m_schemaName.EqualsIAscii("") ? classValuedFunc.c_str() : m_schemaName.append(".").append(classValuedFunc).c_str()
);
}
return Exp::FinalizeParseStatus::Error;
}
m_virtualEntityClass = tableViewClassP->GetEntityClassCP();
Expand Down
36 changes: 30 additions & 6 deletions iModelCore/ECDb/ECDb/ECSql/ECSqlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ BentleyStatus ECSqlParser::ParseTableRef(std::unique_ptr<ClassRefExp>& exp, OSQL
if (SUCCESS == ParseCommonTableBlockName(cteBlockNameExp, *thirdNode)) {
rangeClassRef = std::move(cteBlockNameExp);
}
if (SUCCESS == ParseTableValuedFunction(tableValueFunc, *thirdNode)) {
else if (SUCCESS == ParseTableValuedFunction(tableValueFunc, *thirdNode)) {
rangeClassRef = std::move(tableValueFunc);
}
}
Expand Down Expand Up @@ -2075,10 +2075,10 @@ BentleyStatus ECSqlParser::ParseTableValuedFunction(std::unique_ptr<TableValuedF
}

const size_t pathLength = pathNode->count();
if (pathLength != 2) {
if (pathLength != 1 && pathLength != 2)
return ERROR;
}

if(pathLength == 2){
auto schemaNode = pathNode->getChild(0);
auto functionNode = pathNode->getChild(1);

Expand All @@ -2098,6 +2098,27 @@ BentleyStatus ECSqlParser::ParseTableValuedFunction(std::unique_ptr<TableValuedF
}

exp = std::make_unique<TableValuedFunctionExp>(schemaName.c_str(), std::move(memberFuncCall), PolymorphicInfo::NotSpecified());
}
else if(pathLength == 1)
{
auto functionNode = pathNode->getChild(0);

if(functionNode == nullptr) return ERROR;

if (functionNode->getChild(1) == nullptr || functionNode->getChild(1)->isLeaf()) { // We also need to check the leaf condition here because functionNode->getChild(1) is the argument node and that node should have children
return ERROR;
}

std::unique_ptr<MemberFunctionCallExp> memberFuncCall;
if (functionNode != nullptr)
{
if (SUCCESS != ParseMemberFunctionCall(memberFuncCall, *functionNode, true))
return ERROR;
}

exp = std::make_unique<TableValuedFunctionExp>("", std::move(memberFuncCall), PolymorphicInfo::NotSpecified());
}

return SUCCESS;
}

Expand Down Expand Up @@ -2244,16 +2265,19 @@ BentleyStatus ECSqlParser::ParseMemberFunctionCall(std::unique_ptr<MemberFunctio
return ERROR;
}

BeAssert(parseNode.count() == 2);
if(parseNode.count() != 2)
return ERROR;
OSQLParseNode const* argsNode = parseNode.getChild(1);
BeAssert(argsNode != nullptr);
if(argsNode == nullptr)
return ERROR;
if (argsNode->isLeaf())
{
BeAssert(false && "ParseNode passed to ParseMemberFunctionCall is expected to have a non-empty second child node");
return ERROR;
}

BeAssert(argsNode->count() == 3);
if(argsNode->count() != 3)
return ERROR;

Utf8StringCR functionName = parseNode.getChild(0)->getTokenValue();
memberFunCallExp = std::make_unique<MemberFunctionCallExp>(functionName, tableValuedFunc);
Expand Down
1 change: 1 addition & 0 deletions iModelCore/ECDb/ECDb/IssueReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ IssueId ECDbIssueId::ECDb_0734 = IssueId("ECDb_0734");
IssueId ECDbIssueId::ECDb_0735 = IssueId("ECDb_0735");
IssueId ECDbIssueId::ECDb_0736 = IssueId("ECDb_0736");
IssueId ECDbIssueId::ECDb_0737 = IssueId("ECDb_0737");
IssueId ECDbIssueId::ECDb_0738 = IssueId("ECDb_0738");

//---------------------------------------------------------------------------------------
// @bsimethod
Expand Down
1 change: 1 addition & 0 deletions iModelCore/ECDb/ECDb/IssueReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ struct ECDB_EXPORT ECDbIssueId
static ECN::IssueId ECDb_0735;
static ECN::IssueId ECDb_0736;
static ECN::IssueId ECDb_0737;
static ECN::IssueId ECDb_0738;
};

//---------------------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions iModelCore/ECDb/ECDb/SchemaManagerDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ ECClassCP VirtualSchemaManager::GetClass(Utf8StringCR schemaName, Utf8StringCR c
return schema->GetClassCP(className.c_str());
}

/*---------------------------------------------------------------------------------------
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
ECClassCP VirtualSchemaManager::FindClass(Utf8StringCR className, size_t& numberOfClasses) const{
BeMutexHolder lock(m_ecdb.GetImpl().GetMutex());
std::vector<ECClassCP> v;
for(auto it = m_schemas.begin(); it != m_schemas.end(); ++it)
{
ECClassCP tempClass = GetClass(it->first, className);
if(tempClass != nullptr)
v.push_back(tempClass);
}
numberOfClasses = v.size();
if(v.size() == 0)
return nullptr;
else if(v.size() == 1)
return v[0];
else
return nullptr;
}

/*---------------------------------------------------------------------------------------
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
Expand Down
2 changes: 2 additions & 0 deletions iModelCore/ECDb/ECDb/SchemaManagerDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct VirtualSchemaManager : ECN::IECSchemaLocater {
bool IsValidVirtualSchema(ECN::ECSchemaR schema, Utf8StringR err) const;
ECN::ECSchemaCP GetSchema(Utf8StringCR schemaName) const;
ECN::ECClassCP GetClass(Utf8StringCR schemaName, Utf8StringCR className) const;
// The numberOfClasses parameter gives us the exact number of classes found which can be used for more personalized error message
ECN::ECClassCP FindClass(Utf8StringCR className, size_t& numberOfClasses) const;
BentleyStatus Add(Utf8StringCR schemaXml) const;
};
//=======================================================================================
Expand Down
2 changes: 1 addition & 1 deletion iModelCore/ECDb/PublicAPI/ECDb/ECDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ struct EXPORT_VTABLE_ATTRIBUTE ECDb : Db
// e.g. Remove a sql function or change required argument or format of its return value.
// Sub1: Backward compatible change to 'Syntax'. For example adding new syntax/functions but not breaking any existing.
// Sub2: Backward compatible change to 'Runtime'. For example adding a new sql function.
static BeVersion GetECSqlVersion() { return BeVersion(2, 0, 1, 1); }
static BeVersion GetECSqlVersion() { return BeVersion(2, 0, 2, 0); }

//! Gets the current version of the ECDb profile
static ProfileVersion CurrentECDbProfileVersion() { return ProfileVersion(4, 0, 0, 5); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ TEST_F(ConcurrentQueryFixture, ReaderBindingForIdSetVirtualTable) {
idSet.insert(BeInt64Id(40));
int vsRowCount = 0;

ECSqlReader vsReaderIdSet(mgr, "select id from ECVLib.IdSet(?)",
ECSqlReader vsReaderIdSet(mgr, "select id from IdSet(?)",
ECSqlParams().BindIdSet(1, idSet));

int i = 1;
Expand All @@ -1184,7 +1184,7 @@ TEST_F(ConcurrentQueryFixture, ReaderBindingForIdSetVirtualTable) {
idSet.insert(BeInt64Id(40));
int vsRowCount = 0;

ECSqlReader vsReaderIdSet(mgr, "select ECInstanceId from meta.ECClassDef, ECVLib.IdSet(?) where ECInstanceId = id",
ECSqlReader vsReaderIdSet(mgr, "select ECInstanceId from meta.ECClassDef, IdSet(?) where ECInstanceId = id",
ECSqlParams().BindIdSet(1, idSet));

int i = 1;
Expand All @@ -1200,7 +1200,7 @@ TEST_F(ConcurrentQueryFixture, ReaderBindingForIdSetVirtualTable) {
auto& mgr = ConcurrentQueryMgr::GetInstance(m_ecdb);
int vsRowCount = 0;

ECSqlReader vsReaderIdSet(mgr, "select ECInstanceId from meta.ECClassDef, ECVLib.IdSet(?) where ECInstanceId = id",
ECSqlReader vsReaderIdSet(mgr, "select ECInstanceId from meta.ECClassDef, IdSet(?) where ECInstanceId = id",
ECSqlParams().BindId(1, BeInt64Id(33)));

while(vsReaderIdSet.Next())
Expand All @@ -1220,7 +1220,7 @@ TEST_F(ConcurrentQueryFixture, ReaderBindingForIdSetVirtualTable) {
idSet.insert(BeInt64Id(40));
int vsRowCount = 0;

ECSqlReader vsReaderIdSet(mgr, "select id from ECVLib.IdSet(?)",
ECSqlReader vsReaderIdSet(mgr, "select id from IdSet(?)",
ECSqlParams().BindIdSet(1, idSet));

try{
Expand Down
Loading
Loading