Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
2e8a1d17
Commit
2e8a1d17
authored
5 years ago
by
Victor Kotlyar
Committed by
Michael Davis
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add getSchemaColumnNames to the catalogue schema
parent
8c44aad5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
catalogue/CatalogueSchema.cpp
+52
-0
52 additions, 0 deletions
catalogue/CatalogueSchema.cpp
catalogue/CatalogueSchema.hpp
+9
-0
9 additions, 0 deletions
catalogue/CatalogueSchema.hpp
catalogue/VerifySchemaCmd.cpp
+9
-0
9 additions, 0 deletions
catalogue/VerifySchemaCmd.cpp
with
70 additions
and
0 deletions
catalogue/CatalogueSchema.cpp
+
52
−
0
View file @
2e8a1d17
...
...
@@ -36,6 +36,58 @@ CatalogueSchema::CatalogueSchema(const std::string &sqlSchema,
const
std
::
string
&
sqlSchemaTrigger
)
:
sql
(
sqlSchema
),
sql_trigger
(
sqlSchemaTrigger
)
{
}
//------------------------------------------------------------------------------
// getSchemaColumns
//------------------------------------------------------------------------------
std
::
map
<
std
::
string
,
std
::
string
>
CatalogueSchema
::
getSchemaColumns
(
const
std
::
string
&
table
)
const
{
std
::
map
<
std
::
string
,
std
::
string
>
schemaColumnNames
;
std
::
string
::
size_type
searchPos
=
0
;
std
::
string
::
size_type
findResult
=
std
::
string
::
npos
;
const
std
::
string
columnTypes
=
"NUMERIC|"
"INTEGER|"
"CHAR|"
"VARCHAR|"
"VARCHAR2"
;
try
{
while
(
std
::
string
::
npos
!=
(
findResult
=
sql
.
find
(
';'
,
searchPos
)))
{
// Calculate the length of the current statement without the trailing ';'
const
std
::
string
::
size_type
stmtLen
=
findResult
-
searchPos
;
const
std
::
string
sqlStmt
=
utils
::
trimString
(
sql
.
substr
(
searchPos
,
stmtLen
));
searchPos
=
findResult
+
1
;
if
(
0
<
sqlStmt
.
size
())
{
// Ignore empty statements
const
std
::
string
createTableSQL
=
"CREATE TABLE "
+
table
+
"
\\
(([a-zA-Z0-9_,
\\
)
\\
(]+)
\\
)"
;
cta
::
utils
::
Regex
tableSqlRegex
(
createTableSQL
.
c_str
());
auto
tableSql
=
tableSqlRegex
.
exec
(
sqlStmt
);
if
(
2
==
tableSql
.
size
())
{
tableSql
[
1
]
+=
","
;
// hack for parsing
// we use the same logic here as for trailing ';'
std
::
string
::
size_type
searchPosComma
=
0
;
std
::
string
::
size_type
findResultComma
=
std
::
string
::
npos
;
while
(
std
::
string
::
npos
!=
(
findResultComma
=
tableSql
[
1
].
find
(
','
,
searchPosComma
)))
{
const
std
::
string
::
size_type
stmtLenComma
=
findResultComma
-
searchPosComma
;
const
std
::
string
sqlStmtComma
=
utils
::
trimString
(
tableSql
[
1
].
substr
(
searchPosComma
,
stmtLenComma
));
searchPosComma
=
findResultComma
+
1
;
if
(
0
<
sqlStmtComma
.
size
())
{
// Ignore empty statements
const
std
::
string
columnSQL
=
"([a-zA-Z_]+) +("
+
columnTypes
+
")"
;
cta
::
utils
::
Regex
columnSqlRegex
(
columnSQL
.
c_str
());
auto
columnSql
=
columnSqlRegex
.
exec
(
sqlStmtComma
);
if
(
3
==
columnSql
.
size
())
{
schemaColumnNames
.
insert
(
std
::
make_pair
(
columnSql
[
1
],
columnSql
[
2
]));
}
}
}
}
}
}
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
return
schemaColumnNames
;
}
//------------------------------------------------------------------------------
// getSchemaTableNames
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
catalogue/CatalogueSchema.hpp
+
9
−
0
View file @
2e8a1d17
...
...
@@ -65,6 +65,15 @@ struct CatalogueSchema {
*/
std
::
list
<
std
::
string
>
getSchemaTableNames
()
const
;
/**
* Returns the names of all the column and their type as a map for the given
* table in the catalogue schema.
*
* @param table The table name to get the columns.
* @return The map of types by name of all the columns for the given table in the catalogue schema.
*/
std
::
map
<
std
::
string
,
std
::
string
>
getSchemaColumns
(
const
std
::
string
&
table
)
const
;
/**
* Returns the names of all the indexes in the catalogue schema.
*
...
...
This diff is collapsed.
Click to expand it.
catalogue/VerifySchemaCmd.cpp
+
9
−
0
View file @
2e8a1d17
...
...
@@ -115,6 +115,15 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
const
auto
schemaTableNames
=
schema
->
getSchemaTableNames
();
const
auto
dbTableNames
=
conn
.
getTableNames
();
const
VerifyStatus
verifyTablesStatus
=
verifyTableNames
(
schemaTableNames
,
dbTableNames
);
for
(
const
auto
&
table
:
schemaTableNames
)
{
std
::
cerr
<<
table
<<
std
::
endl
;
const
auto
columns
=
schema
->
getSchemaColumns
(
table
);
for
(
const
auto
&
column
:
columns
)
{
std
::
cerr
<<
" "
<<
column
.
first
<<
" "
<<
column
.
second
<<
std
::
endl
;
}
}
std
::
cerr
<<
"Checking index names..."
<<
std
::
endl
;
const
auto
schemaIndexNames
=
schema
->
getSchemaIndexNames
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment