Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
blendb
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
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
pdts20
blendb
Commits
1ea0ca7d
Commit
1ea0ca7d
authored
7 years ago
by
Lucas Fernandes de Oliveira
Browse files
Options
Downloads
Patches
Plain Diff
Issue #50: Relax constraints over joins in adapter
Signed-off-by:
Lucas Fernandes de Oliveira
<
lfo14@inf.ufpr.br
>
parent
81b6b0eb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/adapter/postgres.ts
+40
-9
40 additions, 9 deletions
src/adapter/postgres.ts
with
40 additions
and
9 deletions
src/adapter/postgres.ts
+
40
−
9
View file @
1ea0ca7d
...
@@ -105,6 +105,16 @@ export class PostgresAdapter extends Adapter {
...
@@ -105,6 +105,16 @@ export class PostgresAdapter extends Adapter {
}
}
}
}
const
blackList
=
view
.
dimensions
.
map
((
i
)
=>
i
.
name
);
for
(
let
i
=
0
;
i
<
view
.
clauses
.
length
;
++
i
)
{
if
(
view
.
clauses
[
i
].
filters
.
length
===
1
)
{
let
filter
=
view
.
clauses
[
i
].
filters
[
0
];
if
(
filter
.
operator
===
FilterOperator
.
EQUAL
)
{
blackList
.
push
(
filter
.
target
.
name
);
}
}
}
/*
/*
If there is more than one source of data (tables/views)
If there is more than one source of data (tables/views)
a join is needed.
a join is needed.
...
@@ -244,8 +254,23 @@ export class PostgresAdapter extends Adapter {
...
@@ -244,8 +254,23 @@ export class PostgresAdapter extends Adapter {
array of strings.
array of strings.
*/
*/
const
sorted
=
partialJoin
.
sort
((
a
,
b
)
=>
{
const
sorted
=
partialJoin
.
sort
((
a
,
b
)
=>
{
return
this
.
compareKeys
(
a
.
keys
,
b
.
keys
);
return
this
.
compareKeys
(
a
.
keys
,
b
.
keys
,
blackList
);
});
});
/*
SUPER WARNING: WHEN THE BLACK LIST IS USED THE VIEW IS
UNMATERIALIZEBLE, BUT THE QUERY CAN AGGREGATE THE VALUES
The blackList is the array of dimensions of the query plus
the dimensions in filters using the equality operator.
In further coments is expained that the relation to make
a join must be one-to-one between the tables.
However and a dimension is choosed, a sub view is
created and if the relation is preserved in the sub view
the query can be agregated, but this view cannot be re-used
so it is unmaterializeble.
The equality operator is the same as select one subview.
*/
/*
/*
First of all, the remaining views are splited in segments.
First of all, the remaining views are splited in segments.
...
@@ -259,7 +284,7 @@ export class PostgresAdapter extends Adapter {
...
@@ -259,7 +284,7 @@ export class PostgresAdapter extends Adapter {
const
segment
=
[[
sorted
[
0
]]];
const
segment
=
[[
sorted
[
0
]]];
let
segmentId
=
0
;
let
segmentId
=
0
;
for
(
let
i
=
1
;
i
<
sorted
.
length
;
++
i
)
{
for
(
let
i
=
1
;
i
<
sorted
.
length
;
++
i
)
{
if
(
this
.
compareKeys
(
sorted
[
i
-
1
].
keys
,
sorted
[
i
].
keys
)
===
0
)
{
if
(
this
.
compareKeys
(
sorted
[
i
-
1
].
keys
,
sorted
[
i
].
keys
,
blackList
)
===
0
)
{
segment
[
segmentId
].
push
(
sorted
[
i
]);
segment
[
segmentId
].
push
(
sorted
[
i
]);
}
}
else
{
else
{
...
@@ -805,22 +830,28 @@ export class PostgresAdapter extends Adapter {
...
@@ -805,22 +830,28 @@ export class PostgresAdapter extends Adapter {
}
}
}
}
private
compareKeys
(
a
:
Dimension
[],
b
:
Dimension
[]):
number
{
private
compareKeys
(
a
:
Dimension
[],
b
:
Dimension
[],
blackList
:
string
[]):
number
{
/*
SUPER WARNING: WHEN THE BLACK LIST IS USED THE VIEW IS
UNMATERIALIZEBLE, BUT THE QUERY CAN AGGREGATE THE VALUES
*/
let
c
=
a
.
filter
((
i
)
=>
!
blackList
.
some
((
bad
)
=>
bad
===
i
.
name
));
let
d
=
b
.
filter
((
i
)
=>
!
blackList
.
some
((
bad
)
=>
bad
===
i
.
name
));
let
length
=
0
;
let
length
=
0
;
let
res
=
a
.
length
-
b
.
length
;
let
res
=
c
.
length
-
d
.
length
;
if
(
a
.
length
<
b
.
length
)
{
if
(
c
.
length
<
d
.
length
)
{
length
=
a
.
length
;
length
=
c
.
length
;
}
}
else
{
else
{
length
=
b
.
length
;
length
=
d
.
length
;
}
}
for
(
let
i
=
0
;
i
<
length
;
++
i
)
{
for
(
let
i
=
0
;
i
<
length
;
++
i
)
{
if
(
a
[
i
].
name
<
b
[
i
].
name
)
{
if
(
c
[
i
].
name
<
d
[
i
].
name
)
{
return
-
1
;
return
-
1
;
}
}
else
if
(
a
[
i
].
name
>
b
[
i
].
name
)
{
else
if
(
c
[
i
].
name
>
d
[
i
].
name
)
{
return
1
;
return
1
;
}
}
}
}
...
...
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