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

feat: Analytics database [DHIS2-16705] #16539

Closed
wants to merge 679 commits into from
Closed
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
679 commits
Select commit Hold shift + click to select a range
96c6f75
fix: Update code
larshelge Feb 29, 2024
96c1297
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Feb 29, 2024
ab39e4a
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Feb 29, 2024
47c3cfb
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Feb 29, 2024
a4318c6
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 1, 2024
ebe3f57
fix: Update code
larshelge Mar 1, 2024
69e9725
fix: Update code
larshelge Mar 1, 2024
9e928fe
fix: Update code
larshelge Mar 1, 2024
79111d3
fix: Update code
larshelge Mar 1, 2024
b69d5f5
fix: Update code
larshelge Mar 1, 2024
8300c2c
fix: Update code
larshelge Mar 1, 2024
3c09a28
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 4, 2024
95221b1
Merge branch 'DHIS2-16705-analytics-db-main' of github.com:dhis2/dhis…
larshelge Mar 4, 2024
08f4c99
fix: Update code
larshelge Mar 4, 2024
ce075c8
fix: Update code
larshelge Mar 4, 2024
34d8792
fix: Update code
larshelge Mar 4, 2024
3aeb455
fix: Update code
larshelge Mar 4, 2024
eeaf0e1
fix: Update code
larshelge Mar 4, 2024
ab026f6
fix: Update code
larshelge Mar 4, 2024
f8cc274
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 5, 2024
42e87df
fix: Update code
larshelge Mar 5, 2024
10eee74
fix: Update code
larshelge Mar 5, 2024
1586612
fix: Update code
larshelge Mar 5, 2024
b70074f
fix: Update code
larshelge Mar 5, 2024
2678feb
fix: Update code
larshelge Mar 5, 2024
7052869
fix: Update code
larshelge Mar 5, 2024
76585dd
fix: Update code
larshelge Mar 5, 2024
2b19c4d
fix: Update code
larshelge Mar 5, 2024
9e4ff72
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 18, 2024
a96dfff
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 18, 2024
47c8774
fix: Update code
larshelge Mar 22, 2024
c87feab
fix: Update code
larshelge Mar 22, 2024
35da405
fix: Update code
larshelge Mar 22, 2024
b88a24d
fix: Update code
larshelge Mar 22, 2024
1decdc9
fix: Update code
larshelge Mar 22, 2024
60fd53e
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 22, 2024
8b41945
fix: Update code
larshelge Mar 22, 2024
ac57d9e
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 24, 2024
82c1815
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 25, 2024
60d50d1
fix: Update code
larshelge Mar 25, 2024
172bf6d
fix: Update code
larshelge Mar 25, 2024
cdfab3c
fix: Update code
larshelge Mar 25, 2024
7edeb4b
fix: Update code
larshelge Mar 25, 2024
abd8cc6
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Mar 25, 2024
afc3c46
fix: Update code
larshelge Mar 25, 2024
094d60e
fix: Update code
larshelge Mar 25, 2024
3cc8b98
fix: Update code
larshelge Mar 25, 2024
c1ff1f2
fix: Update code
larshelge Mar 25, 2024
faf6f59
fix: Merge with master
larshelge Mar 25, 2024
c0e92f6
fix: Update code
larshelge Mar 25, 2024
8e71d3d
fix: Update code
larshelge Mar 25, 2024
ba1a2d3
fix: Update code
larshelge Mar 26, 2024
e87b4bb
fix: Update code
larshelge Mar 26, 2024
2567b2f
fix: Update code
larshelge Mar 26, 2024
43a044e
fix: Update code
larshelge Mar 26, 2024
aa9920a
fix: Update code
larshelge Mar 26, 2024
0a7314b
fix: Update code
larshelge Mar 26, 2024
d573343
fix: Update code
larshelge Mar 26, 2024
818b2b0
fix: Update code
larshelge Mar 26, 2024
0f72c6a
fix: Update code
larshelge Mar 26, 2024
d1575b6
fix: Update code
larshelge Mar 26, 2024
cd329f4
fix: Update code
larshelge Mar 26, 2024
7ba01c7
fix: Update code
larshelge Mar 26, 2024
38c037c
fix: Update code
larshelge Mar 26, 2024
0ce1164
fix: Update code
larshelge Mar 26, 2024
9e24f37
fix: Update code
larshelge Mar 26, 2024
efdfad9
fix: Update code
larshelge Mar 26, 2024
ccec021
fix: Update code
larshelge Mar 26, 2024
95265c1
fix: Update code
larshelge Mar 26, 2024
aa3429c
fix: Update code
larshelge Mar 26, 2024
208e685
fix: Update code
larshelge Mar 26, 2024
76ceaeb
fix: Update code
larshelge Mar 26, 2024
37ed27e
fix: Update code
larshelge Mar 26, 2024
2fb19df
fix: Update code
larshelge Mar 26, 2024
87390fa
fix: Update code
larshelge Mar 26, 2024
44146da
fix: Update code
larshelge Mar 26, 2024
8e9a926
fix: Update code
larshelge Mar 26, 2024
835b5b5
fix: Update code
larshelge Mar 26, 2024
58f9fbc
fix: Update code
larshelge Mar 27, 2024
8dead72
fix: Update code
larshelge Mar 27, 2024
ad5c75d
fix: Update code
larshelge Mar 27, 2024
99a0c9d
fix: Update code
larshelge Mar 27, 2024
43a33d9
fix: Update code
larshelge Mar 27, 2024
faa2bb3
fix: Update code
larshelge Mar 27, 2024
b497196
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 2, 2024
d73b772
fix: Update code
larshelge Apr 2, 2024
cde9bce
fix: Update code
larshelge Apr 2, 2024
f214733
fix: Merge
larshelge Apr 2, 2024
809884d
fix: Update code
larshelge Apr 2, 2024
1b7855a
fix: Update code
larshelge Apr 2, 2024
8247bba
fix: Update code
larshelge Apr 2, 2024
09db231
fix: Update code
larshelge Apr 2, 2024
dbdbbc6
fix: Update code
larshelge Apr 2, 2024
f47127d
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 2, 2024
82c6634
fix: Update code
larshelge Apr 2, 2024
5e4363c
fix: Update code
larshelge Apr 2, 2024
1a5726c
fix: Update code
larshelge Apr 2, 2024
62b944b
fix: Update code
larshelge Apr 2, 2024
06cb7d0
fix: Update code
larshelge Apr 2, 2024
ef5c3e8
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 2, 2024
dfb0fe5
fix: Update code
larshelge Apr 2, 2024
b6ccb5d
fix: Update code
larshelge Apr 2, 2024
b7b93c5
fix: Update code
larshelge Apr 2, 2024
9651110
fix: Update code
larshelge Apr 2, 2024
543de8e
fix: Update code
larshelge Apr 2, 2024
b8cfaf5
fix: Update code
larshelge Apr 2, 2024
a03f01b
fix: Update code
larshelge Apr 2, 2024
0f9e3c5
fix: Update code
larshelge Apr 2, 2024
4dcbcd2
fix: Update code
larshelge Apr 2, 2024
438cd0e
fix: Update code
larshelge Apr 2, 2024
fdd54dc
fix: Update code
larshelge Apr 2, 2024
376e214
fix: Update code
larshelge Apr 2, 2024
775667e
fix: Update code
larshelge Apr 2, 2024
e633ae1
fix: Update code
larshelge Apr 2, 2024
f128427
fix: Update code
larshelge Apr 2, 2024
fdb2c57
fix: Update code
larshelge Apr 2, 2024
294ca7a
fix: Update code
larshelge Apr 2, 2024
8fa8b66
fix: Update code
larshelge Apr 2, 2024
3f0afbb
fix: Update code
larshelge Apr 2, 2024
d57029f
fix: Update code
larshelge Apr 2, 2024
fad0273
fix: Update code
larshelge Apr 2, 2024
7f1fc7e
fix: Update code
larshelge Apr 2, 2024
366b99a
fix: Update code
larshelge Apr 2, 2024
3e64d0c
fix: Update code
larshelge Apr 2, 2024
3027251
fix: Update code
larshelge Apr 3, 2024
5ff88e5
fix: Update code
larshelge Apr 3, 2024
e6de35a
fix: Update code
larshelge Apr 3, 2024
2ce2214
chore: use replaceQualify for analytic queries
vietnguyen Apr 3, 2024
5226fd4
Merge remote-tracking branch 'origin/DHIS2-16705-analytics-db-main' i…
vietnguyen Apr 3, 2024
170fa53
Merge branch 'DHIS2-16705-analytics-db-main' of github.com:dhis2/dhis…
larshelge Apr 3, 2024
a023899
fix: Update code
larshelge Apr 3, 2024
3d78a25
fix: Update code
larshelge Apr 3, 2024
a3e5651
fix: Update code
larshelge Apr 3, 2024
a6a6832
fix: Update code
larshelge Apr 3, 2024
43050e7
fix: Update code
larshelge Apr 3, 2024
7d46f42
fix: Update code
larshelge Apr 3, 2024
eaef942
fix: Update code
larshelge Apr 3, 2024
3aeb365
fix: Update code
larshelge Apr 3, 2024
e605bb9
fix: Update code
larshelge Apr 3, 2024
b2b8287
fix: Update code
larshelge Apr 3, 2024
e9b7965
fix: Update code
larshelge Apr 4, 2024
a47a3f8
fix: Update code
larshelge Apr 4, 2024
1994353
fix: Update code
larshelge Apr 4, 2024
f2d9f94
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 4, 2024
d5daac0
fix unit tests
vietnguyen Apr 4, 2024
58d0227
Merge remote-tracking branch 'origin/DHIS2-16705-analytics-db-main' i…
vietnguyen Apr 4, 2024
6729d80
minor fix in JdbcCompletenessTableManager
vietnguyen Apr 4, 2024
c9a2146
fix: Update code
larshelge Apr 5, 2024
cc5a74e
fix: Update code
larshelge Apr 5, 2024
7010440
fix: Update code
larshelge Apr 5, 2024
230a11b
fix: Update code
larshelge Apr 5, 2024
a0ed8f9
fix: Update code
larshelge Apr 5, 2024
9adb89e
fix: Update code
larshelge Apr 5, 2024
f90384d
fix: Update code
larshelge Apr 5, 2024
bc269eb
fix: Update code
larshelge Apr 5, 2024
1df5a06
fix: Update code
larshelge Apr 6, 2024
12f4af1
fix: Update code
larshelge Apr 6, 2024
6baed66
fix: Update code
larshelge Apr 6, 2024
6f49137
fix: Update code
larshelge Apr 6, 2024
d5c2d87
fix: Update code
larshelge Apr 6, 2024
ce5234b
fix: Update code
larshelge Apr 6, 2024
ca7264f
fix: Update code
larshelge Apr 6, 2024
5e94c8f
fix: Update code
larshelge Apr 6, 2024
fb58053
fix: Update code
larshelge Apr 7, 2024
4394772
fix: Update code
larshelge Apr 7, 2024
0513dd8
fix: Update code
larshelge Apr 7, 2024
e7bafc5
fix: Update code
larshelge Apr 7, 2024
7be33f6
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 7, 2024
d5ed1e2
fix: Update code
larshelge Apr 7, 2024
433f717
fix: Update code
larshelge Apr 7, 2024
87c58a8
fix: Update code
larshelge Apr 7, 2024
4f430cc
fix: Update code
larshelge Apr 7, 2024
27dea60
fix: Update code
larshelge Apr 7, 2024
9c319be
fix: Update code
larshelge Apr 7, 2024
9962be2
fix: Update code
larshelge Apr 7, 2024
9e7bc0c
fix: Update code
larshelge Apr 7, 2024
b0dc410
fix: Update code
larshelge Apr 7, 2024
108de45
fix: Update code
larshelge Apr 7, 2024
50133fa
fix: Update code
larshelge Apr 7, 2024
9c93f1e
fix: Update code
larshelge Apr 7, 2024
d62a9ee
fix: Update code
larshelge Apr 7, 2024
d32129e
fix: Update code
larshelge Apr 7, 2024
c87af3b
fix: Update code
larshelge Apr 7, 2024
d76c5b8
fix: Update code
larshelge Apr 7, 2024
e44fbcd
fix: Update code
larshelge Apr 7, 2024
efcf818
fix: Update code
larshelge Apr 7, 2024
655373c
fix: Update code
larshelge Apr 7, 2024
e332274
fix: Update code
larshelge Apr 7, 2024
4f68da3
fix: Update code
larshelge Apr 7, 2024
f06fb38
fix: Update code
larshelge Apr 7, 2024
0969c9d
fix: Update code
larshelge Apr 7, 2024
33558ec
fix: Update code
larshelge Apr 8, 2024
b3974c6
fix: Update code
larshelge Apr 8, 2024
d0157a1
fix: Update code
larshelge Apr 8, 2024
4518a91
fix: Update code
larshelge Apr 8, 2024
5667824
fix: Update code
larshelge Apr 8, 2024
08a3681
fix: Update code
larshelge Apr 8, 2024
9c253d2
fix: Update code
larshelge Apr 8, 2024
b8217f9
fix: Update code
larshelge Apr 8, 2024
caf9c2f
fix: Update code
larshelge Apr 8, 2024
e20232b
fix: Update code
larshelge Apr 8, 2024
5aa86bd
fix: Update code
larshelge Apr 8, 2024
32a94bb
fix: Update code
larshelge Apr 8, 2024
1c15f23
fix: Update code
larshelge Apr 8, 2024
7b959ea
fix: Update code
larshelge Apr 8, 2024
24cd4f9
fix: Update code
larshelge Apr 8, 2024
1792d31
fix: Update code
larshelge Apr 8, 2024
76109af
fix: Update code
larshelge Apr 9, 2024
85e15c1
fix: Update code
larshelge Apr 9, 2024
e325de5
fix: Update code
larshelge Apr 9, 2024
35fc482
fix: Update code
larshelge Apr 9, 2024
6e72054
fix: Update code
larshelge Apr 9, 2024
61ec0b4
fix: Update code
larshelge Apr 9, 2024
d49d69f
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 9, 2024
8a54e02
fix: Update code
larshelge Apr 9, 2024
a782e6a
fix: Update code
larshelge Apr 9, 2024
7689001
fix: Update code
larshelge Apr 9, 2024
5eb4970
fix: Update code
larshelge Apr 9, 2024
0a147df
fix: Update code
larshelge Apr 9, 2024
dedb73c
fix: Update code
larshelge Apr 9, 2024
69eb024
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 15, 2024
d42688b
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 22, 2024
61111b2
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 22, 2024
738f35d
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Apr 26, 2024
399fea5
fix: Update code
larshelge Apr 29, 2024
ca70705
fix: Update code
larshelge Apr 29, 2024
d334a0d
fix: Update code
larshelge Jun 1, 2024
f7c62ad
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Jun 5, 2024
1526d2e
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Jun 8, 2024
1634eed
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Jun 16, 2024
027fd89
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Jun 16, 2024
3ef2519
fix: Update code
larshelge Jun 16, 2024
107379e
fix: Update code
larshelge Jun 16, 2024
b882430
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Jun 16, 2024
21214bd
fix: Update code
larshelge Jun 17, 2024
76678ab
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Jul 2, 2024
1bfdd42
fix: Update code
larshelge Oct 30, 2024
ebb073b
fix: Update code
larshelge Oct 30, 2024
c172abb
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Oct 31, 2024
a3dd791
fix: Update code
larshelge Oct 31, 2024
5c06a8a
fix: Update code
larshelge Oct 31, 2024
32fa66a
fix: Update code
larshelge Oct 31, 2024
98c02d3
fix: Update code
larshelge Oct 31, 2024
95583c8
fix: Update code
larshelge Oct 31, 2024
c6523d8
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Oct 31, 2024
ad31fe6
fix: Update code
larshelge Oct 31, 2024
4beae2b
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Oct 31, 2024
c7c4d5b
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Oct 31, 2024
fb506f3
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Oct 31, 2024
73413c1
Merge branch 'master' into DHIS2-16705-analytics-db-main
larshelge Nov 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.Date;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import org.hisp.dhis.analytics.AnalyticsTableType;
import org.hisp.dhis.commons.collection.UniqueArrayList;
Expand All @@ -38,7 +39,6 @@
import org.hisp.dhis.db.model.TablePartition;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.springframework.util.Assert;

/**
* Class representing an analytics database table. Note that the table name initially represents a
Expand Down Expand Up @@ -219,15 +219,15 @@ public List<AnalyticsTableColumn> getFactColumns() {
*/
public AnalyticsTable addTablePartition(
List<String> checks, Integer year, Date startDate, Date endDate) {
Assert.notNull(year, "Year must be specified");
Objects.requireNonNull(year);

AnalyticsTablePartition partition =
new AnalyticsTablePartition(this, checks, year, startDate, endDate);

this.tablePartitions.add(partition);

super.addPartition(toTablePartition(partition));

this.tablePartitions.add(partition);

return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
/*
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.db.sql;

import static org.hisp.dhis.commons.util.TextUtils.removeLastComma;

import org.apache.commons.lang3.Validate;
import org.hisp.dhis.db.model.Column;
import org.hisp.dhis.db.model.Index;
import org.hisp.dhis.db.model.Table;
import org.hisp.dhis.db.model.TablePartition;
import org.hisp.dhis.db.model.constraint.Nullable;

public class DorisSqlBuilder extends AbstractSqlBuilder {

// Constants

private static final String QUOTE = "`";

// Data types

@Override
public String dataTypeSmallInt() {
return "smallint";
}

@Override
public String dataTypeInteger() {
return "int";
}

@Override
public String dataTypeBigInt() {
return "bigint";
}

@Override
public String dataTypeDecimal() {
return "decimal(18,6)";
}

@Override
public String dataTypeFloat() {
return "float";
}

@Override
public String dataTypeDouble() {
return "double";
}

@Override
public String dataTypeBoolean() {
return "boolean";
}

@Override
public String dataTypeCharacter(int length) {
return String.format("char(%d)", length);
}

@Override
public String dataTypeVarchar(int length) {
return String.format("varchar(%d)", length);
}

@Override
public String dataTypeText() {
return "string";
}

@Override
public String dataTypeDate() {
return "date";
}

@Override
public String dataTypeTimestamp() {
return "datetime";
}

@Override
public String dataTypeTimestampTz() {
return "datetime";
}

@Override
public String dataTypeGeometry() {
return "string";
}

@Override
public String dataTypeGeometryPoint() {
return "string";
}

@Override
public String dataTypeJson() {
return "json";
}

// Index types

@Override
public String indexTypeBtree() {
return notSupported();
}

@Override
public String indexTypeGist() {
return notSupported();
}

@Override
public String indexTypeGin() {
return notSupported();
}

// Index functions

@Override
public String indexFunctionUpper() {
return "upper";
}

@Override
public String indexFunctionLower() {
return "lower";
}

// Capabilities

@Override
public boolean supportsGeospatialData() {
return false;
}

@Override
public boolean supportsDeclarativePartitioning() {
return true;
}

@Override
public boolean supportsAnalyze() {
return false;
}

@Override
public boolean supportsVacuum() {
return false;
}

@Override
public boolean requiresIndexesForAnalytics() {
return false;
}

// Utilities

@Override
public String quote(String relation) {
String escapedRelation = relation.replace(QUOTE, (QUOTE + QUOTE));
return QUOTE + escapedRelation + QUOTE;
}

@Override
public String quote(String alias, String relation) {
return alias + DOT + quote(relation);
}

@Override
public String singleQuote(String value) {
return SINGLE_QUOTE + escape(value) + SINGLE_QUOTE;
}

@Override
public String escape(String value) {
return value
.replace(SINGLE_QUOTE, (SINGLE_QUOTE + SINGLE_QUOTE))
.replace(BACKSLASH, (BACKSLASH + BACKSLASH));
}

// Statements
@Override
public String createTable(Table table) {
Validate.isTrue(table.hasPrimaryKey());

StringBuilder sql =
new StringBuilder("create table ").append(quote(table.getName())).append(" ");

// Columns

if (table.hasColumns()) {
sql.append("(");

for (Column column : table.getColumns()) {
String dataType = getDataTypeName(column.getDataType());
String nullable = column.getNullable() == Nullable.NOT_NULL ? " not null" : " null";

sql.append(quote(column.getName()) + " ").append(dataType).append(nullable).append(", ");
}

removeLastComma(sql).append(") engine=olap ");
}

// Primary key

if (table.hasPrimaryKey()) {
sql.append("duplicate key (");

for (String columnName : table.getPrimaryKey()) {
sql.append(quote(columnName) + ", ");
}

removeLastComma(sql).append(") ");
}

// Partitions

if (table.hasPartitions()) {
sql.append("partition by range(year) (");

for (TablePartition partition : table.getPartitions()) {
sql.append("partition ")
.append(quote(partition.getName()))
.append(" values less than(\"")
.append(partition.getValue())
.append("\"),");
}

removeLastComma(sql).append(") ");
}

// Distribution

if (table.hasPrimaryKey()) {
sql.append("distributed by hash(")
.append(quote(table.getFirstPrimaryKey()))
.append(") ")
.append("buckets = 10 "); // Verify this
}

// Properties

sql.append("properties (\"replication_num\" = \"1\")");

return sql.append(";").toString();
}

@Override
public String analyzeTable(String name) {
return notSupported();
}

@Override
public String vacuumTable(Table table) {
return notSupported();
}

@Override
public String renameTable(Table table, String newName) {
return String.format("alter table %s rename to %s;", quote(table.getName()), quote(newName));
}

@Override
public String dropTableIfExists(String name) {
return String.format("drop table if exists %s;", quote(name));
}

@Override
public String dropTableIfExistsCascade(Table table) {
return dropTableIfExists(table);
}

@Override
public String dropTableIfExistsCascade(String name) {
return dropTableIfExists(name);
}

@Override
public String setParentTable(Table table, String parentName) {
return notSupported();
}

@Override
public String removeParentTable(Table table, String parentName) {
return notSupported();
}

@Override
public String tableExists(String name) {
return String.format(
"select t.table_name from information_schema.tables t "
+ "where t.table_schema = 'public' and t.table_name = %s;",
singleQuote(name));
}

/**
* Doris supports indexes but relies on concurrency and compression for query performance instead
* of indexes on arbitrary columns. Read more at {@link https://t.ly/uNK5T}.
*/
@Override
public String createIndex(Index index) {
return notSupported();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private SqlBuilder getSqlBuilder(AnalyticsTableSettings config) {
Database database = config.getAnalyticsDatabase();
Objects.requireNonNull(database);
switch (database) {
case DORIS:
return new DorisSqlBuilder();
default:
return new PostgreSqlBuilder();
}
Expand Down
Loading
Loading