From 88df0949c0785739b1ebbc9db0894ed05fb72362 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 10:54:23 +0300 Subject: [PATCH 01/20] merge squash pattern-acceleration-refactor --- database/bloomdb.sql | 45 +-- pom.xml | 8 +- .../pth_06/config/ConditionConfig.java | 16 +- .../pth_06/jooq/generated/DefaultCatalog.java | 6 +- .../jooq/generated/bloomdb/Bloomdb.java | 30 +- .../jooq/generated/bloomdb/Indexes.java | 26 +- .../pth_06/jooq/generated/bloomdb/Keys.java | 50 +--- .../pth_06/jooq/generated/bloomdb/Tables.java | 24 +- .../tables/FilterExpected_1000000Fpp_003.java | 223 -------------- .../tables/FilterExpected_100000Fpp_001.java | 223 -------------- .../tables/FilterExpected_2500000Fpp_005.java | 223 -------------- .../generated/bloomdb/tables/Filtertype.java | 218 ++++++++++++++ .../FilterExpected_1000000Fpp_003Record.java | 236 --------------- .../FilterExpected_2500000Fpp_005Record.java | 236 --------------- ...p_001Record.java => FiltertypeRecord.java} | 147 +++++---- .../jooq/generated/journaldb/Indexes.java | 6 +- .../jooq/generated/journaldb/Journaldb.java | 6 +- .../pth_06/jooq/generated/journaldb/Keys.java | 6 +- .../jooq/generated/journaldb/Tables.java | 6 +- .../generated/journaldb/tables/Bucket.java | 6 +- .../jooq/generated/journaldb/tables/Host.java | 6 +- .../generated/journaldb/tables/Logfile.java | 6 +- .../tables/records/BucketRecord.java | 6 +- .../journaldb/tables/records/HostRecord.java | 6 +- .../tables/records/LogfileRecord.java | 6 +- .../jooq/generated/streamdb/Indexes.java | 6 +- .../pth_06/jooq/generated/streamdb/Keys.java | 6 +- .../jooq/generated/streamdb/Streamdb.java | 6 +- .../jooq/generated/streamdb/Tables.java | 6 +- .../jooq/generated/streamdb/tables/Host.java | 6 +- .../generated/streamdb/tables/LogGroup.java | 6 +- .../generated/streamdb/tables/Stream.java | 6 +- .../streamdb/tables/records/HostRecord.java | 6 +- .../tables/records/LogGroupRecord.java | 6 +- .../streamdb/tables/records/StreamRecord.java | 6 +- .../pth_06/planner/BloomFilterTempTable.java | 236 +++++++++++++++ .../teragrep/pth_06/planner/PatternMatch.java | 137 +++++++++ .../pth_06/planner/StreamDBClient.java | 105 +------ .../planner/walker/ConditionWalker.java | 36 ++- .../walker/conditions/ElementCondition.java | 66 +++-- .../conditions/IndexStatementCondition.java | 126 ++++---- .../walker/conditions/ValidElement.java | 103 +++++++ .../planner/BloomFilterTempTableTest.java | 280 ++++++++++++++++++ .../pth_06/planner/PatternMatchTest.java | 221 ++++++++++++++ .../conditions/ElementConditionTest.java | 17 +- .../IndexStatementConditionTest.java | 176 +++++++++-- .../conditions/LatestConditionTest.java | 15 +- .../conditions/SourceTypeConditionTest.java | 14 +- .../walker/conditions/ValidElementTest.java | 127 ++++++++ .../pth_06/walker/ConditionWalkerTest.java | 274 +++++++++++++++++ 50 files changed, 2115 insertions(+), 1649 deletions(-) delete mode 100644 src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_1000000Fpp_003.java delete mode 100644 src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_100000Fpp_001.java delete mode 100644 src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_2500000Fpp_005.java create mode 100644 src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java delete mode 100644 src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_1000000Fpp_003Record.java delete mode 100644 src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_2500000Fpp_005Record.java rename src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/{FilterExpected_100000Fpp_001Record.java => FiltertypeRecord.java} (53%) create mode 100644 src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/PatternMatch.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java create mode 100644 src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java diff --git a/database/bloomdb.sql b/database/bloomdb.sql index 4157d59b..f6dac295 100644 --- a/database/bloomdb.sql +++ b/database/bloomdb.sql @@ -1,6 +1,6 @@ /* * This program handles user requests that require archive access. - * Copyright (C) 2022 Suomen Kanuuna Oy + * Copyright (C) 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -44,36 +44,15 @@ * a licensee so wish it. */ -DROP TABLE IF EXISTS `filter_expected_100000_fpp_001`; -DROP TABLE IF EXISTS `filter_expected_1000000_fpp_003`; -DROP TABLE IF EXISTS `filter_expected_2500000_fpp_005`; +DROP TABLE IF EXISTS `filtertype`; -CREATE TABLE `filter_expected_100000_fpp_001` ( - `id` INT NOT NULL AUTO_INCREMENT, - `partition_id` BIGINT(20) unsigned NOT NULL UNIQUE, - `filter` LONGBLOB, - CONSTRAINT `fk_smallfilter_partition` - FOREIGN KEY (`partition_id`) REFERENCES `journaldb`.`logfile`(`id`) ON DELETE CASCADE, - CONSTRAINT `pk_small` - PRIMARY KEY (`id`) -)ENGINE=InnoDB ROW_FORMAT=COMPRESSED; - -CREATE TABLE `filter_expected_1000000_fpp_003` ( - `id` INT NOT NULL AUTO_INCREMENT, - `partition_id` BIGINT(20) unsigned NOT NULL UNIQUE , - `filter` LONGBLOB, - CONSTRAINT `fk_mediumfilter_partition` - FOREIGN KEY (`partition_id`) REFERENCES `journaldb`.`logfile`(`id`) ON DELETE CASCADE, - CONSTRAINT `pk_medium` - PRIMARY KEY (`id`) -)ENGINE=InnoDB ROW_FORMAT=COMPRESSED; - -CREATE TABLE `filter_expected_2500000_fpp_005` ( - `id` INT NOT NULL AUTO_INCREMENT, - `partition_id` BIGINT(20) unsigned NOT NULL UNIQUE , - `filter` LONGBLOB, - CONSTRAINT `fk_largefilter_partition` - FOREIGN KEY (`partition_id`) REFERENCES `journaldb`.`logfile`(`id`) ON DELETE CASCADE, - CONSTRAINT `pk_large` - PRIMARY KEY (`id`) -)ENGINE=InnoDB ROW_FORMAT=COMPRESSED; +CREATE TABLE `filtertype` +( + `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `expectedElements` bigint(20) UNSIGNED NOT NULL, + `targetFpp` DOUBLE(2, 2) UNSIGNED NOT NULL, + `pattern` VARCHAR(2048) NOT NULL, + UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci; \ No newline at end of file diff --git a/pom.xml b/pom.xml index be06540c..100d2066 100644 --- a/pom.xml +++ b/pom.xml @@ -197,6 +197,12 @@ ${jclouds.version} test + + com.h2database + h2 + 2.2.224 + test + org.apache.kafka kafka-clients @@ -304,7 +310,7 @@ - streamdb.log_group|streamdb.host|streamdb.stream|journaldb.host|journaldb.bucket|journaldb.logfile|bloomdb.filter_expected_100000_fpp_001|bloomdb.filter_expected_1000000_fpp_003|bloomdb.filter_expected_2500000_fpp_005 + streamdb.log_group|streamdb.host|streamdb.stream|journaldb.host|journaldb.bucket|journaldb.logfile|bloomdb.filtertype com.teragrep.pth_06.jooq.generated diff --git a/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java b/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java index 0f805d9b..abf11833 100644 --- a/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java +++ b/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java @@ -52,20 +52,15 @@ public final class ConditionConfig { private final DSLContext ctx; private final boolean streamQuery; private final boolean bloomEnabled; - private final boolean withoutFilters; public ConditionConfig(DSLContext ctx, boolean streamQuery) { - this.ctx = ctx; - this.streamQuery = streamQuery; - this.bloomEnabled = false; - this.withoutFilters = false; + this(ctx, streamQuery, false); } - public ConditionConfig(DSLContext ctx, boolean streamQuery, boolean bloomEnabled, boolean withoutFilters) { + public ConditionConfig(DSLContext ctx, boolean streamQuery, boolean bloomEnabled) { this.ctx = ctx; this.streamQuery = streamQuery; this.bloomEnabled = bloomEnabled; - this.withoutFilters = withoutFilters; } public DSLContext context() { @@ -80,10 +75,6 @@ public boolean streamQuery() { return streamQuery; } - public boolean withoutFilter() { - return withoutFilters; - } - @Override public boolean equals(Object object) { if (this == object) @@ -93,7 +84,6 @@ public boolean equals(Object object) { if (object.getClass() != this.getClass()) return false; final ConditionConfig cast = (ConditionConfig) object; - return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery - && this.withoutFilters == cast.withoutFilters && this.ctx == cast.ctx; + return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery && this.ctx == cast.ctx; } } diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java b/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java index 2bbd4cbf..c311b38b 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java index 66a093bd..1dd155d4 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 @@ -50,9 +50,7 @@ import com.teragrep.pth_06.jooq.generated.DefaultCatalog; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_1000000Fpp_003; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_100000Fpp_001; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_2500000Fpp_005; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.Filtertype; import java.util.ArrayList; import java.util.Arrays; @@ -78,7 +76,7 @@ @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Bloomdb extends SchemaImpl { - private static final long serialVersionUID = 1310856944; + private static final long serialVersionUID = -1839179080; /** * The reference instance of bloomdb @@ -86,19 +84,9 @@ public class Bloomdb extends SchemaImpl { public static final Bloomdb BLOOMDB = new Bloomdb(); /** - * The table bloomdb.filter_expected_1000000_fpp_003. + * The table bloomdb.filtertype. */ - public final FilterExpected_1000000Fpp_003 FILTER_EXPECTED_1000000_FPP_003 = com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003; - - /** - * The table bloomdb.filter_expected_100000_fpp_001. - */ - public final FilterExpected_100000Fpp_001 FILTER_EXPECTED_100000_FPP_001 = com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001; - - /** - * The table bloomdb.filter_expected_2500000_fpp_005. - */ - public final FilterExpected_2500000Fpp_005 FILTER_EXPECTED_2500000_FPP_005 = com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005; + public final Filtertype FILTERTYPE = com.teragrep.pth_06.jooq.generated.bloomdb.tables.Filtertype.FILTERTYPE; /** * No further instances allowed @@ -122,8 +110,6 @@ public final List> getTables() { private final List> getTables0() { return Arrays.>asList( - FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, - FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, - FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005); + Filtertype.FILTERTYPE); } } diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java index 7e6d00df..3a795632 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 @@ -49,9 +49,7 @@ package com.teragrep.pth_06.jooq.generated.bloomdb; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_1000000Fpp_003; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_100000Fpp_001; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_2500000Fpp_005; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.Filtertype; import javax.annotation.Generated; @@ -77,23 +75,15 @@ public class Indexes { // INDEX definitions // ------------------------------------------------------------------------- - public static final Index FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID = Indexes0.FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID; - public static final Index FILTER_EXPECTED_1000000_FPP_003_PRIMARY = Indexes0.FILTER_EXPECTED_1000000_FPP_003_PRIMARY; - public static final Index FILTER_EXPECTED_100000_FPP_001_PARTITION_ID = Indexes0.FILTER_EXPECTED_100000_FPP_001_PARTITION_ID; - public static final Index FILTER_EXPECTED_100000_FPP_001_PRIMARY = Indexes0.FILTER_EXPECTED_100000_FPP_001_PRIMARY; - public static final Index FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID = Indexes0.FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID; - public static final Index FILTER_EXPECTED_2500000_FPP_005_PRIMARY = Indexes0.FILTER_EXPECTED_2500000_FPP_005_PRIMARY; + public static final Index FILTERTYPE_EXPECTEDELEMENTS = Indexes0.FILTERTYPE_EXPECTEDELEMENTS; + public static final Index FILTERTYPE_PRIMARY = Indexes0.FILTERTYPE_PRIMARY; // ------------------------------------------------------------------------- // [#1459] distribute members to avoid static initialisers > 64kb // ------------------------------------------------------------------------- private static class Indexes0 { - public static Index FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID = Internal.createIndex("partition_id", FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, new OrderField[] { FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.PARTITION_ID }, true); - public static Index FILTER_EXPECTED_1000000_FPP_003_PRIMARY = Internal.createIndex("PRIMARY", FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, new OrderField[] { FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.ID }, true); - public static Index FILTER_EXPECTED_100000_FPP_001_PARTITION_ID = Internal.createIndex("partition_id", FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, new OrderField[] { FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.PARTITION_ID }, true); - public static Index FILTER_EXPECTED_100000_FPP_001_PRIMARY = Internal.createIndex("PRIMARY", FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, new OrderField[] { FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.ID }, true); - public static Index FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID = Internal.createIndex("partition_id", FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005, new OrderField[] { FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.PARTITION_ID }, true); - public static Index FILTER_EXPECTED_2500000_FPP_005_PRIMARY = Internal.createIndex("PRIMARY", FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005, new OrderField[] { FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.ID }, true); + public static Index FILTERTYPE_EXPECTEDELEMENTS = Internal.createIndex("expectedElements", Filtertype.FILTERTYPE, new OrderField[] { Filtertype.FILTERTYPE.EXPECTEDELEMENTS, Filtertype.FILTERTYPE.TARGETFPP, Filtertype.FILTERTYPE.PATTERN }, true); + public static Index FILTERTYPE_PRIMARY = Internal.createIndex("PRIMARY", Filtertype.FILTERTYPE, new OrderField[] { Filtertype.FILTERTYPE.ID }, true); } } diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java index 7fac4939..13f2b35a 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 @@ -49,20 +49,15 @@ package com.teragrep.pth_06.jooq.generated.bloomdb; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_1000000Fpp_003; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_100000Fpp_001; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_2500000Fpp_005; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FilterExpected_1000000Fpp_003Record; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FilterExpected_100000Fpp_001Record; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FilterExpected_2500000Fpp_005Record; -import com.teragrep.pth_06.jooq.generated.journaldb.tables.records.LogfileRecord; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.Filtertype; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FiltertypeRecord; import javax.annotation.Generated; -import org.jooq.ForeignKey; import org.jooq.Identity; import org.jooq.UniqueKey; import org.jooq.impl.Internal; +import org.jooq.types.ULong; /** @@ -83,51 +78,30 @@ public class Keys { // IDENTITY definitions // ------------------------------------------------------------------------- - public static final Identity IDENTITY_FILTER_EXPECTED_1000000_FPP_003 = Identities0.IDENTITY_FILTER_EXPECTED_1000000_FPP_003; - public static final Identity IDENTITY_FILTER_EXPECTED_100000_FPP_001 = Identities0.IDENTITY_FILTER_EXPECTED_100000_FPP_001; - public static final Identity IDENTITY_FILTER_EXPECTED_2500000_FPP_005 = Identities0.IDENTITY_FILTER_EXPECTED_2500000_FPP_005; + public static final Identity IDENTITY_FILTERTYPE = Identities0.IDENTITY_FILTERTYPE; // ------------------------------------------------------------------------- // UNIQUE and PRIMARY KEY definitions // ------------------------------------------------------------------------- - public static final UniqueKey KEY_FILTER_EXPECTED_1000000_FPP_003_PRIMARY = UniqueKeys0.KEY_FILTER_EXPECTED_1000000_FPP_003_PRIMARY; - public static final UniqueKey KEY_FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID = UniqueKeys0.KEY_FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID; - public static final UniqueKey KEY_FILTER_EXPECTED_100000_FPP_001_PRIMARY = UniqueKeys0.KEY_FILTER_EXPECTED_100000_FPP_001_PRIMARY; - public static final UniqueKey KEY_FILTER_EXPECTED_100000_FPP_001_PARTITION_ID = UniqueKeys0.KEY_FILTER_EXPECTED_100000_FPP_001_PARTITION_ID; - public static final UniqueKey KEY_FILTER_EXPECTED_2500000_FPP_005_PRIMARY = UniqueKeys0.KEY_FILTER_EXPECTED_2500000_FPP_005_PRIMARY; - public static final UniqueKey KEY_FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID = UniqueKeys0.KEY_FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID; + public static final UniqueKey KEY_FILTERTYPE_PRIMARY = UniqueKeys0.KEY_FILTERTYPE_PRIMARY; + public static final UniqueKey KEY_FILTERTYPE_EXPECTEDELEMENTS = UniqueKeys0.KEY_FILTERTYPE_EXPECTEDELEMENTS; // ------------------------------------------------------------------------- // FOREIGN KEY definitions // ------------------------------------------------------------------------- - public static final ForeignKey FK_MEDIUMFILTER_PARTITION = ForeignKeys0.FK_MEDIUMFILTER_PARTITION; - public static final ForeignKey FK_SMALLFILTER_PARTITION = ForeignKeys0.FK_SMALLFILTER_PARTITION; - public static final ForeignKey FK_LARGEFILTER_PARTITION = ForeignKeys0.FK_LARGEFILTER_PARTITION; // ------------------------------------------------------------------------- // [#1459] distribute members to avoid static initialisers > 64kb // ------------------------------------------------------------------------- private static class Identities0 { - public static Identity IDENTITY_FILTER_EXPECTED_1000000_FPP_003 = Internal.createIdentity(FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.ID); - public static Identity IDENTITY_FILTER_EXPECTED_100000_FPP_001 = Internal.createIdentity(FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.ID); - public static Identity IDENTITY_FILTER_EXPECTED_2500000_FPP_005 = Internal.createIdentity(FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005, FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.ID); + public static Identity IDENTITY_FILTERTYPE = Internal.createIdentity(Filtertype.FILTERTYPE, Filtertype.FILTERTYPE.ID); } private static class UniqueKeys0 { - public static final UniqueKey KEY_FILTER_EXPECTED_1000000_FPP_003_PRIMARY = Internal.createUniqueKey(FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, "KEY_filter_expected_1000000_fpp_003_PRIMARY", FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.ID); - public static final UniqueKey KEY_FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID = Internal.createUniqueKey(FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, "KEY_filter_expected_1000000_fpp_003_partition_id", FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.PARTITION_ID); - public static final UniqueKey KEY_FILTER_EXPECTED_100000_FPP_001_PRIMARY = Internal.createUniqueKey(FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, "KEY_filter_expected_100000_fpp_001_PRIMARY", FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.ID); - public static final UniqueKey KEY_FILTER_EXPECTED_100000_FPP_001_PARTITION_ID = Internal.createUniqueKey(FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, "KEY_filter_expected_100000_fpp_001_partition_id", FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.PARTITION_ID); - public static final UniqueKey KEY_FILTER_EXPECTED_2500000_FPP_005_PRIMARY = Internal.createUniqueKey(FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005, "KEY_filter_expected_2500000_fpp_005_PRIMARY", FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.ID); - public static final UniqueKey KEY_FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID = Internal.createUniqueKey(FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005, "KEY_filter_expected_2500000_fpp_005_partition_id", FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.PARTITION_ID); - } - - private static class ForeignKeys0 { - public static final ForeignKey FK_MEDIUMFILTER_PARTITION = Internal.createForeignKey(com.teragrep.pth_06.jooq.generated.journaldb.Keys.KEY_LOGFILE_PRIMARY, FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003, "fk_mediumfilter_partition", FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.PARTITION_ID); - public static final ForeignKey FK_SMALLFILTER_PARTITION = Internal.createForeignKey(com.teragrep.pth_06.jooq.generated.journaldb.Keys.KEY_LOGFILE_PRIMARY, FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001, "fk_smallfilter_partition", FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.PARTITION_ID); - public static final ForeignKey FK_LARGEFILTER_PARTITION = Internal.createForeignKey(com.teragrep.pth_06.jooq.generated.journaldb.Keys.KEY_LOGFILE_PRIMARY, FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005, "fk_largefilter_partition", FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.PARTITION_ID); + public static final UniqueKey KEY_FILTERTYPE_PRIMARY = Internal.createUniqueKey(Filtertype.FILTERTYPE, "KEY_filtertype_PRIMARY", Filtertype.FILTERTYPE.ID); + public static final UniqueKey KEY_FILTERTYPE_EXPECTEDELEMENTS = Internal.createUniqueKey(Filtertype.FILTERTYPE, "KEY_filtertype_expectedElements", Filtertype.FILTERTYPE.EXPECTEDELEMENTS, Filtertype.FILTERTYPE.TARGETFPP, Filtertype.FILTERTYPE.PATTERN); } } diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java index c56d26ae..146d9e63 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 @@ -49,9 +49,7 @@ package com.teragrep.pth_06.jooq.generated.bloomdb; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_1000000Fpp_003; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_100000Fpp_001; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_2500000Fpp_005; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.Filtertype; import javax.annotation.Generated; @@ -70,17 +68,7 @@ public class Tables { /** - * The table bloomdb.filter_expected_1000000_fpp_003. + * The table bloomdb.filtertype. */ - public static final FilterExpected_1000000Fpp_003 FILTER_EXPECTED_1000000_FPP_003 = FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003; - - /** - * The table bloomdb.filter_expected_100000_fpp_001. - */ - public static final FilterExpected_100000Fpp_001 FILTER_EXPECTED_100000_FPP_001 = FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001; - - /** - * The table bloomdb.filter_expected_2500000_fpp_005. - */ - public static final FilterExpected_2500000Fpp_005 FILTER_EXPECTED_2500000_FPP_005 = FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005; + public static final Filtertype FILTERTYPE = Filtertype.FILTERTYPE; } diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_1000000Fpp_003.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_1000000Fpp_003.java deleted file mode 100644 index 00fc68bb..00000000 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_1000000Fpp_003.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -/* - * This file is generated by jOOQ. - */ -package com.teragrep.pth_06.jooq.generated.bloomdb.tables; - - -import com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb; -import com.teragrep.pth_06.jooq.generated.bloomdb.Indexes; -import com.teragrep.pth_06.jooq.generated.bloomdb.Keys; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FilterExpected_1000000Fpp_003Record; -import com.teragrep.pth_06.jooq.generated.journaldb.tables.Logfile; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.ForeignKey; -import org.jooq.Identity; -import org.jooq.Index; -import org.jooq.Name; -import org.jooq.Record; -import org.jooq.Row3; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.DSL; -import org.jooq.impl.TableImpl; -import org.jooq.types.ULong; - - -/** - * This class is generated by jOOQ. - */ -@Generated( - value = { - "http://www.jooq.org", - "jOOQ version:3.12.4" - }, - comments = "This class is generated by jOOQ" -) -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class FilterExpected_1000000Fpp_003 extends TableImpl { - - private static final long serialVersionUID = -1153410410; - - /** - * The reference instance of bloomdb.filter_expected_1000000_fpp_003 - */ - public static final FilterExpected_1000000Fpp_003 FILTER_EXPECTED_1000000_FPP_003 = new FilterExpected_1000000Fpp_003(); - - /** - * The class holding records for this type - */ - @Override - public Class getRecordType() { - return FilterExpected_1000000Fpp_003Record.class; - } - - /** - * The column bloomdb.filter_expected_1000000_fpp_003.id. - */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).identity(true), this, ""); - - /** - * The column bloomdb.filter_expected_1000000_fpp_003.partition_id. - */ - public final TableField PARTITION_ID = createField(DSL.name("partition_id"), org.jooq.impl.SQLDataType.BIGINTUNSIGNED.nullable(false), this, ""); - - /** - * The column bloomdb.filter_expected_1000000_fpp_003.filter. - */ - public final TableField FILTER = createField(DSL.name("filter"), org.jooq.impl.SQLDataType.BLOB.defaultValue(org.jooq.impl.DSL.field("NULL", org.jooq.impl.SQLDataType.BLOB)), this, ""); - - /** - * Create a bloomdb.filter_expected_1000000_fpp_003 table reference - */ - public FilterExpected_1000000Fpp_003() { - this(DSL.name("filter_expected_1000000_fpp_003"), null); - } - - /** - * Create an aliased bloomdb.filter_expected_1000000_fpp_003 table reference - */ - public FilterExpected_1000000Fpp_003(String alias) { - this(DSL.name(alias), FILTER_EXPECTED_1000000_FPP_003); - } - - /** - * Create an aliased bloomdb.filter_expected_1000000_fpp_003 table reference - */ - public FilterExpected_1000000Fpp_003(Name alias) { - this(alias, FILTER_EXPECTED_1000000_FPP_003); - } - - private FilterExpected_1000000Fpp_003(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private FilterExpected_1000000Fpp_003(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment("")); - } - - public FilterExpected_1000000Fpp_003(Table child, ForeignKey key) { - super(child, key, FILTER_EXPECTED_1000000_FPP_003); - } - - @Override - public Schema getSchema() { - return Bloomdb.BLOOMDB; - } - - @Override - public List getIndexes() { - return Arrays.asList(Indexes.FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID, Indexes.FILTER_EXPECTED_1000000_FPP_003_PRIMARY); - } - - @Override - public Identity getIdentity() { - return Keys.IDENTITY_FILTER_EXPECTED_1000000_FPP_003; - } - - @Override - public UniqueKey getPrimaryKey() { - return Keys.KEY_FILTER_EXPECTED_1000000_FPP_003_PRIMARY; - } - - @Override - public List> getKeys() { - return Arrays.>asList(Keys.KEY_FILTER_EXPECTED_1000000_FPP_003_PRIMARY, Keys.KEY_FILTER_EXPECTED_1000000_FPP_003_PARTITION_ID); - } - - @Override - public List> getReferences() { - return Arrays.>asList(Keys.FK_MEDIUMFILTER_PARTITION); - } - - public Logfile logfile() { - return new Logfile(this, Keys.FK_MEDIUMFILTER_PARTITION); - } - - @Override - public FilterExpected_1000000Fpp_003 as(String alias) { - return new FilterExpected_1000000Fpp_003(DSL.name(alias), this); - } - - @Override - public FilterExpected_1000000Fpp_003 as(Name alias) { - return new FilterExpected_1000000Fpp_003(alias, this); - } - - /** - * Rename this table - */ - @Override - public FilterExpected_1000000Fpp_003 rename(String name) { - return new FilterExpected_1000000Fpp_003(DSL.name(name), null); - } - - /** - * Rename this table - */ - @Override - public FilterExpected_1000000Fpp_003 rename(Name name) { - return new FilterExpected_1000000Fpp_003(name, null); - } - - // ------------------------------------------------------------------------- - // Row3 type methods - // ------------------------------------------------------------------------- - - @Override - public Row3 fieldsRow() { - return (Row3) super.fieldsRow(); - } -} diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_100000Fpp_001.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_100000Fpp_001.java deleted file mode 100644 index a135e84d..00000000 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_100000Fpp_001.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -/* - * This file is generated by jOOQ. - */ -package com.teragrep.pth_06.jooq.generated.bloomdb.tables; - - -import com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb; -import com.teragrep.pth_06.jooq.generated.bloomdb.Indexes; -import com.teragrep.pth_06.jooq.generated.bloomdb.Keys; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FilterExpected_100000Fpp_001Record; -import com.teragrep.pth_06.jooq.generated.journaldb.tables.Logfile; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.ForeignKey; -import org.jooq.Identity; -import org.jooq.Index; -import org.jooq.Name; -import org.jooq.Record; -import org.jooq.Row3; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.DSL; -import org.jooq.impl.TableImpl; -import org.jooq.types.ULong; - - -/** - * This class is generated by jOOQ. - */ -@Generated( - value = { - "http://www.jooq.org", - "jOOQ version:3.12.4" - }, - comments = "This class is generated by jOOQ" -) -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class FilterExpected_100000Fpp_001 extends TableImpl { - - private static final long serialVersionUID = 1282555104; - - /** - * The reference instance of bloomdb.filter_expected_100000_fpp_001 - */ - public static final FilterExpected_100000Fpp_001 FILTER_EXPECTED_100000_FPP_001 = new FilterExpected_100000Fpp_001(); - - /** - * The class holding records for this type - */ - @Override - public Class getRecordType() { - return FilterExpected_100000Fpp_001Record.class; - } - - /** - * The column bloomdb.filter_expected_100000_fpp_001.id. - */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).identity(true), this, ""); - - /** - * The column bloomdb.filter_expected_100000_fpp_001.partition_id. - */ - public final TableField PARTITION_ID = createField(DSL.name("partition_id"), org.jooq.impl.SQLDataType.BIGINTUNSIGNED.nullable(false), this, ""); - - /** - * The column bloomdb.filter_expected_100000_fpp_001.filter. - */ - public final TableField FILTER = createField(DSL.name("filter"), org.jooq.impl.SQLDataType.BLOB.defaultValue(org.jooq.impl.DSL.field("NULL", org.jooq.impl.SQLDataType.BLOB)), this, ""); - - /** - * Create a bloomdb.filter_expected_100000_fpp_001 table reference - */ - public FilterExpected_100000Fpp_001() { - this(DSL.name("filter_expected_100000_fpp_001"), null); - } - - /** - * Create an aliased bloomdb.filter_expected_100000_fpp_001 table reference - */ - public FilterExpected_100000Fpp_001(String alias) { - this(DSL.name(alias), FILTER_EXPECTED_100000_FPP_001); - } - - /** - * Create an aliased bloomdb.filter_expected_100000_fpp_001 table reference - */ - public FilterExpected_100000Fpp_001(Name alias) { - this(alias, FILTER_EXPECTED_100000_FPP_001); - } - - private FilterExpected_100000Fpp_001(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private FilterExpected_100000Fpp_001(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment("")); - } - - public FilterExpected_100000Fpp_001(Table child, ForeignKey key) { - super(child, key, FILTER_EXPECTED_100000_FPP_001); - } - - @Override - public Schema getSchema() { - return Bloomdb.BLOOMDB; - } - - @Override - public List getIndexes() { - return Arrays.asList(Indexes.FILTER_EXPECTED_100000_FPP_001_PARTITION_ID, Indexes.FILTER_EXPECTED_100000_FPP_001_PRIMARY); - } - - @Override - public Identity getIdentity() { - return Keys.IDENTITY_FILTER_EXPECTED_100000_FPP_001; - } - - @Override - public UniqueKey getPrimaryKey() { - return Keys.KEY_FILTER_EXPECTED_100000_FPP_001_PRIMARY; - } - - @Override - public List> getKeys() { - return Arrays.>asList(Keys.KEY_FILTER_EXPECTED_100000_FPP_001_PRIMARY, Keys.KEY_FILTER_EXPECTED_100000_FPP_001_PARTITION_ID); - } - - @Override - public List> getReferences() { - return Arrays.>asList(Keys.FK_SMALLFILTER_PARTITION); - } - - public Logfile logfile() { - return new Logfile(this, Keys.FK_SMALLFILTER_PARTITION); - } - - @Override - public FilterExpected_100000Fpp_001 as(String alias) { - return new FilterExpected_100000Fpp_001(DSL.name(alias), this); - } - - @Override - public FilterExpected_100000Fpp_001 as(Name alias) { - return new FilterExpected_100000Fpp_001(alias, this); - } - - /** - * Rename this table - */ - @Override - public FilterExpected_100000Fpp_001 rename(String name) { - return new FilterExpected_100000Fpp_001(DSL.name(name), null); - } - - /** - * Rename this table - */ - @Override - public FilterExpected_100000Fpp_001 rename(Name name) { - return new FilterExpected_100000Fpp_001(name, null); - } - - // ------------------------------------------------------------------------- - // Row3 type methods - // ------------------------------------------------------------------------- - - @Override - public Row3 fieldsRow() { - return (Row3) super.fieldsRow(); - } -} diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_2500000Fpp_005.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_2500000Fpp_005.java deleted file mode 100644 index 3cbaf726..00000000 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/FilterExpected_2500000Fpp_005.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -/* - * This file is generated by jOOQ. - */ -package com.teragrep.pth_06.jooq.generated.bloomdb.tables; - - -import com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb; -import com.teragrep.pth_06.jooq.generated.bloomdb.Indexes; -import com.teragrep.pth_06.jooq.generated.bloomdb.Keys; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FilterExpected_2500000Fpp_005Record; -import com.teragrep.pth_06.jooq.generated.journaldb.tables.Logfile; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.ForeignKey; -import org.jooq.Identity; -import org.jooq.Index; -import org.jooq.Name; -import org.jooq.Record; -import org.jooq.Row3; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.DSL; -import org.jooq.impl.TableImpl; -import org.jooq.types.ULong; - - -/** - * This class is generated by jOOQ. - */ -@Generated( - value = { - "http://www.jooq.org", - "jOOQ version:3.12.4" - }, - comments = "This class is generated by jOOQ" -) -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class FilterExpected_2500000Fpp_005 extends TableImpl { - - private static final long serialVersionUID = 1626135712; - - /** - * The reference instance of bloomdb.filter_expected_2500000_fpp_005 - */ - public static final FilterExpected_2500000Fpp_005 FILTER_EXPECTED_2500000_FPP_005 = new FilterExpected_2500000Fpp_005(); - - /** - * The class holding records for this type - */ - @Override - public Class getRecordType() { - return FilterExpected_2500000Fpp_005Record.class; - } - - /** - * The column bloomdb.filter_expected_2500000_fpp_005.id. - */ - public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.INTEGER.nullable(false).identity(true), this, ""); - - /** - * The column bloomdb.filter_expected_2500000_fpp_005.partition_id. - */ - public final TableField PARTITION_ID = createField(DSL.name("partition_id"), org.jooq.impl.SQLDataType.BIGINTUNSIGNED.nullable(false), this, ""); - - /** - * The column bloomdb.filter_expected_2500000_fpp_005.filter. - */ - public final TableField FILTER = createField(DSL.name("filter"), org.jooq.impl.SQLDataType.BLOB.defaultValue(org.jooq.impl.DSL.field("NULL", org.jooq.impl.SQLDataType.BLOB)), this, ""); - - /** - * Create a bloomdb.filter_expected_2500000_fpp_005 table reference - */ - public FilterExpected_2500000Fpp_005() { - this(DSL.name("filter_expected_2500000_fpp_005"), null); - } - - /** - * Create an aliased bloomdb.filter_expected_2500000_fpp_005 table reference - */ - public FilterExpected_2500000Fpp_005(String alias) { - this(DSL.name(alias), FILTER_EXPECTED_2500000_FPP_005); - } - - /** - * Create an aliased bloomdb.filter_expected_2500000_fpp_005 table reference - */ - public FilterExpected_2500000Fpp_005(Name alias) { - this(alias, FILTER_EXPECTED_2500000_FPP_005); - } - - private FilterExpected_2500000Fpp_005(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private FilterExpected_2500000Fpp_005(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment("")); - } - - public FilterExpected_2500000Fpp_005(Table child, ForeignKey key) { - super(child, key, FILTER_EXPECTED_2500000_FPP_005); - } - - @Override - public Schema getSchema() { - return Bloomdb.BLOOMDB; - } - - @Override - public List getIndexes() { - return Arrays.asList(Indexes.FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID, Indexes.FILTER_EXPECTED_2500000_FPP_005_PRIMARY); - } - - @Override - public Identity getIdentity() { - return Keys.IDENTITY_FILTER_EXPECTED_2500000_FPP_005; - } - - @Override - public UniqueKey getPrimaryKey() { - return Keys.KEY_FILTER_EXPECTED_2500000_FPP_005_PRIMARY; - } - - @Override - public List> getKeys() { - return Arrays.>asList(Keys.KEY_FILTER_EXPECTED_2500000_FPP_005_PRIMARY, Keys.KEY_FILTER_EXPECTED_2500000_FPP_005_PARTITION_ID); - } - - @Override - public List> getReferences() { - return Arrays.>asList(Keys.FK_LARGEFILTER_PARTITION); - } - - public Logfile logfile() { - return new Logfile(this, Keys.FK_LARGEFILTER_PARTITION); - } - - @Override - public FilterExpected_2500000Fpp_005 as(String alias) { - return new FilterExpected_2500000Fpp_005(DSL.name(alias), this); - } - - @Override - public FilterExpected_2500000Fpp_005 as(Name alias) { - return new FilterExpected_2500000Fpp_005(alias, this); - } - - /** - * Rename this table - */ - @Override - public FilterExpected_2500000Fpp_005 rename(String name) { - return new FilterExpected_2500000Fpp_005(DSL.name(name), null); - } - - /** - * Rename this table - */ - @Override - public FilterExpected_2500000Fpp_005 rename(Name name) { - return new FilterExpected_2500000Fpp_005(name, null); - } - - // ------------------------------------------------------------------------- - // Row3 type methods - // ------------------------------------------------------------------------- - - @Override - public Row3 fieldsRow() { - return (Row3) super.fieldsRow(); - } -} diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java new file mode 100644 index 00000000..c60c2332 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java @@ -0,0 +1,218 @@ +/* + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +/* + * This file is generated by jOOQ. + */ +package com.teragrep.pth_06.jooq.generated.bloomdb.tables; + + +import com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb; +import com.teragrep.pth_06.jooq.generated.bloomdb.Indexes; +import com.teragrep.pth_06.jooq.generated.bloomdb.Keys; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.records.FiltertypeRecord; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Identity; +import org.jooq.Index; +import org.jooq.Name; +import org.jooq.Record; +import org.jooq.Row4; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.UniqueKey; +import org.jooq.impl.DSL; +import org.jooq.impl.TableImpl; +import org.jooq.types.ULong; + + +/** + * This class is generated by jOOQ. + */ +@Generated( + value = { + "http://www.jooq.org", + "jOOQ version:3.12.4" + }, + comments = "This class is generated by jOOQ" +) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Filtertype extends TableImpl { + + private static final long serialVersionUID = -832934084; + + /** + * The reference instance of bloomdb.filtertype + */ + public static final Filtertype FILTERTYPE = new Filtertype(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return FiltertypeRecord.class; + } + + /** + * The column bloomdb.filtertype.id. + */ + public final TableField ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.BIGINTUNSIGNED.nullable(false).identity(true), this, ""); + + /** + * The column bloomdb.filtertype.expectedElements. + */ + public final TableField EXPECTEDELEMENTS = createField(DSL.name("expectedElements"), org.jooq.impl.SQLDataType.BIGINTUNSIGNED.nullable(false), this, ""); + + /** + * The column bloomdb.filtertype.targetFpp. + */ + public final TableField TARGETFPP = createField(DSL.name("targetFpp"), org.jooq.impl.SQLDataType.DOUBLE.nullable(false), this, ""); + + /** + * The column bloomdb.filtertype.pattern. + */ + public final TableField PATTERN = createField(DSL.name("pattern"), org.jooq.impl.SQLDataType.VARCHAR(2048).nullable(false), this, ""); + + /** + * Create a bloomdb.filtertype table reference + */ + public Filtertype() { + this(DSL.name("filtertype"), null); + } + + /** + * Create an aliased bloomdb.filtertype table reference + */ + public Filtertype(String alias) { + this(DSL.name(alias), FILTERTYPE); + } + + /** + * Create an aliased bloomdb.filtertype table reference + */ + public Filtertype(Name alias) { + this(alias, FILTERTYPE); + } + + private Filtertype(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private Filtertype(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment("")); + } + + public Filtertype(Table child, ForeignKey key) { + super(child, key, FILTERTYPE); + } + + @Override + public Schema getSchema() { + return Bloomdb.BLOOMDB; + } + + @Override + public List getIndexes() { + return Arrays.asList(Indexes.FILTERTYPE_EXPECTEDELEMENTS, Indexes.FILTERTYPE_PRIMARY); + } + + @Override + public Identity getIdentity() { + return Keys.IDENTITY_FILTERTYPE; + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.KEY_FILTERTYPE_PRIMARY; + } + + @Override + public List> getKeys() { + return Arrays.>asList(Keys.KEY_FILTERTYPE_PRIMARY, Keys.KEY_FILTERTYPE_EXPECTEDELEMENTS); + } + + @Override + public Filtertype as(String alias) { + return new Filtertype(DSL.name(alias), this); + } + + @Override + public Filtertype as(Name alias) { + return new Filtertype(alias, this); + } + + /** + * Rename this table + */ + @Override + public Filtertype rename(String name) { + return new Filtertype(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public Filtertype rename(Name name) { + return new Filtertype(name, null); + } + + // ------------------------------------------------------------------------- + // Row4 type methods + // ------------------------------------------------------------------------- + + @Override + public Row4 fieldsRow() { + return (Row4) super.fieldsRow(); + } +} diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_1000000Fpp_003Record.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_1000000Fpp_003Record.java deleted file mode 100644 index 9db79966..00000000 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_1000000Fpp_003Record.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -/* - * This file is generated by jOOQ. - */ -package com.teragrep.pth_06.jooq.generated.bloomdb.tables.records; - - -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_1000000Fpp_003; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.Record1; -import org.jooq.Record3; -import org.jooq.Row3; -import org.jooq.impl.UpdatableRecordImpl; -import org.jooq.types.ULong; - - -/** - * This class is generated by jOOQ. - */ -@Generated( - value = { - "http://www.jooq.org", - "jOOQ version:3.12.4" - }, - comments = "This class is generated by jOOQ" -) -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class FilterExpected_1000000Fpp_003Record extends UpdatableRecordImpl implements Record3 { - - private static final long serialVersionUID = 305015494; - - /** - * Setter for bloomdb.filter_expected_1000000_fpp_003.id. - */ - public void setId(Integer value) { - set(0, value); - } - - /** - * Getter for bloomdb.filter_expected_1000000_fpp_003.id. - */ - public Integer getId() { - return (Integer) get(0); - } - - /** - * Setter for bloomdb.filter_expected_1000000_fpp_003.partition_id. - */ - public void setPartitionId(ULong value) { - set(1, value); - } - - /** - * Getter for bloomdb.filter_expected_1000000_fpp_003.partition_id. - */ - public ULong getPartitionId() { - return (ULong) get(1); - } - - /** - * Setter for bloomdb.filter_expected_1000000_fpp_003.filter. - */ - public void setFilter(byte... value) { - set(2, value); - } - - /** - * Getter for bloomdb.filter_expected_1000000_fpp_003.filter. - */ - public byte[] getFilter() { - return (byte[]) get(2); - } - - // ------------------------------------------------------------------------- - // Primary key information - // ------------------------------------------------------------------------- - - @Override - public Record1 key() { - return (Record1) super.key(); - } - - // ------------------------------------------------------------------------- - // Record3 type implementation - // ------------------------------------------------------------------------- - - @Override - public Row3 fieldsRow() { - return (Row3) super.fieldsRow(); - } - - @Override - public Row3 valuesRow() { - return (Row3) super.valuesRow(); - } - - @Override - public Field field1() { - return FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.ID; - } - - @Override - public Field field2() { - return FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.PARTITION_ID; - } - - @Override - public Field field3() { - return FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003.FILTER; - } - - @Override - public Integer component1() { - return getId(); - } - - @Override - public ULong component2() { - return getPartitionId(); - } - - @Override - public byte[] component3() { - return getFilter(); - } - - @Override - public Integer value1() { - return getId(); - } - - @Override - public ULong value2() { - return getPartitionId(); - } - - @Override - public byte[] value3() { - return getFilter(); - } - - @Override - public FilterExpected_1000000Fpp_003Record value1(Integer value) { - setId(value); - return this; - } - - @Override - public FilterExpected_1000000Fpp_003Record value2(ULong value) { - setPartitionId(value); - return this; - } - - @Override - public FilterExpected_1000000Fpp_003Record value3(byte... value) { - setFilter(value); - return this; - } - - @Override - public FilterExpected_1000000Fpp_003Record values(Integer value1, ULong value2, byte[] value3) { - value1(value1); - value2(value2); - value3(value3); - return this; - } - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - /** - * Create a detached FilterExpected_1000000Fpp_003Record - */ - public FilterExpected_1000000Fpp_003Record() { - super(FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003); - } - - /** - * Create a detached, initialised FilterExpected_1000000Fpp_003Record - */ - public FilterExpected_1000000Fpp_003Record(Integer id, ULong partitionId, byte[] filter) { - super(FilterExpected_1000000Fpp_003.FILTER_EXPECTED_1000000_FPP_003); - - set(0, id); - set(1, partitionId); - set(2, filter); - } -} diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_2500000Fpp_005Record.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_2500000Fpp_005Record.java deleted file mode 100644 index 639d59a9..00000000 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_2500000Fpp_005Record.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -/* - * This file is generated by jOOQ. - */ -package com.teragrep.pth_06.jooq.generated.bloomdb.tables.records; - - -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_2500000Fpp_005; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.Record1; -import org.jooq.Record3; -import org.jooq.Row3; -import org.jooq.impl.UpdatableRecordImpl; -import org.jooq.types.ULong; - - -/** - * This class is generated by jOOQ. - */ -@Generated( - value = { - "http://www.jooq.org", - "jOOQ version:3.12.4" - }, - comments = "This class is generated by jOOQ" -) -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class FilterExpected_2500000Fpp_005Record extends UpdatableRecordImpl implements Record3 { - - private static final long serialVersionUID = -557327928; - - /** - * Setter for bloomdb.filter_expected_2500000_fpp_005.id. - */ - public void setId(Integer value) { - set(0, value); - } - - /** - * Getter for bloomdb.filter_expected_2500000_fpp_005.id. - */ - public Integer getId() { - return (Integer) get(0); - } - - /** - * Setter for bloomdb.filter_expected_2500000_fpp_005.partition_id. - */ - public void setPartitionId(ULong value) { - set(1, value); - } - - /** - * Getter for bloomdb.filter_expected_2500000_fpp_005.partition_id. - */ - public ULong getPartitionId() { - return (ULong) get(1); - } - - /** - * Setter for bloomdb.filter_expected_2500000_fpp_005.filter. - */ - public void setFilter(byte... value) { - set(2, value); - } - - /** - * Getter for bloomdb.filter_expected_2500000_fpp_005.filter. - */ - public byte[] getFilter() { - return (byte[]) get(2); - } - - // ------------------------------------------------------------------------- - // Primary key information - // ------------------------------------------------------------------------- - - @Override - public Record1 key() { - return (Record1) super.key(); - } - - // ------------------------------------------------------------------------- - // Record3 type implementation - // ------------------------------------------------------------------------- - - @Override - public Row3 fieldsRow() { - return (Row3) super.fieldsRow(); - } - - @Override - public Row3 valuesRow() { - return (Row3) super.valuesRow(); - } - - @Override - public Field field1() { - return FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.ID; - } - - @Override - public Field field2() { - return FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.PARTITION_ID; - } - - @Override - public Field field3() { - return FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005.FILTER; - } - - @Override - public Integer component1() { - return getId(); - } - - @Override - public ULong component2() { - return getPartitionId(); - } - - @Override - public byte[] component3() { - return getFilter(); - } - - @Override - public Integer value1() { - return getId(); - } - - @Override - public ULong value2() { - return getPartitionId(); - } - - @Override - public byte[] value3() { - return getFilter(); - } - - @Override - public FilterExpected_2500000Fpp_005Record value1(Integer value) { - setId(value); - return this; - } - - @Override - public FilterExpected_2500000Fpp_005Record value2(ULong value) { - setPartitionId(value); - return this; - } - - @Override - public FilterExpected_2500000Fpp_005Record value3(byte... value) { - setFilter(value); - return this; - } - - @Override - public FilterExpected_2500000Fpp_005Record values(Integer value1, ULong value2, byte[] value3) { - value1(value1); - value2(value2); - value3(value3); - return this; - } - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - /** - * Create a detached FilterExpected_2500000Fpp_005Record - */ - public FilterExpected_2500000Fpp_005Record() { - super(FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005); - } - - /** - * Create a detached, initialised FilterExpected_2500000Fpp_005Record - */ - public FilterExpected_2500000Fpp_005Record(Integer id, ULong partitionId, byte[] filter) { - super(FilterExpected_2500000Fpp_005.FILTER_EXPECTED_2500000_FPP_005); - - set(0, id); - set(1, partitionId); - set(2, filter); - } -} diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_100000Fpp_001Record.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java similarity index 53% rename from src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_100000Fpp_001Record.java rename to src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java index a61f9eed..bd782920 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FilterExpected_100000Fpp_001Record.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 @@ -49,14 +49,14 @@ package com.teragrep.pth_06.jooq.generated.bloomdb.tables.records; -import com.teragrep.pth_06.jooq.generated.bloomdb.tables.FilterExpected_100000Fpp_001; +import com.teragrep.pth_06.jooq.generated.bloomdb.tables.Filtertype; import javax.annotation.Generated; import org.jooq.Field; import org.jooq.Record1; -import org.jooq.Record3; -import org.jooq.Row3; +import org.jooq.Record4; +import org.jooq.Row4; import org.jooq.impl.UpdatableRecordImpl; import org.jooq.types.ULong; @@ -72,50 +72,64 @@ comments = "This class is generated by jOOQ" ) @SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class FilterExpected_100000Fpp_001Record extends UpdatableRecordImpl implements Record3 { +public class FiltertypeRecord extends UpdatableRecordImpl implements Record4 { - private static final long serialVersionUID = -373382442; + private static final long serialVersionUID = 962824899; /** - * Setter for bloomdb.filter_expected_100000_fpp_001.id. + * Setter for bloomdb.filtertype.id. */ - public void setId(Integer value) { + public void setId(ULong value) { set(0, value); } /** - * Getter for bloomdb.filter_expected_100000_fpp_001.id. + * Getter for bloomdb.filtertype.id. */ - public Integer getId() { - return (Integer) get(0); + public ULong getId() { + return (ULong) get(0); } /** - * Setter for bloomdb.filter_expected_100000_fpp_001.partition_id. + * Setter for bloomdb.filtertype.expectedElements. */ - public void setPartitionId(ULong value) { + public void setExpectedelements(ULong value) { set(1, value); } /** - * Getter for bloomdb.filter_expected_100000_fpp_001.partition_id. + * Getter for bloomdb.filtertype.expectedElements. */ - public ULong getPartitionId() { + public ULong getExpectedelements() { return (ULong) get(1); } /** - * Setter for bloomdb.filter_expected_100000_fpp_001.filter. + * Setter for bloomdb.filtertype.targetFpp. */ - public void setFilter(byte... value) { + public void setTargetfpp(Double value) { set(2, value); } /** - * Getter for bloomdb.filter_expected_100000_fpp_001.filter. + * Getter for bloomdb.filtertype.targetFpp. */ - public byte[] getFilter() { - return (byte[]) get(2); + public Double getTargetfpp() { + return (Double) get(2); + } + + /** + * Setter for bloomdb.filtertype.pattern. + */ + public void setPattern(String value) { + set(3, value); + } + + /** + * Getter for bloomdb.filtertype.pattern. + */ + public String getPattern() { + return (String) get(3); } // ------------------------------------------------------------------------- @@ -123,92 +137,114 @@ public byte[] getFilter() { // ------------------------------------------------------------------------- @Override - public Record1 key() { + public Record1 key() { return (Record1) super.key(); } // ------------------------------------------------------------------------- - // Record3 type implementation + // Record4 type implementation // ------------------------------------------------------------------------- @Override - public Row3 fieldsRow() { - return (Row3) super.fieldsRow(); + public Row4 fieldsRow() { + return (Row4) super.fieldsRow(); } @Override - public Row3 valuesRow() { - return (Row3) super.valuesRow(); + public Row4 valuesRow() { + return (Row4) super.valuesRow(); } @Override - public Field field1() { - return FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.ID; + public Field field1() { + return Filtertype.FILTERTYPE.ID; } @Override public Field field2() { - return FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.PARTITION_ID; + return Filtertype.FILTERTYPE.EXPECTEDELEMENTS; + } + + @Override + public Field field3() { + return Filtertype.FILTERTYPE.TARGETFPP; } @Override - public Field field3() { - return FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001.FILTER; + public Field field4() { + return Filtertype.FILTERTYPE.PATTERN; } @Override - public Integer component1() { + public ULong component1() { return getId(); } @Override public ULong component2() { - return getPartitionId(); + return getExpectedelements(); } @Override - public byte[] component3() { - return getFilter(); + public Double component3() { + return getTargetfpp(); } @Override - public Integer value1() { + public String component4() { + return getPattern(); + } + + @Override + public ULong value1() { return getId(); } @Override public ULong value2() { - return getPartitionId(); + return getExpectedelements(); + } + + @Override + public Double value3() { + return getTargetfpp(); } @Override - public byte[] value3() { - return getFilter(); + public String value4() { + return getPattern(); } @Override - public FilterExpected_100000Fpp_001Record value1(Integer value) { + public FiltertypeRecord value1(ULong value) { setId(value); return this; } @Override - public FilterExpected_100000Fpp_001Record value2(ULong value) { - setPartitionId(value); + public FiltertypeRecord value2(ULong value) { + setExpectedelements(value); + return this; + } + + @Override + public FiltertypeRecord value3(Double value) { + setTargetfpp(value); return this; } @Override - public FilterExpected_100000Fpp_001Record value3(byte... value) { - setFilter(value); + public FiltertypeRecord value4(String value) { + setPattern(value); return this; } @Override - public FilterExpected_100000Fpp_001Record values(Integer value1, ULong value2, byte[] value3) { + public FiltertypeRecord values(ULong value1, ULong value2, Double value3, String value4) { value1(value1); value2(value2); value3(value3); + value4(value4); return this; } @@ -217,20 +253,21 @@ public FilterExpected_100000Fpp_001Record values(Integer value1, ULong value2, b // ------------------------------------------------------------------------- /** - * Create a detached FilterExpected_100000Fpp_001Record + * Create a detached FiltertypeRecord */ - public FilterExpected_100000Fpp_001Record() { - super(FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001); + public FiltertypeRecord() { + super(Filtertype.FILTERTYPE); } /** - * Create a detached, initialised FilterExpected_100000Fpp_001Record + * Create a detached, initialised FiltertypeRecord */ - public FilterExpected_100000Fpp_001Record(Integer id, ULong partitionId, byte[] filter) { - super(FilterExpected_100000Fpp_001.FILTER_EXPECTED_100000_FPP_001); + public FiltertypeRecord(ULong id, ULong expectedelements, Double targetfpp, String pattern) { + super(Filtertype.FILTERTYPE); set(0, id); - set(1, partitionId); - set(2, filter); + set(1, expectedelements); + set(2, targetfpp); + set(3, pattern); } } diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java index c3a7aee0..0042fe65 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java index fc6582ca..8e9d4029 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java index 74db3c37..a6654596 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java index 90829a5b..77b2593b 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java index 8de40279..67652d22 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java index 53ae48ad..46fc699a 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java index 7aa46c88..0fd87e38 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java index 2d72a131..b1fa088a 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java index 1e37966c..e9efbefd 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java index b2e2f77f..270335b3 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java index 44391acb..6f0b8201 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java index bd2d747b..a8808aba 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java index fb07c2be..b493c970 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java index 4ba60cf2..8dbff9ae 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java index 58a611fb..7b815983 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java index ab3213a8..5aad7f38 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java index f9a80368..ac92e891 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java index e54a35b3..990f64b0 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java index 0919473a..2626c7e6 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java index 6b32b10d..5d0f8d46 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java @@ -1,6 +1,6 @@ /* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * This program handles user requests that require archive access. + * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java b/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java new file mode 100644 index 00000000..c38a1c87 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java @@ -0,0 +1,236 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.blf_01.Token; +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.*; +import org.jooq.impl.DSL; +import org.jooq.types.ULong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Set; + +import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; +import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; + +/** + * Class to represent a SQL Temp. Filled with bloom filters of all the parent tables records filter types. Search term + * token set parameter is inserted into each filter. Used to generate bloommatch condition that compares this filter + * column against parent table filter column row by row using bloommatch UDF. + *

+ * Parent Table Schema: + *

    + *
  1. id PK
  2. + *
  3. partition_id FK journaldb.logfile.id
  4. + *
  5. filter_type_id FK bloomdb.filtertype.id
  6. + *
  7. filter - bloomfilter byte array
  8. + *
+ *

+ * Temp Table Schema: + *

    + *
  1. id PK
  2. + *
  3. termId - count of the current search term
  4. + *
  5. typeId FK bloomdb.filtertype.id
  6. + *
  7. filter - bloomfilter bytes with only the search term token set inserted
  8. + *
+ * Parent table create table example: + *

+ * + * CREATE TABLE `example` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `partition_id` bigint(20) unsigned NOT NULL, `filter_type_id` bigint(20) unsigned NOT NULL, `filter` longblob NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `partition_id` (`partition_id`), KEY `example_ibfk_1` (`filter_type_id`), CONSTRAINT `example_ibfk_1` FOREIGN KEY (`filter_type_id`) REFERENCES `filtertype` (`id`) ON DELETE CASCADE, CONSTRAINT `example_ibfk_2` FOREIGN KEY (`partition_id`) REFERENCES `journaldb`.`logfile` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=54787 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + * + * + * @see com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb + */ +public final class BloomFilterTempTable { + + private static final Logger LOGGER = LoggerFactory.getLogger(BloomFilterTempTable.class); + + private final DSLContext ctx; + private final Table parentTable; + private final long bloomTermId; + private final Set tokenSet; + + public BloomFilterTempTable(DSLContext ctx, Table parentTable, long bloomTermId, Set tokenSet) { + this.ctx = ctx; + this.parentTable = parentTable; + this.bloomTermId = bloomTermId; + this.tokenSet = tokenSet; + } + + private void create() { + final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Creating temporary table <{}>", table.getName()); + } + ctx.dropTemporaryTableIfExists(table).execute(); + final String sql = "create temporary table " + table.getName() + + "(id bigint auto_increment primary key, term_id bigint, type_id bigint, filter longblob, unique key " + + table.getName() + "_unique_key (term_id, type_id))"; + final Query createQuery = ctx.query(sql); + createQuery.execute(); + final Index typeIndex = DSL.index(DSL.name(table.getName() + "_ix_type_id")); + final CreateIndexIncludeStep indexStep = ctx + .createIndex(typeIndex) + .on(table, DSL.field("type_id", BIGINTUNSIGNED.nullable(false))); + LOGGER.trace("BloomFilterTempTable create index <{}>", indexStep); + indexStep.execute(); + } + + /** + * Inserts a filter for each filtertype inside parent table records. Filter is filled with search term token set, + * filter size is selected using parent table filtertype expected and fpp values. + */ + private void insertFilters() { + final Table joined = parentTable + .join(BLOOMDB.FILTERTYPE) + .on(BLOOMDB.FILTERTYPE.ID.eq((Field) parentTable.field("filter_type_id"))); + final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); + final Field expectedField = DSL.field(DSL.name(table.getName(), "expectedElements"), ULong.class); + final Field fppField = DSL.field(DSL.name(table.getName(), "targetFpp"), Double.class); + final SelectField[] resultFields = { + BLOOMDB.FILTERTYPE.ID, + joined.field("expectedElements").as(expectedField), + joined.field("targetFpp").as(fppField) + }; + // Fetch filtertype values + final Result records = ctx + .select(resultFields) + .from(joined) + .groupBy(joined.field("filter_type_id")) + .fetch(); + if (records.isEmpty()) { + throw new RuntimeException("Parent table was empty"); + } + for (Record record : records) { + insertFilterFromRecord(record, expectedField, fppField); + } + } + + private void insertFilterFromRecord( + final Record record, + final Field expectedField, + final Field fppField + ) { + final ULong filterTypeId = record.getValue(BLOOMDB.FILTERTYPE.ID); // filter_type_id + final ULong expected = record.getValue(expectedField); // expectedElements + final Double fpp = record.getValue(fppField); // targetFpp + final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); + tokenSet.forEach(token -> filter.put(token.toString())); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + try { + filter.writeTo(filterBAOS); + filterBAOS.close(); + } + catch (IOException e) { + throw new UncheckedIOException(new IOException("Error writing filter bytes: " + e.getMessage())); + } + final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); + final Field[] insertFields = { + DSL.field("term_id", BIGINTUNSIGNED.nullable(false)), + DSL.field("type_id", BIGINTUNSIGNED.nullable(false)), + DSL.field(DSL.name(table.getName(), "filter"), byte[].class) + }; + ctx + .insertInto(table) + .columns(insertFields) + .values(DSL.val(bloomTermId, ULong.class), DSL.val(filterTypeId, ULong.class), DSL.val(filterBAOS.toByteArray(), byte[].class)).execute(); + } + + /** + * Generates a condition that returns true if this temp tables search term tokens might be contained in the parent + * table or parent table bloom filter is null. Selects to same sized filter from the temp table for each parent + * table row. + *

+ * expects the user defined function 'bloommatch' to be present to compare filter bytes. expects the parent table to + * be joined in the query that uses the generated Condition. + * + * @return Condition - generated condition + */ + public Condition generateCondition() { + create(); + insertFilters(); + final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); + final Field termIdField = DSL.field("term_id", BIGINTUNSIGNED.nullable(false)); + final Field typeIdField = DSL.field("type_id", BIGINTUNSIGNED.nullable(false)); + final Field filterField = DSL.field(DSL.name(table.getName(), "filter"), byte[].class); + final SelectConditionStep> selectFilterStep = DSL + .select(filterField) + .from(table) + .where(termIdField.eq(ULong.valueOf(bloomTermId))) + .and(typeIdField.eq((Field) parentTable.field("filter_type_id"))); + final Field filterColumn = selectFilterStep.asField(); + final Condition filterFieldCondition = DSL + .function("bloommatch", Boolean.class, filterColumn, parentTable.field("filter")) + .eq(true); + // null check allows SQL to optimize query + final Condition notNullCondition = parentTable.field("filter").isNotNull(); + return filterFieldCondition.and(notNullCondition); + } + + /** + * Equal only if all object parameters are same value and the instances of DSLContext are same + * + * @param object object compared against + * @return true if all object is same class, object fields are equal and DSLContext is same instance + */ + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final BloomFilterTempTable cast = (BloomFilterTempTable) object; + return this.parentTable.equals(cast.parentTable) && this.ctx == cast.ctx && // equal only if same instance of DSLContext + this.bloomTermId == cast.bloomTermId && this.tokenSet.equals(cast.tokenSet); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/PatternMatch.java b/src/main/java/com/teragrep/pth_06/planner/PatternMatch.java new file mode 100644 index 00000000..0337a95c --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/PatternMatch.java @@ -0,0 +1,137 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.blf_01.Token; +import com.teragrep.blf_01.Tokenizer; + +import org.jooq.Condition; +import org.jooq.DSLContext; +import org.jooq.Field; +import org.jooq.Table; +import org.jooq.impl.DSL; +import org.jooq.types.ULong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; + +public class PatternMatch { + + private static final Logger LOGGER = LoggerFactory.getLogger(PatternMatch.class); + + private final DSLContext ctx; + private final String input; + + public PatternMatch(DSLContext ctx, String input) { + this.ctx = ctx; + this.input = input; + } + + /** + * Finds all non-empty Tables from bloomdb that are not filtertype and that match regex condition from token set + * Note: Table records are not fetched fully + * + * @return List of tables that matched condition and were not empty + */ + public List> toList() { + final Set tokenSet = tokenSet(); + Condition patternCondition = DSL.noCondition(); + // tokens = ['one, 'two'] -> ('one' regex like BLOOMDB.FILTERTYPE.PATTERN).or('two' regex like BLOOMDB.FILTERTYPE.PATTERN) + for (Token token : tokenSet) { + Field tokenStringField = DSL.val(token.toString()); + patternCondition = patternCondition.or(tokenStringField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN)); + } + final Condition finalPatternCondition = patternCondition; + // SQL metadata + final List> tables = ctx + .meta() + .filterSchemas(s -> s.equals(BLOOMDB)) // select bloomdb + .filterTables(t -> !t.equals(BLOOMDB.FILTERTYPE)) // remove filtertype table + .filterTables(t -> ctx.select((Field) t.field("id"))// for each remaining table + .from(t) + .leftJoin(BLOOMDB.FILTERTYPE)// join filtertype to access patterns + .on(BLOOMDB.FILTERTYPE.ID.eq((Field) t.field("filter_type_id"))) + .where(finalPatternCondition)// select tables that match pattern condition + .limit(1)// limit 1 since we are checking only if table is not empty + .fetch() + .isNotEmpty() // select table if not empty + ) + .getTables(); + LOGGER.debug("Table(s) with a pattern match <{}>", tables); + return tables; + } + + public Set tokenSet() { + return new HashSet<>( + new Tokenizer(0).tokenize(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))) + ); + } + + /** + * Equal only if all values are equal and same instance of DSLContext + * + * @param object object compared against + * @return true if all object is same class, object fields are equal and DSLContext is same instance + */ + @Override + public boolean equals(Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final PatternMatch cast = (PatternMatch) object; + return this.input.equals(cast.input) && this.ctx == cast.ctx; // only same instance of DSLContext is equal + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java b/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java index c3b880d0..e733ca25 100644 --- a/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java +++ b/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java @@ -45,16 +45,12 @@ */ package com.teragrep.pth_06.planner; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UncheckedIOException; import java.sql.*; import java.time.Instant; +import java.util.Set; import com.teragrep.pth_06.config.Config; -import com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb; import com.teragrep.pth_06.planner.walker.ConditionWalker; -import org.apache.spark.util.sketch.BloomFilter; import org.jooq.*; import org.jooq.conf.MappedSchema; import org.jooq.conf.RenderMapping; @@ -70,7 +66,6 @@ import static com.teragrep.pth_06.jooq.generated.journaldb.Journaldb.JOURNALDB; import static org.jooq.impl.DSL.select; -import static org.jooq.impl.SQLDataType.BIGINT; // https://stackoverflow.com/questions/33657391/qualifying-a-temporary-table-column-name-in-jooq // https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql/ @@ -96,6 +91,7 @@ public class StreamDBClient { private long includeBeforeEpoch; private final boolean bloomEnabled; private final Condition journaldbCondition; + private final ConditionWalker walker; public StreamDBClient(Config config) throws SQLException { @@ -128,10 +124,7 @@ public StreamDBClient(Config config) throws SQLException { ctx.execute("SET sql_mode = 'NO_ENGINE_SUBSTITUTION';"); } // -- TODO use dslContext.batch for all initial operations - BloomFiltersTempTable.create(ctx); - - final ConditionWalker walker = new ConditionWalker(ctx, bloomEnabled); - + this.walker = new ConditionWalker(ctx, bloomEnabled); Condition streamdbCondition; try { @@ -154,7 +147,7 @@ void setIncludeBeforeEpoch(long includeBeforeEpoch) { this.includeBeforeEpoch = includeBeforeEpoch; } - int pullToSliceTable(Date day) { + public int pullToSliceTable(Date day) { NestedTopNQuery nestedTopNQuery = new NestedTopNQuery(); SelectOnConditionStep> select = ctx .select( @@ -263,76 +256,6 @@ private static void create(DSLContext ctx) { } - // TODO WIP - public static class BloomFiltersTempTable { - - public static final String bloomTable = "bloomFiltersTable"; - public static final Table BLOOM_TABLE = DSL.table(DSL.name(bloomTable)); - - public static final Field id = DSL.field("id", BIGINT.identity(true)); - public static final Field fe100kfp001 = DSL.field(DSL.name(bloomTable, "fe100kfp001"), byte[].class); - public static final Field fe1000kfpp003 = DSL - .field(DSL.name(bloomTable, "fe1000kfpp003"), byte[].class); - public static final Field fe2500kfpp005 = DSL - .field(DSL.name(bloomTable, "fe2500kfpp005"), byte[].class); - - private static void create(DSLContext ctx) { - - DropTableStep dropQuery = ctx.dropTemporaryTableIfExists(BloomFiltersTempTable.BLOOM_TABLE); - dropQuery.execute(); - - Query query = ctx - .query( - "create temporary table bloomFiltersTable(id bigint auto_increment primary key, fe100kfp001 longblob, fe1000kfpp003 longblob, fe2500kfpp005 longblob)" - ); - - /*CreateTableConstraintStep query = ctx.createTemporaryTable(BloomFiltersTempTable.BLOOM_TABLE) - .columns( - id, - fe100kfp001, - fe1000kfpp003, - fe2500kfpp005) - .constraints(primaryKey(id)); - - */ - query.execute(); - - } - - public static long insert( - DSLContext ctx, - BloomFilter smallFilter, - BloomFilter mediumFilter, - BloomFilter largeFilter - ) { - - final ByteArrayOutputStream smallBaos = new ByteArrayOutputStream(); - final ByteArrayOutputStream mediumBaos = new ByteArrayOutputStream(); - final ByteArrayOutputStream largeBaos = new ByteArrayOutputStream(); - - try { - smallFilter.writeTo(smallBaos); - mediumFilter.writeTo(mediumBaos); - largeFilter.writeTo(largeBaos); - - smallBaos.close(); - mediumBaos.close(); - largeBaos.close(); - } - catch (IOException e) { - throw new UncheckedIOException(e); - } - - ctx - .insertInto(BLOOM_TABLE) - .columns(fe100kfp001, fe1000kfpp003, fe2500kfpp005) - .values(DSL.val(smallBaos.toByteArray(), byte[].class), DSL.val(mediumBaos.toByteArray(), byte[].class), DSL.val(largeBaos.toByteArray(), byte[].class)).execute(); - - long rv = ctx.lastID().longValue(); - return rv; - } - } - public static class GetArchivedObjectsFilterTable { // temporary table created from streamdb @@ -420,15 +343,17 @@ private Table getTableStatement(Condition journaldbCondition, Date day) .on(JOURNALDB.LOGFILE.HOST_ID.eq(GetArchivedObjectsFilterTable.host_id).and(JOURNALDB.LOGFILE.LOGTAG.eq(GetArchivedObjectsFilterTable.tag))); if (bloomEnabled) { - - selectOnConditionStep = selectOnConditionStep - .leftJoin(Bloomdb.BLOOMDB.FILTER_EXPECTED_100000_FPP_001) - .on(JOURNALDB.LOGFILE.ID.eq(Bloomdb.BLOOMDB.FILTER_EXPECTED_100000_FPP_001.PARTITION_ID)) - .leftJoin(Bloomdb.BLOOMDB.FILTER_EXPECTED_1000000_FPP_003) - .on(JOURNALDB.LOGFILE.ID.eq(Bloomdb.BLOOMDB.FILTER_EXPECTED_1000000_FPP_003.PARTITION_ID)) - .leftJoin(Bloomdb.BLOOMDB.FILTER_EXPECTED_2500000_FPP_005) - .on(JOURNALDB.LOGFILE.ID.eq(Bloomdb.BLOOMDB.FILTER_EXPECTED_2500000_FPP_005.PARTITION_ID)); - + Set> tables = walker.patternMatchTables(); + if (!tables.isEmpty()) { + for (Table table : tables) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Left join pattern match table: <{}>", table.getName()); + } + selectOnConditionStep = selectOnConditionStep + .leftJoin(table) + .on(JOURNALDB.LOGFILE.ID.eq((Field) table.field("partition_id"))); + } + } } return selectOnConditionStep diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java index 2635ac79..881595d3 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java @@ -47,19 +47,24 @@ import com.teragrep.pth_06.config.ConditionConfig; import com.teragrep.pth_06.planner.walker.conditions.ElementCondition; +import com.teragrep.pth_06.planner.walker.conditions.ValidElement; import org.jooq.Condition; import org.jooq.DSLContext; +import org.jooq.Table; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; +import java.util.HashSet; +import java.util.Set; + /** *

Condition Walker

Walker for conditions. * - * @since 23/09/2021 * @author Kimmo Leppinen * @author Mikko Kortelainen * @author Ville Manninen + * @since 23/09/2021 */ public class ConditionWalker extends XmlWalker { @@ -68,20 +73,21 @@ public class ConditionWalker extends XmlWalker { // Default query is full private boolean streamQuery = false; private final DSLContext ctx; + private final Set> patternMatchSet; + private long bloomTermId = 0; /** * Constructor without connection. Used during unit-tests. Enables jooq-query construction. */ public ConditionWalker() { - super(); - this.ctx = null; - this.bloomEnabled = false; + this(null, false); } public ConditionWalker(DSLContext ctx, boolean bloomEnabled) { super(); this.ctx = ctx; this.bloomEnabled = bloomEnabled; + this.patternMatchSet = new HashSet<>(); } public Condition fromString(String inXml, boolean streamQuery) throws Exception { @@ -89,6 +95,15 @@ public Condition fromString(String inXml, boolean streamQuery) throws Exception return fromString(inXml); } + /** + * Set of all the tables that pattern matched with tokenized search terms the walkers has visited + * + * @return Set of Tables that had a pattern match + */ + public Set> patternMatchTables() { + return patternMatchSet; + } + @Override public Condition emitLogicalOperation(String op, Object l, Object r) throws Exception { Condition rv; @@ -138,11 +153,16 @@ public Condition emitUnaryOperation(String op, Element current) throws Exception return rv; } - Condition emitElem(Element current) { - ElementCondition elementCondition = new ElementCondition( - current, - new ConditionConfig(ctx, streamQuery, bloomEnabled, false) + Condition emitElem(final Element current) { + final ElementCondition elementCondition = new ElementCondition( + new ValidElement(current), + new ConditionConfig(ctx, streamQuery, bloomEnabled), + bloomTermId ); + if (elementCondition.isIndexStatement()) { + patternMatchTables().addAll(elementCondition.matchSet()); + bloomTermId++; + } return elementCondition.condition(); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index be7d0033..d311aea8 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -48,11 +48,16 @@ import com.teragrep.blf_01.Tokenizer; import com.teragrep.pth_06.config.ConditionConfig; import org.jooq.Condition; +import org.jooq.Table; import org.jooq.impl.DSL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * Creates a query condition from provided dom element */ @@ -60,35 +65,26 @@ public final class ElementCondition { private static final Logger LOGGER = LoggerFactory.getLogger(ElementCondition.class); - private final Element element; + private final ValidElement element; private final ConditionConfig config; + private final long bloomTermId; + private final Set> tableSet; public ElementCondition(Element element, ConditionConfig config) { - this.element = element; - this.config = config; + this(new ValidElement(element), config, 0L); } - private void validate(Element element) { - if (element.getTagName() == null) { - throw new IllegalStateException("Tag name for Element was null"); - } - if (!element.hasAttribute("operation")) { - throw new IllegalStateException( - "Could not find specified or default value for 'operation' attribute from Element" - ); - } - if (!element.hasAttribute("value")) { - throw new IllegalStateException( - "Could not find specified or default value for 'value' attribute from Element" - ); - } + public ElementCondition(ValidElement element, ConditionConfig config, long bloomTermId) { + this.element = element; + this.config = config; + this.bloomTermId = bloomTermId; + this.tableSet = new HashSet<>(); } public Condition condition() { - validate(element); - final String tag = element.getTagName(); - final String value = element.getAttribute("value"); - final String operation = element.getAttribute("operation"); + final String tag = element.tag(); + final String value = element.value(); + final String operation = element.operation(); Condition condition = DSL.noCondition(); switch (tag.toLowerCase()) { case "index": @@ -119,18 +115,37 @@ public Condition condition() { IndexStatementCondition indexStatementCondition = new IndexStatementCondition( value, config, - new Tokenizer(32) + new Tokenizer(0), + condition, + bloomTermId ); condition = indexStatementCondition.condition(); + List> newMatches = indexStatementCondition.matchList(); + if (!newMatches.isEmpty()) { + tableSet.addAll(newMatches); + } } } - if (condition.equals(DSL.noCondition())) { + // indexstatement can return condition unmodified + if (condition.equals(DSL.noCondition()) && !isIndexStatement()) { throw new IllegalStateException("Unsupported Element tag " + tag); } LOGGER.debug("Query condition: <{}>", condition); return condition; } + public boolean isIndexStatement() { + String tag = element.tag(); + return !config.streamQuery() && "indexstatement".equalsIgnoreCase(tag) && config.bloomEnabled(); + } + + public Set> matchSet() { + if (tableSet.isEmpty()) { + condition(); + } + return tableSet; + } + @Override public boolean equals(final Object object) { if (this == object) @@ -140,9 +155,6 @@ public boolean equals(final Object object) { if (object.getClass() != this.getClass()) return false; final ElementCondition cast = (ElementCondition) object; - boolean equalName = this.element.getTagName().equals(cast.element.getTagName()); - boolean equalOperation = this.element.getAttribute("operation").equals(cast.element.getAttribute("operation")); - boolean equalValue = this.element.getAttribute("value").equals(cast.element.getAttribute("value")); - return equalName && equalOperation && equalValue && this.config.equals(cast.config); + return this.element.equals(cast.element) && this.config.equals(cast.config); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index e48e4b49..f9205b4d 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -45,23 +45,18 @@ */ package com.teragrep.pth_06.planner.walker.conditions; -import com.teragrep.blf_01.Token; import com.teragrep.blf_01.Tokenizer; import com.teragrep.pth_06.config.ConditionConfig; -import com.teragrep.pth_06.planner.StreamDBClient; -import org.apache.spark.util.sketch.BloomFilter; +import com.teragrep.pth_06.planner.BloomFilterTempTable; +import com.teragrep.pth_06.planner.PatternMatch; import org.jooq.Condition; -import org.jooq.Field; +import org.jooq.Table; import org.jooq.impl.DSL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.HashSet; -import java.util.Set; - -import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; +import java.util.ArrayList; +import java.util.List; public final class IndexStatementCondition implements QueryCondition { @@ -70,71 +65,72 @@ public final class IndexStatementCondition implements QueryCondition { private final String value; private final ConditionConfig config; private final Tokenizer tokenizer; + private final Condition condition; + private final long bloomTermId; + private final List> tableList; + + public IndexStatementCondition(String value, ConditionConfig config) { + this(value, config, new Tokenizer(0), DSL.noCondition(), 0L); + } public IndexStatementCondition(String value, ConditionConfig config, Tokenizer tokenizer) { + this(value, config, tokenizer, DSL.noCondition(), 0L); + } + + public IndexStatementCondition(String value, ConditionConfig config, Tokenizer tokenizer, long bloomTermId) { + this(value, config, tokenizer, DSL.noCondition(), bloomTermId); + } + + public IndexStatementCondition( + String value, + ConditionConfig config, + Tokenizer tokenizer, + Condition condition, + long bloomTermId + ) { this.value = value; this.config = config; this.tokenizer = tokenizer; + this.condition = condition; + this.bloomTermId = bloomTermId; + this.tableList = new ArrayList<>(); } public Condition condition() { - final Set tokenSet = new HashSet<>( - tokenizer.tokenize(new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8))) - ); - - LOGGER.info("BloomFilter tokenSet <[{}]>", tokenSet); - - final BloomFilter smallFilter = BloomFilter.create(100000, 0.01); - final BloomFilter mediumFilter = BloomFilter.create(1000000, 0.03); - final BloomFilter largeFilter = BloomFilter.create(2500000, 0.05); - - tokenSet.forEach(token -> { - smallFilter.put(token.toString()); - mediumFilter.put(token.toString()); - largeFilter.put(token.toString()); - }); - - final long rowId = StreamDBClient.BloomFiltersTempTable - .insert(config.context(), smallFilter, mediumFilter, largeFilter); - - final Condition rowIdCondition = StreamDBClient.BloomFiltersTempTable.id.eq(rowId); - - final Field smallColumn = DSL - .select(StreamDBClient.BloomFiltersTempTable.fe100kfp001) - .from(StreamDBClient.BloomFiltersTempTable.BLOOM_TABLE) - .where(rowIdCondition) - .asField(); - final Field mediumColumn = DSL - .select(StreamDBClient.BloomFiltersTempTable.fe1000kfpp003) - .from(StreamDBClient.BloomFiltersTempTable.BLOOM_TABLE) - .where(rowIdCondition) - .asField(); - final Field largeColumn = DSL - .select(StreamDBClient.BloomFiltersTempTable.fe2500kfpp005) - .from(StreamDBClient.BloomFiltersTempTable.BLOOM_TABLE) - .where(rowIdCondition) - .asField(); - - final Field fe100kfp001 = DSL - .function("bloommatch", Boolean.class, smallColumn, BLOOMDB.FILTER_EXPECTED_100000_FPP_001.FILTER); - final Field fe1000kfpp003 = DSL - .function("bloommatch", Boolean.class, mediumColumn, BLOOMDB.FILTER_EXPECTED_1000000_FPP_003.FILTER); - final Field fe2500kfpp005 = DSL - .function("bloommatch", Boolean.class, largeColumn, BLOOMDB.FILTER_EXPECTED_2500000_FPP_005.FILTER); - - final Condition noBloomFilter = BLOOMDB.FILTER_EXPECTED_100000_FPP_001.FILTER - .isNull() - .and( - BLOOMDB.FILTER_EXPECTED_1000000_FPP_003.FILTER - .isNull() - .and(BLOOMDB.FILTER_EXPECTED_2500000_FPP_005.FILTER.isNull()) + Condition newCondition = condition; + LOGGER.info("indexstatement reached with search term <{}>", value); + PatternMatch patternMatch = new PatternMatch(config.context(), value); + if (tableList.isEmpty()) { + tableList.addAll(patternMatch.toList()); + } + if (!tableList.isEmpty()) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Found pattern match on <{}> table(s)", tableList.size()); + } + Condition bloomCondition = DSL.noCondition(); + Condition noBloomCondition = DSL.noCondition(); + + for (Table table : tableList) { + BloomFilterTempTable tempTable = new BloomFilterTempTable( + config.context(), + table, + bloomTermId, + patternMatch.tokenSet() ); - final Condition queryCondition = fe100kfp001 - .eq(true) - .or(fe1000kfpp003.eq(true).or(fe2500kfpp005.eq(true).or(noBloomFilter))); - LOGGER.trace("ConditionWalker.emitElement bloomCondition part <{}>", queryCondition); + Condition tableCondition = tempTable.generateCondition(); + bloomCondition = bloomCondition.or(tableCondition); + noBloomCondition = noBloomCondition.and(table.field("filter").isNull()); + } + newCondition = bloomCondition.or(noBloomCondition); + } + return newCondition; + } - return queryCondition; + public List> matchList() { + if (tableList.isEmpty()) { + condition(); + } + return tableList; } /** diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java new file mode 100644 index 00000000..31fa5384 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java @@ -0,0 +1,103 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner.walker.conditions; + +import org.w3c.dom.Element; + +public class ValidElement { + + private final Element element; + + private void validate() { + if (element.getTagName() == null) { + throw new IllegalStateException("Tag name for Element was null"); + } + if (!element.hasAttribute("operation")) { + throw new IllegalStateException( + "Could not find specified or default value for 'operation' attribute from Element" + ); + } + if (!element.hasAttribute("value")) { + throw new IllegalStateException( + "Could not find specified or default value for 'value' attribute from Element" + ); + } + } + + public ValidElement(Element element) { + this.element = element; + } + + public String tag() { + validate(); + return element.getTagName(); + } + + public String value() { + validate(); + return element.getAttribute("value"); + } + + public String operation() { + validate(); + return element.getAttribute("operation"); + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final ValidElement cast = (ValidElement) object; + boolean equalName = this.element.getTagName().equals(cast.element.getTagName()); + boolean equalOperation = this.element.getAttribute("operation").equals(cast.element.getAttribute("operation")); + boolean equalValue = this.element.getAttribute("value").equals(cast.element.getAttribute("value")); + return equalName && equalOperation && equalValue; + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java b/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java new file mode 100644 index 00000000..c21cf665 --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java @@ -0,0 +1,280 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.blf_01.Token; +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.Condition; +import org.jooq.DSLContext; +import org.jooq.Table; +import org.jooq.impl.DSL; +import org.junit.jupiter.api.*; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class BloomFilterTempTableTest { + + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + public void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + conn.prepareStatement(filtertype).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + }); + } + + @BeforeEach + void createTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS target").execute(); + String targetTable = "CREATE TABLE `target`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(targetTable).execute(); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS").execute(); //h2 clear database + conn.close(); + }); + } + + @Test + public void testEmptyParentTable() { + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); + BloomFilterTempTable tempTable = new BloomFilterTempTable(ctx, table, 0L, tokenSet); + RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::generateCondition); + Assertions.assertEquals("Parent table was empty", ex.getMessage()); + } + + @Test + public void testConditionGeneration() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); + BloomFilterTempTable tempTable = new BloomFilterTempTable(ctx, table, 0L, tokenSet); + Condition condition = tempTable.generateCondition(); + String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_0_target\".\"filter\"\n" + + " from \"term_0_target\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + " )\n" + " ),\n" + + " \"bloomdb\".\"target\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"target\".\"filter\" is not null\n" + ")"; + Assertions.assertEquals(e, condition.toString()); + } + + @Test + public void testBloomTerm() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); + BloomFilterTempTable tempTable = new BloomFilterTempTable(ctx, table, 1L, tokenSet); + Condition condition = tempTable.generateCondition(); + Assertions.assertTrue(condition.toString().contains("term_1_")); + } + + @Test + public void testEquality() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table target1 = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + Table target2 = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); + BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, target1, 1L, tokenSet); + BloomFilterTempTable table2 = new BloomFilterTempTable(ctx, target2, 1L, tokenSet); + Assertions.assertEquals(table1, table2); + Assertions.assertEquals(table2, table1); + } + + @Test + public void testDifferentTokenSetNotEquals() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + Set set1 = new PatternMatch(ctx, "one").tokenSet(); + Set set2 = new PatternMatch(ctx, "two").tokenSet(); + BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, table, 1L, set1); + BloomFilterTempTable table2 = new BloomFilterTempTable(ctx, table, 1L, set2); + Assertions.assertNotEquals(table1, table2); + Assertions.assertNotEquals(table2, table1); + } + + @Test + public void testDifferentBloomTermNotEquals() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + Set set = new PatternMatch(ctx, "one").tokenSet(); + BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, table, 0L, set); + BloomFilterTempTable table2 = new BloomFilterTempTable(ctx, table, 1L, set); + Assertions.assertNotEquals(table1, table2); + Assertions.assertNotEquals(table2, table1); + } + + @Test + public void testDifferentDSLContextNotEquals() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + DSLContext ctx2 = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + Set set = new PatternMatch(ctx, "one").tokenSet(); + BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, table, 0L, set); + BloomFilterTempTable table2 = new BloomFilterTempTable(ctx2, table, 0L, set); + Assertions.assertNotEquals(table1, table2); + Assertions.assertNotEquals(table2, table1); + } + + void fillTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `target` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, 1); + stmt.setInt(2, 1); + stmt.setBytes(3, filterBAOS.toByteArray()); + stmt.executeUpdate(); + }); + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java b/src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java new file mode 100644 index 00000000..2a7b61ab --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java @@ -0,0 +1,221 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.DSLContext; +import org.jooq.Named; +import org.jooq.Table; +import org.jooq.impl.DSL; +import org.junit.jupiter.api.*; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class PatternMatchTest { + + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS pattern_test_ip").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS pattern_test_ip255").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + String ip = "CREATE TABLE `pattern_test_ip`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + String ip255 = "CREATE TABLE `pattern_test_ip255`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(filtertype).execute(); + conn.prepareStatement(ip).execute(); + conn.prepareStatement(ip255).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + writeFilter("pattern_test_ip", 1); + writeFilter("pattern_test_ip255", 2); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS").execute(); //h2 clear database + conn.close(); + }); + } + + @Test + public void testSingleMatch() { + DSLContext ctx = DSL.using(conn); + String input = "192.168.1.1"; + PatternMatch patternMatch = new PatternMatch(ctx, input); + List> result = patternMatch.toList(); + Assertions.assertEquals(1, result.size()); + Assertions.assertEquals("pattern_test_ip", result.get(0).getName()); + } + + @Test + public void testSearchTermTokenizedMatch() { + DSLContext ctx = DSL.using(conn); + String input = "target_ip=192.168.1.1"; + PatternMatch patternMatch = new PatternMatch(ctx, input); + List> result = patternMatch.toList(); + Assertions.assertEquals(1, result.size()); + Assertions.assertEquals("pattern_test_ip", result.get(0).getName()); + } + + @Test + public void testMultipleMatch() { + DSLContext ctx = DSL.using(conn); + String input = "255.255.255.255"; + PatternMatch patternMatch = new PatternMatch(ctx, input); + List> result = patternMatch.toList(); + List> result2 = patternMatch.toList(); + List tableNames = result.stream().map(Named::getName).collect(Collectors.toList()); + Assertions.assertEquals(2, result.size()); + Assertions.assertEquals(2, result2.size()); + Assertions.assertTrue(tableNames.contains("pattern_test_ip")); + Assertions.assertTrue(tableNames.contains("pattern_test_ip255")); + } + + @Test + public void testNoMatch() { + DSLContext ctx = DSL.using(conn); + String input = "testinput"; + PatternMatch patternMatch = new PatternMatch(ctx, input); + List> result = patternMatch.toList(); + Assertions.assertTrue(result.isEmpty()); + } + + @Test + public void equalsTest() { + DSLContext ctx = DSL.using(conn); + String input = "testinput"; + PatternMatch eq1 = new PatternMatch(ctx, input); + PatternMatch eq2 = new PatternMatch(ctx, input); + Assertions.assertEquals(eq1, eq2); + Assertions.assertEquals(eq2, eq1); + } + + @Test + public void differentInputNotEqualsTest() { + DSLContext ctx = DSL.using(conn); + PatternMatch eq1 = new PatternMatch(ctx, "testinput"); + PatternMatch eq2 = new PatternMatch(ctx, "anotherinput"); + Assertions.assertNotEquals(eq1, eq2); + Assertions.assertNotEquals(eq2, eq1); + } + + @Test + public void differentDSLContextNotEqualsTest() { + DSLContext ctx1 = DSL.using(conn); + DSLContext ctx2 = DSL.using(conn); + PatternMatch eq1 = new PatternMatch(ctx1, "testinput"); + PatternMatch eq2 = new PatternMatch(ctx2, "testinput"); + Assertions.assertNotEquals(eq1, eq2); + Assertions.assertNotEquals(eq2, eq1); + } + + private void writeFilter(String tableName, int filterId) { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `" + tableName + "` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, 1); + stmt.setInt(2, filterId); + stmt.setBytes(3, filterBAOS.toByteArray()); + stmt.executeUpdate(); + }); + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java index e4c99561..145f5801 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java @@ -48,7 +48,6 @@ import com.teragrep.pth_06.config.ConditionConfig; import org.jooq.Condition; import org.jooq.DSLContext; -import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.impl.DSL; import org.jooq.tools.jdbc.MockConnection; import org.jooq.tools.jdbc.MockResult; @@ -64,7 +63,7 @@ class ElementConditionTest { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final Document document = Assertions.assertDoesNotThrow(() -> factory.newDocumentBuilder().newDocument()); final DSLContext mockCtx = DSL.using(new MockConnection(ctx -> new MockResult[0])); - final ConditionConfig config = new ConditionConfig(mockCtx, false, true, false); + final ConditionConfig config = new ConditionConfig(mockCtx, false, true); final ConditionConfig streamConfig = new ConditionConfig(mockCtx, true); @Test @@ -84,20 +83,6 @@ void testStreamTags() { Assertions.assertEquals(loops, streamTags.length); } - @Test - void testIndexStatement() { - Element element = document.createElement("indexstatement"); - element.setAttribute("value", "searchTerm"); - element.setAttribute("operation", "EQUALS"); - Element element2 = document.createElement("indexstatement"); - element2.setAttribute("value", "searchTerm"); - element2.setAttribute("operation", "NOT_EQUALS"); - Assertions - .assertThrows(SQLDialectNotSupportedException.class, new ElementCondition(element, config)::condition); - Assertions.assertThrows(IllegalStateException.class, new ElementCondition(element, streamConfig)::condition); - Assertions.assertThrows(IllegalStateException.class, new ElementCondition(element2, config)::condition); - } - @Test void testProvidedElementMissingValue() { Element element = document.createElement("test"); diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index 0773a437..d7bcf3a8 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -47,55 +47,181 @@ import com.teragrep.blf_01.Tokenizer; import com.teragrep.pth_06.config.ConditionConfig; +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.Condition; import org.jooq.DSLContext; -import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.impl.DSL; import org.jooq.tools.jdbc.MockConnection; import org.jooq.tools.jdbc.MockResult; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; -/** - * Requires database setup for full test - */ +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class IndexStatementConditionTest { - final ConditionConfig config = new ConditionConfig( + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final ConditionConfig mockConfig = new ConditionConfig( DSL.using(new MockConnection(ctx -> new MockResult[0])), false, - true, - false + true ); - final Tokenizer tokenizer = new Tokenizer(32); + final Tokenizer tokenizer = new Tokenizer(0); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS pattern_test_ip").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS pattern_test_ip255").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + String ip = "CREATE TABLE `pattern_test_ip`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + String ip255 = "CREATE TABLE `pattern_test_ip255`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(filtertype).execute(); + conn.prepareStatement(ip).execute(); + conn.prepareStatement(ip255).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + writeFilter("pattern_test_ip", 1); + writeFilter("pattern_test_ip255", 2); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS"); // h2 clear database + conn.close(); + }); + } @Test - void conditionTest() { - DSLContext ctx = DSL.using(new MockConnection(context -> new MockResult[0])); - // only tests that database access is tried as expected - Assertions - .assertThrows( - SQLDialectNotSupportedException.class, () -> new IndexStatementCondition( - "value", - new ConditionConfig(ctx, false, true, false), - tokenizer - ).condition() - ); + void noMatchesTest() { + DSLContext ctx = DSL.using(conn); + Condition e1 = DSL.falseCondition(); + Condition e2 = DSL.trueCondition(); + ConditionConfig config = new ConditionConfig(ctx, false, true); + IndexStatementCondition cond1 = new IndexStatementCondition("test", config, tokenizer, e1, 0L); + IndexStatementCondition cond2 = new IndexStatementCondition("test", config, tokenizer, e2, 1L); + Assertions.assertEquals(e1, cond1.condition()); + Assertions.assertEquals(e2, cond2.condition()); + Assertions.assertTrue(cond1.matchList().isEmpty()); + Assertions.assertTrue(cond2.matchList().isEmpty()); + } + + @Test + void oneMatchingTableTest() { + DSLContext ctx = DSL.using(conn); + ConditionConfig config = new ConditionConfig(ctx, false, true); + IndexStatementCondition cond = new IndexStatementCondition("192.168.1.1", config, tokenizer); + String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_0_pattern_test_ip\".\"filter\"\n" + " from \"term_0_pattern_test_ip\"\n" + + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + + " or \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + ")"; + Assertions.assertEquals(e, cond.condition().toString()); + Assertions.assertEquals(1, cond.matchList().size()); + } + + @Test + void twoMatchingTableTest() { + DSLContext ctx = DSL.using(conn); + ConditionConfig config = new ConditionConfig(ctx, false, true); + IndexStatementCondition cond = new IndexStatementCondition("255.255.255.255", config, tokenizer); + String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_0_pattern_test_ip\".\"filter\"\n" + " from \"term_0_pattern_test_ip\"\n" + + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + " or (\n" + + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip255\".\"filter\"\n" + + " from \"term_0_pattern_test_ip255\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip255\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip255\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is not null\n" + " )\n" + " or (\n" + + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + " )\n" + ")"; + Assertions.assertEquals(e, cond.condition().toString()); + Assertions.assertEquals(2, cond.matchList().size()); } @Test void equalsTest() { - IndexStatementCondition eq1 = new IndexStatementCondition("946677600", config, tokenizer); - IndexStatementCondition eq2 = new IndexStatementCondition("946677600", config, tokenizer); + IndexStatementCondition eq1 = new IndexStatementCondition("946677600", mockConfig, tokenizer); + IndexStatementCondition eq2 = new IndexStatementCondition("946677600", mockConfig, tokenizer); Assertions.assertEquals(eq1, eq2); Assertions.assertEquals(eq2, eq1); } @Test void notEqualsTest() { - IndexStatementCondition eq1 = new IndexStatementCondition("946677600", config, tokenizer); - IndexStatementCondition notEq = new IndexStatementCondition("1000", config, tokenizer); + IndexStatementCondition eq1 = new IndexStatementCondition("946677600", mockConfig, tokenizer); + IndexStatementCondition notEq = new IndexStatementCondition("1000", mockConfig, tokenizer); Assertions.assertNotEquals(eq1, notEq); Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, null); } + + private void writeFilter(String tableName, int filterId) { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `" + tableName + "` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, 1); + stmt.setInt(2, filterId); + stmt.setBytes(3, filterBAOS.toByteArray()); + stmt.executeUpdate(); + stmt.close(); + }); + } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java index 7937abc3..aa7eaa7c 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java @@ -71,12 +71,12 @@ void conditionUpdatedTest() { @Test void equalsTest() { - IndexCondition eq1 = new IndexCondition("946720800", "EQUALS", false); + LatestCondition eq1 = new LatestCondition("946720800"); eq1.condition(); - IndexCondition eq2 = new IndexCondition("946720800", "EQUALS", false); - IndexCondition eq3 = new IndexCondition("946720800", "EQUALS", true); + LatestCondition eq2 = new LatestCondition("946720800"); + LatestCondition eq3 = new LatestCondition("946720800"); eq3.condition(); - IndexCondition eq4 = new IndexCondition("946720800", "EQUALS", true); + LatestCondition eq4 = new LatestCondition("946720800"); Assertions.assertEquals(eq1, eq2); Assertions.assertEquals(eq2, eq1); Assertions.assertEquals(eq3, eq4); @@ -84,13 +84,10 @@ void equalsTest() { @Test void notEqualsTest() { - IndexCondition eq1 = new IndexCondition("946720800", "EQUALS", false); - IndexCondition notEq = new IndexCondition("1000", "EQUALS", false); - IndexCondition notEq2 = new IndexCondition("946720800", "EQUALS", true); + LatestCondition eq1 = new LatestCondition("946720800"); + LatestCondition notEq = new LatestCondition("1000"); Assertions.assertNotEquals(eq1, notEq); Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, null); - Assertions.assertNotEquals(eq1, notEq2); - Assertions.assertNotEquals(notEq, notEq2); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java index a6179093..87861168 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java @@ -73,12 +73,12 @@ void negationTest() { @Test void equalsTest() { - IndexCondition eq1 = new IndexCondition("946677600", "EQUALS", false); + SourceTypeCondition eq1 = new SourceTypeCondition("946677600", "EQUALS", false); eq1.condition(); - IndexCondition eq2 = new IndexCondition("946677600", "EQUALS", false); - IndexCondition eq3 = new IndexCondition("946677600", "EQUALS", true); + SourceTypeCondition eq2 = new SourceTypeCondition("946677600", "EQUALS", false); + SourceTypeCondition eq3 = new SourceTypeCondition("946677600", "EQUALS", true); eq3.condition(); - IndexCondition eq4 = new IndexCondition("946677600", "EQUALS", true); + SourceTypeCondition eq4 = new SourceTypeCondition("946677600", "EQUALS", true); Assertions.assertEquals(eq1, eq2); Assertions.assertEquals(eq2, eq1); Assertions.assertEquals(eq3, eq4); @@ -86,9 +86,9 @@ void equalsTest() { @Test void notEqualsTest() { - IndexCondition eq1 = new IndexCondition("946677600", "EQUALS", false); - IndexCondition notEq = new IndexCondition("1000", "EQUALS", false); - IndexCondition notEq2 = new IndexCondition("1000", "EQUALS", true); + SourceTypeCondition eq1 = new SourceTypeCondition("946677600", "EQUALS", false); + SourceTypeCondition notEq = new SourceTypeCondition("1000", "EQUALS", false); + SourceTypeCondition notEq2 = new SourceTypeCondition("1000", "EQUALS", true); Assertions.assertNotEquals(eq1, notEq); Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, null); diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java new file mode 100644 index 00000000..fcf7f31e --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java @@ -0,0 +1,127 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner.walker.conditions; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import javax.xml.parsers.DocumentBuilderFactory; + +class ValidElementTest { + + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + final Document document = Assertions.assertDoesNotThrow(() -> factory.newDocumentBuilder().newDocument()); + + @Test + void validTest() { + Element element = document.createElement("test"); + element.setAttribute("value", "value"); + element.setAttribute("operation", "operation"); + ValidElement valid = new ValidElement(element); + Assertions.assertDoesNotThrow(() -> { + Assertions.assertEquals("test", valid.tag()); + Assertions.assertEquals("value", valid.value()); + Assertions.assertEquals("operation", valid.operation()); + }); + } + + @Test + void missingValueTest() { + Element noValue = document.createElement("test"); + noValue.setAttribute("operation", "operation"); + ValidElement invalid1 = new ValidElement(noValue); + Assertions.assertThrows(RuntimeException.class, () -> Assertions.assertEquals("test", invalid1.tag())); + } + + @Test + void missingOperationTest() { + Element noValue = document.createElement("test"); + noValue.setAttribute("value", "value"); + ValidElement invalid1 = new ValidElement(noValue); + Assertions.assertThrows(RuntimeException.class, () -> Assertions.assertEquals("test", invalid1.tag())); + } + + @Test + void equalityTest() { + Element element = document.createElement("test"); + element.setAttribute("value", "value"); + element.setAttribute("operation", "operation"); + ValidElement eq1 = new ValidElement(element); + ValidElement eq2 = new ValidElement(element); + Assertions.assertEquals(eq1, eq2); + Assertions.assertEquals(eq2, eq1); + } + + @Test + void notEqualValueTest() { + Element element1 = document.createElement("test"); + element1.setAttribute("value", "value"); + element1.setAttribute("operation", "operation"); + Element element2 = document.createElement("test"); + element2.setAttribute("value", "notValue"); + element2.setAttribute("operation", "operation"); + ValidElement eq1 = new ValidElement(element1); + ValidElement eq2 = new ValidElement(element2); + Assertions.assertNotEquals(eq1, eq2); + Assertions.assertNotEquals(eq2, eq1); + } + + @Test + void notEqualOperationTest() { + Element element1 = document.createElement("test"); + element1.setAttribute("value", "value"); + element1.setAttribute("operation", "operation"); + Element element2 = document.createElement("test"); + element2.setAttribute("value", "value"); + element2.setAttribute("operation", "notOperation"); + ValidElement eq1 = new ValidElement(element1); + ValidElement eq2 = new ValidElement(element2); + Assertions.assertNotEquals(eq1, eq2); + Assertions.assertNotEquals(eq2, eq1); + } +} diff --git a/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java b/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java new file mode 100644 index 00000000..5473e3e7 --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java @@ -0,0 +1,274 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.walker; + +import com.teragrep.pth_06.planner.walker.ConditionWalker; +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.Condition; +import org.jooq.impl.DSL; +import org.junit.jupiter.api.*; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ConditionWalkerTest { + + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS pattern_test_ip").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS pattern_test_ip255").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + String ip = "CREATE TABLE `pattern_test_ip`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + String ip255 = "CREATE TABLE `pattern_test_ip255`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(filtertype).execute(); + conn.prepareStatement(ip).execute(); + conn.prepareStatement(ip255).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + writeFilter("pattern_test_ip", 1); + writeFilter("pattern_test_ip255", 2); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS").execute(); //h2 clear database + conn.close(); + }); + } + + @Test + void bloomNoMatchTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "\"getArchivedObjects_filter_table\".\"directory\" like 'haproxy'"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(0, walker.patternMatchTables().size()); + } + + @Test + void bloomNoMatchStreamQueryTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "\"streamdb\".\"stream\".\"directory\" like 'haproxy'"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, true)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(0, walker.patternMatchTables().size()); + } + + @Test + void singleTablePatternMatchStreamQueryTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "\"streamdb\".\"stream\".\"directory\" like 'haproxy'"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, true)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(0, walker.patternMatchTables().size()); + } + + @Test + void singleTablePatternMatchTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "(\n" + " \"getArchivedObjects_filter_table\".\"directory\" like 'haproxy'\n" + " and (\n" + + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_0_pattern_test_ip\".\"filter\"\n" + + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + + " or \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + " )\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(1, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + } + + @Test + void twoTablePatternMatchTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "(\n" + " \"getArchivedObjects_filter_table\".\"directory\" like 'haproxy'\n" + " and (\n" + + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_0_pattern_test_ip\".\"filter\"\n" + + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + " or (\n" + + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip255\".\"filter\"\n" + + " from \"term_0_pattern_test_ip255\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip255\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip255\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is not null\n" + " )\n" + " or (\n" + + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + " )\n" + " )\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(2, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip255"))); + } + + @Test + void multipleSearchTermTestOneMatchTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_1_pattern_test_ip\".\"filter\"\n" + " from \"term_1_pattern_test_ip\"\n" + + " where (\n" + " term_id = 1\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + + " or \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(1, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + } + + @Test + void multipleSearchTermTwoAndOneMatchTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); + String q = ""; + String e = "(\n" + " (\n" + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_0_pattern_test_ip\".\"filter\"\n" + + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + " or (\n" + + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip255\".\"filter\"\n" + + " from \"term_0_pattern_test_ip255\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip255\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip255\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is not null\n" + " )\n" + " or (\n" + + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + " )\n" + " )\n" + + " and (\n" + " (\n" + " bloommatch(\n" + " (\n" + + " select \"term_1_pattern_test_ip\".\"filter\"\n" + + " from \"term_1_pattern_test_ip\"\n" + " where (\n" + " term_id = 1\n" + + " and type_id = \"bloomdb\".\"pattern_test_ip\".\"filter_type_id\"\n" + " )\n" + + " ),\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + + " or \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + " )\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(2, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip255"))); + } + + private void writeFilter(String tableName, int filterId) { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `" + tableName + "` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, 1); + stmt.setInt(2, filterId); + stmt.setBytes(3, filterBAOS.toByteArray()); + stmt.executeUpdate(); + }); + } +} From d9730aeb912a527045f808f21d1351b6e749587e Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 10:59:38 +0300 Subject: [PATCH 02/20] run jooq generate with new settings and spotless --- .../com/teragrep/pth_06/jooq/generated/DefaultCatalog.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java | 6 +++--- .../pth_06/jooq/generated/bloomdb/tables/Filtertype.java | 6 +++--- .../generated/bloomdb/tables/records/FiltertypeRecord.java | 6 +++--- .../teragrep/pth_06/jooq/generated/journaldb/Indexes.java | 6 +++--- .../teragrep/pth_06/jooq/generated/journaldb/Journaldb.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/journaldb/Keys.java | 6 +++--- .../teragrep/pth_06/jooq/generated/journaldb/Tables.java | 6 +++--- .../pth_06/jooq/generated/journaldb/tables/Bucket.java | 6 +++--- .../pth_06/jooq/generated/journaldb/tables/Host.java | 6 +++--- .../pth_06/jooq/generated/journaldb/tables/Logfile.java | 6 +++--- .../generated/journaldb/tables/records/BucketRecord.java | 6 +++--- .../jooq/generated/journaldb/tables/records/HostRecord.java | 6 +++--- .../generated/journaldb/tables/records/LogfileRecord.java | 6 +++--- .../teragrep/pth_06/jooq/generated/streamdb/Indexes.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/streamdb/Keys.java | 6 +++--- .../teragrep/pth_06/jooq/generated/streamdb/Streamdb.java | 6 +++--- .../com/teragrep/pth_06/jooq/generated/streamdb/Tables.java | 6 +++--- .../pth_06/jooq/generated/streamdb/tables/Host.java | 6 +++--- .../pth_06/jooq/generated/streamdb/tables/LogGroup.java | 6 +++--- .../pth_06/jooq/generated/streamdb/tables/Stream.java | 6 +++--- .../jooq/generated/streamdb/tables/records/HostRecord.java | 6 +++--- .../generated/streamdb/tables/records/LogGroupRecord.java | 6 +++--- .../generated/streamdb/tables/records/StreamRecord.java | 6 +++--- 27 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java b/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java index c311b38b..2bbd4cbf 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/DefaultCatalog.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java index 1dd155d4..8905a5fb 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Bloomdb.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java index 3a795632..5decdcba 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Indexes.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java index 13f2b35a..52344ed8 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Keys.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java index 146d9e63..364c28c9 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/Tables.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java index c60c2332..f347f11a 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/Filtertype.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java index bd782920..494c5771 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/bloomdb/tables/records/FiltertypeRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java index 0042fe65..c3a7aee0 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Indexes.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java index 8e9d4029..fc6582ca 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Journaldb.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java index a6654596..74db3c37 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Keys.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java index 77b2593b..90829a5b 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/Tables.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java index 67652d22..8de40279 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Bucket.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java index 46fc699a..53ae48ad 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Host.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java index 0fd87e38..7aa46c88 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/Logfile.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java index b1fa088a..2d72a131 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/BucketRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java index e9efbefd..1e37966c 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/HostRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java index 270335b3..b2e2f77f 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/journaldb/tables/records/LogfileRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java index 6f0b8201..44391acb 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Indexes.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java index a8808aba..bd2d747b 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Keys.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java index b493c970..fb07c2be 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Streamdb.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java index 8dbff9ae..4ba60cf2 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/Tables.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java index 7b815983..58a611fb 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Host.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java index 5aad7f38..ab3213a8 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/LogGroup.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java index ac92e891..f9a80368 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/Stream.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java index 990f64b0..e54a35b3 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/HostRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java index 2626c7e6..0919473a 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/LogGroupRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 diff --git a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java index 5d0f8d46..6b32b10d 100644 --- a/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java +++ b/src/main/java/com/teragrep/pth_06/jooq/generated/streamdb/tables/records/StreamRecord.java @@ -1,6 +1,6 @@ /* - * This program handles user requests that require archive access. - * Copyright (C) 2022, 2023, 2024 Suomen Kanuuna Oy + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -13,7 +13,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . * * * Additional permission under GNU Affero General Public License version 3 From dd42e06af255cdf71bd1ee66f7f637b7dd5c8801 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 12:25:37 +0300 Subject: [PATCH 03/20] rename BloomFilterTempTable tokenSet to searchTermTokenSet --- .../teragrep/pth_06/planner/BloomFilterTempTable.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java b/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java index c38a1c87..4a5a46e4 100644 --- a/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java +++ b/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java @@ -96,13 +96,13 @@ public final class BloomFilterTempTable { private final DSLContext ctx; private final Table parentTable; private final long bloomTermId; - private final Set tokenSet; + private final Set searchTermTokenSet; - public BloomFilterTempTable(DSLContext ctx, Table parentTable, long bloomTermId, Set tokenSet) { + public BloomFilterTempTable(DSLContext ctx, Table parentTable, long bloomTermId, Set searchTermTokenSet) { this.ctx = ctx; this.parentTable = parentTable; this.bloomTermId = bloomTermId; - this.tokenSet = tokenSet; + this.searchTermTokenSet = searchTermTokenSet; } private void create() { @@ -163,7 +163,7 @@ private void insertFilterFromRecord( final ULong expected = record.getValue(expectedField); // expectedElements final Double fpp = record.getValue(fppField); // targetFpp final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); - tokenSet.forEach(token -> filter.put(token.toString())); + searchTermTokenSet.forEach(token -> filter.put(token.toString())); final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); try { filter.writeTo(filterBAOS); @@ -231,6 +231,6 @@ public boolean equals(final Object object) { return false; final BloomFilterTempTable cast = (BloomFilterTempTable) object; return this.parentTable.equals(cast.parentTable) && this.ctx == cast.ctx && // equal only if same instance of DSLContext - this.bloomTermId == cast.bloomTermId && this.tokenSet.equals(cast.tokenSet); + this.bloomTermId == cast.bloomTermId && this.searchTermTokenSet.equals(cast.searchTermTokenSet); } } From b2aaf03e468470ef7e9b6ea31e2e20bd5ac13e8b Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 12:29:23 +0300 Subject: [PATCH 04/20] make ConditionWalker and ValidElement classes final --- .../com/teragrep/pth_06/planner/walker/ConditionWalker.java | 2 +- .../teragrep/pth_06/planner/walker/conditions/ValidElement.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java index 881595d3..77e7a8da 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java @@ -66,7 +66,7 @@ * @author Ville Manninen * @since 23/09/2021 */ -public class ConditionWalker extends XmlWalker { +public final class ConditionWalker extends XmlWalker { private final boolean bloomEnabled; private final Logger LOGGER = LoggerFactory.getLogger(ConditionWalker.class); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java index 31fa5384..0ea44822 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ValidElement.java @@ -47,7 +47,7 @@ import org.w3c.dom.Element; -public class ValidElement { +public final class ValidElement { private final Element element; From c1ae260ca79babb76145df12fa7c519909e63b7e Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 12:48:04 +0300 Subject: [PATCH 05/20] rename method isIndexStatement to isBloomSearchCondition --- .../pth_06/planner/walker/ConditionWalker.java | 4 ++-- .../walker/conditions/ElementCondition.java | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java index 77e7a8da..3aa61f39 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java @@ -159,8 +159,8 @@ Condition emitElem(final Element current) { new ConditionConfig(ctx, streamQuery, bloomEnabled), bloomTermId ); - if (elementCondition.isIndexStatement()) { - patternMatchTables().addAll(elementCondition.matchSet()); + if (elementCondition.isBloomSearchCondition()) { + patternMatchTables().addAll(elementCondition.patternMatchTables()); bloomTermId++; } return elementCondition.condition(); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index d311aea8..38137fd6 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -126,20 +126,24 @@ public Condition condition() { } } } - // indexstatement can return condition unmodified - if (condition.equals(DSL.noCondition()) && !isIndexStatement()) { + // bloom search can return condition unmodified + if (condition.equals(DSL.noCondition()) && !isBloomSearchCondition()) { throw new IllegalStateException("Unsupported Element tag " + tag); } LOGGER.debug("Query condition: <{}>", condition); return condition; } - public boolean isIndexStatement() { - String tag = element.tag(); - return !config.streamQuery() && "indexstatement".equalsIgnoreCase(tag) && config.bloomEnabled(); + public boolean isBloomSearchCondition() { + final String tag = element.tag(); + final String operation = element.tag(); + return "indexstatement".equalsIgnoreCase(tag) && + "EQUALS".equals(operation) && + !config.streamQuery() && + config.bloomEnabled(); } - public Set> matchSet() { + public Set> patternMatchTables() { if (tableSet.isEmpty()) { condition(); } From 914ddff3d2e71fda3a6c584935c9f5b657aea6bd Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 13:05:33 +0300 Subject: [PATCH 06/20] add indexstatement with bad connection tests for ElementConditionTest and IndexStatementConditionTest and tests for isBloomSearchCondition method --- .../walker/conditions/ElementCondition.java | 2 +- .../conditions/ElementConditionTest.java | 30 +++++++++++++++++++ .../IndexStatementConditionTest.java | 9 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index 38137fd6..c9880b61 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -136,7 +136,7 @@ public Condition condition() { public boolean isBloomSearchCondition() { final String tag = element.tag(); - final String operation = element.tag(); + final String operation = element.operation(); return "indexstatement".equalsIgnoreCase(tag) && "EQUALS".equals(operation) && !config.streamQuery() && diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java index 145f5801..7ca1280d 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java @@ -48,6 +48,7 @@ import com.teragrep.pth_06.config.ConditionConfig; import org.jooq.Condition; import org.jooq.DSLContext; +import org.jooq.exception.DataAccessException; import org.jooq.impl.DSL; import org.jooq.tools.jdbc.MockConnection; import org.jooq.tools.jdbc.MockResult; @@ -103,6 +104,35 @@ void testProvidedElementMissingOperation() { Assertions.assertThrows(IllegalStateException.class, streamElementCondition::condition); } + @Test + void testIsIndexStatement() { + Element element = document.createElement("indexstatement"); + element.setAttribute("value", "searchTerm"); + element.setAttribute("operation", "EQUALS"); + Element element2 = document.createElement("index"); + element2.setAttribute("value", "searchTerm"); + element2.setAttribute("operation", "EQUALS"); + ElementCondition condition = new ElementCondition(element, config); + Assertions.assertTrue(condition.isBloomSearchCondition()); + element.setAttribute("operation", "NOT_EQUALS"); + ElementCondition condition2 = new ElementCondition(element, config); + Assertions.assertFalse(condition2.isBloomSearchCondition()); + ElementCondition condition3 = new ElementCondition(element, streamConfig); + Assertions.assertFalse(condition3.isBloomSearchCondition()); + ElementCondition condition4 = new ElementCondition(element2, streamConfig); + Assertions.assertFalse(condition4.isBloomSearchCondition()); + } + + @Test + void testIndexStatementWithBadConnection() { + Element element = document.createElement("indexstatement"); + element.setAttribute("value", "searchTerm"); + element.setAttribute("operation", "EQUALS"); + ElementCondition condition = new ElementCondition(element, config); + Assertions.assertTrue(condition.isBloomSearchCondition()); + Assertions.assertThrows(DataAccessException.class, condition::condition); + } + @Test void testTimeQualifiers() { String[] tags = { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index d7bcf3a8..55b0c5a1 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -50,6 +50,7 @@ import org.apache.spark.util.sketch.BloomFilter; import org.jooq.Condition; import org.jooq.DSLContext; +import org.jooq.exception.DataAccessException; import org.jooq.impl.DSL; import org.jooq.tools.jdbc.MockConnection; import org.jooq.tools.jdbc.MockResult; @@ -135,6 +136,14 @@ void tearDown() { }); } + @Test + void testConnectionException() { + DSLContext ctx = DSL.using(new MockConnection(c -> new MockResult[0])); + ConditionConfig config = new ConditionConfig(ctx, false); + IndexStatementCondition cond = new IndexStatementCondition("test", config, tokenizer, DSL.trueCondition(), 0L); + Assertions.assertThrows(DataAccessException.class, cond::condition); + } + @Test void noMatchesTest() { DSLContext ctx = DSL.using(conn); From 485b3464ee3e62c84e57ac8fd424f440b1d83248 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 13:21:55 +0300 Subject: [PATCH 07/20] apply spotless --- .../pth_06/planner/walker/conditions/ElementCondition.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index c9880b61..f4360e54 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -137,10 +137,8 @@ public Condition condition() { public boolean isBloomSearchCondition() { final String tag = element.tag(); final String operation = element.operation(); - return "indexstatement".equalsIgnoreCase(tag) && - "EQUALS".equals(operation) && - !config.streamQuery() && - config.bloomEnabled(); + return "indexstatement".equalsIgnoreCase(tag) && "EQUALS".equals(operation) && !config.streamQuery() + && config.bloomEnabled(); } public Set> patternMatchTables() { From b3435ad319e4c88dbf58080ad0fbdc184076d5d5 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Thu, 12 Sep 2024 15:24:05 +0300 Subject: [PATCH 08/20] add javadoc to tests that use Condition.toString for equality testing --- .../teragrep/pth_06/planner/BloomFilterTempTableTest.java | 5 +++++ .../planner/walker/conditions/EarliestConditionTest.java | 5 +++++ .../planner/walker/conditions/ElementConditionTest.java | 5 +++++ .../pth_06/planner/walker/conditions/HostConditionTest.java | 5 +++++ .../pth_06/planner/walker/conditions/IndexConditionTest.java | 5 +++++ .../walker/conditions/IndexStatementConditionTest.java | 5 +++++ .../planner/walker/conditions/LatestConditionTest.java | 5 +++++ .../planner/walker/conditions/SourceTypeConditionTest.java | 5 +++++ .../pth_06/planner/walker/conditions/ValidElementTest.java | 5 +++++ .../java/com/teragrep/pth_06/walker/ConditionWalkerTest.java | 5 +++++ 10 files changed, 50 insertions(+) diff --git a/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java b/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java index c21cf665..83226235 100644 --- a/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java @@ -62,6 +62,11 @@ import java.util.List; import java.util.Set; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class BloomFilterTempTableTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java index c21d8374..9dd3cc16 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java @@ -49,6 +49,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ public class EarliestConditionTest { @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java index 7ca1280d..4e9855cc 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java @@ -59,6 +59,11 @@ import javax.xml.parsers.DocumentBuilderFactory; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ class ElementConditionTest { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java index be77c9be..a4a5b8c4 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java @@ -49,6 +49,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ public class HostConditionTest { @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java index 734177de..48fa3df6 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java @@ -49,6 +49,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ public class IndexConditionTest { @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index 55b0c5a1..f6321b87 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -64,6 +64,11 @@ import java.util.Arrays; import java.util.List; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class IndexStatementConditionTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java index aa7eaa7c..f150da7e 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java @@ -49,6 +49,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ class LatestConditionTest { @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java index 87861168..eb6a2dc2 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java @@ -49,6 +49,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ class SourceTypeConditionTest { @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java index fcf7f31e..2c7fd787 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java @@ -52,6 +52,11 @@ import javax.xml.parsers.DocumentBuilderFactory; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ class ValidElementTest { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); diff --git a/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java b/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java index 5473e3e7..9d295004 100644 --- a/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java +++ b/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java @@ -59,6 +59,11 @@ import java.util.Arrays; import java.util.List; +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * @see org.jooq.QueryPart + */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class ConditionWalkerTest { From 2916cd6a5ea6c778ee619469abe6229938982b91 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Mon, 16 Sep 2024 15:28:15 +0300 Subject: [PATCH 09/20] refactoring iteration: multiple new classes and interfaces to simplify and ensure single responsibility for objects --- .../teragrep/pth_06/config/ArchiveConfig.java | 3 + .../pth_06/config/ConditionConfig.java | 35 ++- .../pth_06/planner/BloomFilterTempTable.java | 236 ------------------ .../pth_06/planner/CategoryTable.java | 57 +++++ .../pth_06/planner/CategoryTableImpl.java | 174 +++++++++++++ .../com/teragrep/pth_06/planner/Created.java | 76 ++++++ .../pth_06/planner/FiltersInserted.java | 76 ++++++ ...ternMatch.java => PatternMatchTables.java} | 56 ++--- .../pth_06/planner/StreamDBClient.java | 3 +- .../planner/TableFilterTypesFromMetadata.java | 107 ++++++++ .../teragrep/pth_06/planner/TableFilters.java | 154 ++++++++++++ .../teragrep/pth_06/planner/TableRecords.java | 54 ++++ .../pth_06/planner/TokenizedValue.java | 81 ++++++ .../planner/walker/ConditionWalker.java | 26 +- .../conditions/BloomQueryCondition.java | 60 +++++ .../conditions/CategoryTableCondition.java | 94 +++++++ .../walker/conditions/ElementCondition.java | 24 +- .../conditions/IndexStatementCondition.java | 93 +++---- .../conditions/PatternMatchCondition.java | 99 ++++++++ ...leTest.java => CategoryTableImplTest.java} | 95 ++++--- ...hTest.java => PatternMatchTablesTest.java} | 32 +-- ...ableFilterTypesFromMetadataResultTest.java | 236 ++++++++++++++++++ .../pth_06/planner/TableFiltersTest.java | 213 ++++++++++++++++ .../pth_06/planner/TokenizedValueTest.java | 88 +++++++ .../CategoryTableConditionTest.java | 228 +++++++++++++++++ .../conditions/EarliestConditionTest.java | 1 + .../conditions/ElementConditionTest.java | 37 +-- .../walker/conditions/HostConditionTest.java | 1 + .../walker/conditions/IndexConditionTest.java | 1 + .../IndexStatementConditionTest.java | 58 +++-- .../conditions/LatestConditionTest.java | 1 + .../conditions/PatternMatchConditionTest.java | 50 ++++ .../conditions/SourceTypeConditionTest.java | 1 + .../walker/conditions/ValidElementTest.java | 1 + .../pth_06/walker/ConditionWalkerTest.java | 56 +++++ 35 files changed, 2170 insertions(+), 437 deletions(-) delete mode 100644 src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/CategoryTable.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/Created.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java rename src/main/java/com/teragrep/pth_06/planner/{PatternMatch.java => PatternMatchTables.java} (73%) create mode 100644 src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/TableFilters.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/TableRecords.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java rename src/test/java/com/teragrep/pth_06/planner/{BloomFilterTempTableTest.java => CategoryTableImplTest.java} (76%) rename src/test/java/com/teragrep/pth_06/planner/{PatternMatchTest.java => PatternMatchTablesTest.java} (88%) create mode 100644 src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java create mode 100644 src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java diff --git a/src/main/java/com/teragrep/pth_06/config/ArchiveConfig.java b/src/main/java/com/teragrep/pth_06/config/ArchiveConfig.java index 71ae5fa5..6c5b4752 100644 --- a/src/main/java/com/teragrep/pth_06/config/ArchiveConfig.java +++ b/src/main/java/com/teragrep/pth_06/config/ArchiveConfig.java @@ -67,6 +67,7 @@ public final class ArchiveConfig { // bloom public final boolean bloomEnabled; + public final boolean withoutFilters; public final String bloomDbName; public final boolean isStub; @@ -79,6 +80,7 @@ public ArchiveConfig(Map opts) { dbPassword = getOrThrow(opts, "DBpassword"); dbUrl = getOrThrow(opts, "DBurl"); bloomEnabled = opts.getOrDefault("bloom.enabled", "false").equalsIgnoreCase("true"); + withoutFilters = opts.getOrDefault("bloom.enabled", "false").equalsIgnoreCase("true"); bloomDbName = opts.getOrDefault("DBbloomdbname", "bloomdb"); dbJournalDbName = opts.getOrDefault("DBjournaldbname", "journaldb"); @@ -108,6 +110,7 @@ public ArchiveConfig() { dbStreamDbName = ""; bloomEnabled = false; + withoutFilters = false; bloomDbName = ""; hideDatabaseExceptions = false; diff --git a/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java b/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java index abf11833..618eaeed 100644 --- a/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java +++ b/src/main/java/com/teragrep/pth_06/config/ConditionConfig.java @@ -52,15 +52,37 @@ public final class ConditionConfig { private final DSLContext ctx; private final boolean streamQuery; private final boolean bloomEnabled; + private final boolean withoutFilters; + private final long bloomTermId; public ConditionConfig(DSLContext ctx, boolean streamQuery) { - this(ctx, streamQuery, false); + this(ctx, streamQuery, false, false, 0L); } public ConditionConfig(DSLContext ctx, boolean streamQuery, boolean bloomEnabled) { + this(ctx, streamQuery, bloomEnabled, false, 0L); + } + + public ConditionConfig(DSLContext ctx, boolean streamQuery, boolean bloomEnabled, boolean withoutFilters) { + this(ctx, streamQuery, bloomEnabled, withoutFilters, 0L); + } + + public ConditionConfig(DSLContext ctx, boolean streamQuery, boolean bloomEnabled, long bloomTermId) { + this(ctx, streamQuery, bloomEnabled, false, bloomTermId); + } + + public ConditionConfig( + DSLContext ctx, + boolean streamQuery, + boolean bloomEnabled, + boolean withoutFilters, + long bloomTermId + ) { this.ctx = ctx; this.streamQuery = streamQuery; this.bloomEnabled = bloomEnabled; + this.withoutFilters = withoutFilters; + this.bloomTermId = bloomTermId; } public DSLContext context() { @@ -71,6 +93,14 @@ public boolean bloomEnabled() { return bloomEnabled; } + public boolean withoutFilters() { + return withoutFilters; + } + + public long bloomTermId() { + return bloomTermId; + } + public boolean streamQuery() { return streamQuery; } @@ -84,6 +114,7 @@ public boolean equals(Object object) { if (object.getClass() != this.getClass()) return false; final ConditionConfig cast = (ConditionConfig) object; - return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery && this.ctx == cast.ctx; + return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery + && this.withoutFilters == cast.withoutFilters && this.ctx == cast.ctx; } } diff --git a/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java b/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java deleted file mode 100644 index 4a5a46e4..00000000 --- a/src/main/java/com/teragrep/pth_06/planner/BloomFilterTempTable.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -package com.teragrep.pth_06.planner; - -import com.teragrep.blf_01.Token; -import org.apache.spark.util.sketch.BloomFilter; -import org.jooq.*; -import org.jooq.impl.DSL; -import org.jooq.types.ULong; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.Set; - -import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; -import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; - -/** - * Class to represent a SQL Temp. Filled with bloom filters of all the parent tables records filter types. Search term - * token set parameter is inserted into each filter. Used to generate bloommatch condition that compares this filter - * column against parent table filter column row by row using bloommatch UDF. - *

- * Parent Table Schema: - *

    - *
  1. id PK
  2. - *
  3. partition_id FK journaldb.logfile.id
  4. - *
  5. filter_type_id FK bloomdb.filtertype.id
  6. - *
  7. filter - bloomfilter byte array
  8. - *
- *

- * Temp Table Schema: - *

    - *
  1. id PK
  2. - *
  3. termId - count of the current search term
  4. - *
  5. typeId FK bloomdb.filtertype.id
  6. - *
  7. filter - bloomfilter bytes with only the search term token set inserted
  8. - *
- * Parent table create table example: - *

- * - * CREATE TABLE `example` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `partition_id` bigint(20) unsigned NOT NULL, `filter_type_id` bigint(20) unsigned NOT NULL, `filter` longblob NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `partition_id` (`partition_id`), KEY `example_ibfk_1` (`filter_type_id`), CONSTRAINT `example_ibfk_1` FOREIGN KEY (`filter_type_id`) REFERENCES `filtertype` (`id`) ON DELETE CASCADE, CONSTRAINT `example_ibfk_2` FOREIGN KEY (`partition_id`) REFERENCES `journaldb`.`logfile` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=54787 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci - * - * - * @see com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb - */ -public final class BloomFilterTempTable { - - private static final Logger LOGGER = LoggerFactory.getLogger(BloomFilterTempTable.class); - - private final DSLContext ctx; - private final Table parentTable; - private final long bloomTermId; - private final Set searchTermTokenSet; - - public BloomFilterTempTable(DSLContext ctx, Table parentTable, long bloomTermId, Set searchTermTokenSet) { - this.ctx = ctx; - this.parentTable = parentTable; - this.bloomTermId = bloomTermId; - this.searchTermTokenSet = searchTermTokenSet; - } - - private void create() { - final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); - if (LOGGER.isInfoEnabled()) { - LOGGER.info("Creating temporary table <{}>", table.getName()); - } - ctx.dropTemporaryTableIfExists(table).execute(); - final String sql = "create temporary table " + table.getName() - + "(id bigint auto_increment primary key, term_id bigint, type_id bigint, filter longblob, unique key " - + table.getName() + "_unique_key (term_id, type_id))"; - final Query createQuery = ctx.query(sql); - createQuery.execute(); - final Index typeIndex = DSL.index(DSL.name(table.getName() + "_ix_type_id")); - final CreateIndexIncludeStep indexStep = ctx - .createIndex(typeIndex) - .on(table, DSL.field("type_id", BIGINTUNSIGNED.nullable(false))); - LOGGER.trace("BloomFilterTempTable create index <{}>", indexStep); - indexStep.execute(); - } - - /** - * Inserts a filter for each filtertype inside parent table records. Filter is filled with search term token set, - * filter size is selected using parent table filtertype expected and fpp values. - */ - private void insertFilters() { - final Table joined = parentTable - .join(BLOOMDB.FILTERTYPE) - .on(BLOOMDB.FILTERTYPE.ID.eq((Field) parentTable.field("filter_type_id"))); - final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); - final Field expectedField = DSL.field(DSL.name(table.getName(), "expectedElements"), ULong.class); - final Field fppField = DSL.field(DSL.name(table.getName(), "targetFpp"), Double.class); - final SelectField[] resultFields = { - BLOOMDB.FILTERTYPE.ID, - joined.field("expectedElements").as(expectedField), - joined.field("targetFpp").as(fppField) - }; - // Fetch filtertype values - final Result records = ctx - .select(resultFields) - .from(joined) - .groupBy(joined.field("filter_type_id")) - .fetch(); - if (records.isEmpty()) { - throw new RuntimeException("Parent table was empty"); - } - for (Record record : records) { - insertFilterFromRecord(record, expectedField, fppField); - } - } - - private void insertFilterFromRecord( - final Record record, - final Field expectedField, - final Field fppField - ) { - final ULong filterTypeId = record.getValue(BLOOMDB.FILTERTYPE.ID); // filter_type_id - final ULong expected = record.getValue(expectedField); // expectedElements - final Double fpp = record.getValue(fppField); // targetFpp - final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); - searchTermTokenSet.forEach(token -> filter.put(token.toString())); - final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); - try { - filter.writeTo(filterBAOS); - filterBAOS.close(); - } - catch (IOException e) { - throw new UncheckedIOException(new IOException("Error writing filter bytes: " + e.getMessage())); - } - final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); - final Field[] insertFields = { - DSL.field("term_id", BIGINTUNSIGNED.nullable(false)), - DSL.field("type_id", BIGINTUNSIGNED.nullable(false)), - DSL.field(DSL.name(table.getName(), "filter"), byte[].class) - }; - ctx - .insertInto(table) - .columns(insertFields) - .values(DSL.val(bloomTermId, ULong.class), DSL.val(filterTypeId, ULong.class), DSL.val(filterBAOS.toByteArray(), byte[].class)).execute(); - } - - /** - * Generates a condition that returns true if this temp tables search term tokens might be contained in the parent - * table or parent table bloom filter is null. Selects to same sized filter from the temp table for each parent - * table row. - *

- * expects the user defined function 'bloommatch' to be present to compare filter bytes. expects the parent table to - * be joined in the query that uses the generated Condition. - * - * @return Condition - generated condition - */ - public Condition generateCondition() { - create(); - insertFilters(); - final Table table = DSL.table(DSL.name(("term_" + bloomTermId + "_" + parentTable.getName()))); - final Field termIdField = DSL.field("term_id", BIGINTUNSIGNED.nullable(false)); - final Field typeIdField = DSL.field("type_id", BIGINTUNSIGNED.nullable(false)); - final Field filterField = DSL.field(DSL.name(table.getName(), "filter"), byte[].class); - final SelectConditionStep> selectFilterStep = DSL - .select(filterField) - .from(table) - .where(termIdField.eq(ULong.valueOf(bloomTermId))) - .and(typeIdField.eq((Field) parentTable.field("filter_type_id"))); - final Field filterColumn = selectFilterStep.asField(); - final Condition filterFieldCondition = DSL - .function("bloommatch", Boolean.class, filterColumn, parentTable.field("filter")) - .eq(true); - // null check allows SQL to optimize query - final Condition notNullCondition = parentTable.field("filter").isNotNull(); - return filterFieldCondition.and(notNullCondition); - } - - /** - * Equal only if all object parameters are same value and the instances of DSLContext are same - * - * @param object object compared against - * @return true if all object is same class, object fields are equal and DSLContext is same instance - */ - @Override - public boolean equals(final Object object) { - if (this == object) - return true; - if (object == null) - return false; - if (object.getClass() != this.getClass()) - return false; - final BloomFilterTempTable cast = (BloomFilterTempTable) object; - return this.parentTable.equals(cast.parentTable) && this.ctx == cast.ctx && // equal only if same instance of DSLContext - this.bloomTermId == cast.bloomTermId && this.searchTermTokenSet.equals(cast.searchTermTokenSet); - } -} diff --git a/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java b/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java new file mode 100644 index 00000000..e9545f9f --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java @@ -0,0 +1,57 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; + +public interface CategoryTable { + + void create(); + + void insertFilterTypes(); + + QueryCondition bloommatchCondition(); +} diff --git a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java new file mode 100644 index 00000000..1cc60e55 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java @@ -0,0 +1,174 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.pth_06.config.ConditionConfig; +import com.teragrep.pth_06.planner.walker.conditions.CategoryTableCondition; +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; +import org.jooq.*; +import org.jooq.impl.DSL; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; + +/** + * Class to create a temp table that can create a bloommatch row condition to compare this filter bytes against origin + * filter types. + *

+ * Origin schema: + *

    + *
  1. id PK
  2. + *
  3. partition_id FK journaldb.logfile.id
  4. + *
  5. filter_type_id FK bloomdb.filtertype.id
  6. + *
  7. filter - bloomfilter byte array
  8. + *
+ *

+ * This schema: + *

    + *
  1. id PK
  2. + *
  3. termId - count of the current search term
  4. + *
  5. typeId FK bloomdb.filtertype.id
  6. + *
  7. filter - bloomfilter bytes with only the search term token set inserted
  8. + *
+ * Parent table create table example: + *

+ * + * CREATE TABLE `example` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `partition_id` bigint(20) unsigned NOT NULL, `filter_type_id` bigint(20) unsigned NOT NULL, `filter` longblob NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `partition_id` (`partition_id`), KEY `example_ibfk_1` (`filter_type_id`), CONSTRAINT `example_ibfk_1` FOREIGN KEY (`filter_type_id`) REFERENCES `filtertype` (`id`) ON DELETE CASCADE, CONSTRAINT `example_ibfk_2` FOREIGN KEY (`partition_id`) REFERENCES `journaldb`.`logfile` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=54787 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + * + * + * @see com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb + */ +public final class CategoryTableImpl implements CategoryTable { + + private static final Logger LOGGER = LoggerFactory.getLogger(CategoryTableImpl.class); + + private final DSLContext ctx; + private final Table originTable; + private final long bloomTermId; + private final CategoryTableCondition tableCondition; + private final TableFilters tableFilters; + + public CategoryTableImpl(ConditionConfig config, Table originTable, TokenizedValue tokenizedValue) { + this( + config.context(), + originTable, + config.bloomTermId(), + new CategoryTableCondition(originTable, config.bloomTermId()), + new TableFilters(config.context(), originTable, config.bloomTermId(), tokenizedValue) + ); + } + + public CategoryTableImpl(DSLContext ctx, Table originTable, long bloomTermId, TokenizedValue tokenizedValue) { + this( + ctx, + originTable, + bloomTermId, + new CategoryTableCondition(originTable, bloomTermId), + new TableFilters(ctx, originTable, bloomTermId, tokenizedValue) + ); + } + + public CategoryTableImpl( + DSLContext ctx, + Table originTable, + long bloomTermId, + CategoryTableCondition tableCondition, + TableFilters tableFilters + ) { + this.ctx = ctx; + this.originTable = originTable; + this.bloomTermId = bloomTermId; + this.tableCondition = tableCondition; + this.tableFilters = tableFilters; + } + + public void create() { + final Table namedTable = DSL.table(DSL.name(("term_" + bloomTermId + "_" + originTable.getName()))); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Creating temporary table <{}>", namedTable.getName()); + } + ctx.dropTemporaryTableIfExists(namedTable).execute(); + final String sql = "create temporary table " + namedTable.getName() + + "(id bigint auto_increment primary key, term_id bigint, type_id bigint, filter longblob, unique key " + + namedTable.getName() + "_unique_key (term_id, type_id))"; + final Query createQuery = ctx.query(sql); + createQuery.execute(); + final Index typeIndex = DSL.index(DSL.name(namedTable.getName() + "_ix_type_id")); + final CreateIndexIncludeStep indexStep = ctx + .createIndex(typeIndex) + .on(namedTable, DSL.field("type_id", BIGINTUNSIGNED.nullable(false))); + LOGGER.trace("BloomFilterTempTable create index <{}>", indexStep); + indexStep.execute(); + } + + public void insertFilterTypes() { + tableFilters.insert(); + } + + public QueryCondition bloommatchCondition() { + return tableCondition; + } + + /** + * Equal only if all object parameters are same value and the instances of DSLContext are same + * + * @param object object compared against + * @return true if all object is same class, object fields are equal and DSLContext is same instance + */ + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final CategoryTableImpl cast = (CategoryTableImpl) object; + return this.originTable.equals(cast.originTable) && this.ctx == cast.ctx && // equal only if same instance of DSLContext + this.bloomTermId == cast.bloomTermId && this.tableFilters.equals(cast.tableFilters); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/Created.java b/src/main/java/com/teragrep/pth_06/planner/Created.java new file mode 100644 index 00000000..9a76d469 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/Created.java @@ -0,0 +1,76 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; + +/** + * Decorator that creates category table + */ +public final class Created implements CategoryTable { + + private final CategoryTable origin; + + public Created(final CategoryTable origin) { + this.origin = origin; + } + + @Override + public void create() { + origin.create(); + } + + @Override + public void insertFilterTypes() { + origin.insertFilterTypes(); + } + + @Override + public QueryCondition bloommatchCondition() { + create(); + return origin.bloommatchCondition(); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java b/src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java new file mode 100644 index 00000000..f61a7da9 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java @@ -0,0 +1,76 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; + +/** + * Decorator that inserts category tables filter types into database + */ +public final class FiltersInserted implements CategoryTable { + + private final CategoryTable origin; + + public FiltersInserted(final CategoryTable origin) { + this.origin = origin; + } + + @Override + public void create() { + origin.create(); + } + + @Override + public void insertFilterTypes() { + origin.insertFilterTypes(); + } + + @Override + public QueryCondition bloommatchCondition() { + insertFilterTypes(); + return origin.bloommatchCondition(); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/PatternMatch.java b/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java similarity index 73% rename from src/main/java/com/teragrep/pth_06/planner/PatternMatch.java rename to src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java index 0337a95c..7b91d5e6 100644 --- a/src/main/java/com/teragrep/pth_06/planner/PatternMatch.java +++ b/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java @@ -45,36 +45,39 @@ */ package com.teragrep.pth_06.planner; -import com.teragrep.blf_01.Token; -import com.teragrep.blf_01.Tokenizer; - -import org.jooq.Condition; +import com.teragrep.pth_06.planner.walker.conditions.PatternMatchCondition; import org.jooq.DSLContext; import org.jooq.Field; import org.jooq.Table; -import org.jooq.impl.DSL; import org.jooq.types.ULong; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; -public class PatternMatch { +/** + * Class to get a collection of Tables that match the given PatternMatchCondition + */ +public final class PatternMatchTables { - private static final Logger LOGGER = LoggerFactory.getLogger(PatternMatch.class); + private static final Logger LOGGER = LoggerFactory.getLogger(PatternMatchTables.class); private final DSLContext ctx; - private final String input; + private final PatternMatchCondition patternMatchCondition; - public PatternMatch(DSLContext ctx, String input) { + public PatternMatchTables(DSLContext ctx, String pattern) { + this(ctx, new PatternMatchCondition(new TokenizedValue(pattern))); + } + + public PatternMatchTables(DSLContext ctx, TokenizedValue tokenizedValue) { + this(ctx, new PatternMatchCondition(tokenizedValue)); + } + + public PatternMatchTables(DSLContext ctx, PatternMatchCondition patternMatchCondition) { this.ctx = ctx; - this.input = input; + this.patternMatchCondition = patternMatchCondition; } /** @@ -84,15 +87,6 @@ public PatternMatch(DSLContext ctx, String input) { * @return List of tables that matched condition and were not empty */ public List> toList() { - final Set tokenSet = tokenSet(); - Condition patternCondition = DSL.noCondition(); - // tokens = ['one, 'two'] -> ('one' regex like BLOOMDB.FILTERTYPE.PATTERN).or('two' regex like BLOOMDB.FILTERTYPE.PATTERN) - for (Token token : tokenSet) { - Field tokenStringField = DSL.val(token.toString()); - patternCondition = patternCondition.or(tokenStringField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN)); - } - final Condition finalPatternCondition = patternCondition; - // SQL metadata final List> tables = ctx .meta() .filterSchemas(s -> s.equals(BLOOMDB)) // select bloomdb @@ -101,7 +95,7 @@ public List> toList() { .from(t) .leftJoin(BLOOMDB.FILTERTYPE)// join filtertype to access patterns .on(BLOOMDB.FILTERTYPE.ID.eq((Field) t.field("filter_type_id"))) - .where(finalPatternCondition)// select tables that match pattern condition + .where(patternMatchCondition.condition())// select tables that match pattern condition .limit(1)// limit 1 since we are checking only if table is not empty .fetch() .isNotEmpty() // select table if not empty @@ -111,27 +105,21 @@ public List> toList() { return tables; } - public Set tokenSet() { - return new HashSet<>( - new Tokenizer(0).tokenize(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))) - ); - } - /** * Equal only if all values are equal and same instance of DSLContext - * + * * @param object object compared against * @return true if all object is same class, object fields are equal and DSLContext is same instance */ @Override - public boolean equals(Object object) { + public boolean equals(final Object object) { if (this == object) return true; if (object == null) return false; if (object.getClass() != this.getClass()) return false; - final PatternMatch cast = (PatternMatch) object; - return this.input.equals(cast.input) && this.ctx == cast.ctx; // only same instance of DSLContext is equal + final PatternMatchTables cast = (PatternMatchTables) object; + return this.patternMatchCondition.equals(cast.patternMatchCondition) && this.ctx == cast.ctx; // only same instance of DSLContext is equal } } diff --git a/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java b/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java index e733ca25..0cc044cb 100644 --- a/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java +++ b/src/main/java/com/teragrep/pth_06/planner/StreamDBClient.java @@ -106,6 +106,7 @@ public StreamDBClient(Config config) throws SQLException { final String streamdbName = config.archiveConfig.dbStreamDbName; final String bloomdbName = config.archiveConfig.bloomDbName; final boolean hideDatabaseExceptions = config.archiveConfig.hideDatabaseExceptions; + final boolean withoutFilters = config.archiveConfig.withoutFilters; // https://blog.jooq.org/how-i-incorrectly-fetched-jdbc-resultsets-again/ Settings settings = new Settings() @@ -124,7 +125,7 @@ public StreamDBClient(Config config) throws SQLException { ctx.execute("SET sql_mode = 'NO_ENGINE_SUBSTITUTION';"); } // -- TODO use dslContext.batch for all initial operations - this.walker = new ConditionWalker(ctx, bloomEnabled); + this.walker = new ConditionWalker(ctx, bloomEnabled, withoutFilters); Condition streamdbCondition; try { diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java b/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java new file mode 100644 index 00000000..e4ba078e --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java @@ -0,0 +1,107 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import org.jooq.*; +import org.jooq.impl.DSL; +import org.jooq.types.ULong; + +import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; + +/** + * Filter types of a table from metadata + */ +public final class TableFilterTypesFromMetadata implements TableRecords { + + private final DSLContext ctx; + private final Table table; + private final long bloomTermId; + + public TableFilterTypesFromMetadata(DSLContext ctx, Table table, long bloomTermId) { + this.ctx = ctx; + this.table = table; + this.bloomTermId = bloomTermId; + } + + public Result toResult() { + if (table == null) { + throw new IllegalStateException("Origin table was null"); + } + final Table joined = table + .join(BLOOMDB.FILTERTYPE) + .on(BLOOMDB.FILTERTYPE.ID.eq((Field) table.field("filter_type_id"))); + final Table namedTable = DSL.table(DSL.name(("term_" + bloomTermId + "_" + table.getName()))); + final Field expectedField = DSL.field(DSL.name(namedTable.getName(), "expectedElements"), ULong.class); + final Field fppField = DSL.field(DSL.name(namedTable.getName(), "targetFpp"), Double.class); + final SelectField[] resultFields = { + BLOOMDB.FILTERTYPE.ID, + joined.field("expectedElements").as(expectedField), + joined.field("targetFpp").as(fppField) + }; + // Fetch filtertype values from metadata + final Result records = ctx + .select(resultFields) + .from(joined) + .groupBy(joined.field("filter_type_id")) + .fetch(); + if (records.isEmpty()) { + throw new RuntimeException("Origin table was empty"); + } + return records; + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final TableFilterTypesFromMetadata cast = (TableFilterTypesFromMetadata) object; + return this.bloomTermId == cast.bloomTermId && this.table.equals(cast.table) && this.ctx == cast.ctx; + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java new file mode 100644 index 00000000..c556936a --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -0,0 +1,154 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.*; +import org.jooq.impl.DSL; +import org.jooq.types.ULong; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UncheckedIOException; + +import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; +import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; + +/** + * Filter types of a table that can be inserted + */ +public final class TableFilters { + + private final DSLContext ctx; + private final Table table; + private final long bloomTermId; + private final TokenizedValue tokenizedValue; + private final TableRecords recordsInMetadata; + + public TableFilters(DSLContext ctx, Table table, long bloomTermId, TokenizedValue tokenizedValue) { + this(ctx, table, bloomTermId, tokenizedValue, new TableFilterTypesFromMetadata(ctx, table, bloomTermId)); + } + + public TableFilters( + DSLContext ctx, + Table table, + long bloomTermId, + TokenizedValue tokenizedValue, + TableFilterTypesFromMetadata recordsInMetadata + ) { + this.ctx = ctx; + this.table = table; + this.bloomTermId = bloomTermId; + this.tokenizedValue = tokenizedValue; + this.recordsInMetadata = recordsInMetadata; + } + + /** + * Extracts filter information from record, + * creates a bloom filter and returns the filter byte array + * @param record record with filter info + * @return byte[] of the created filter + */ + private byte[] filterBAOSFromRecord(Record record) { + final ULong expected = record.getValue(DSL.field(DSL.name(table.getName(), "expectedElements"), ULong.class)); + final Double fpp = record.getValue(DSL.field(DSL.name(table.getName(), "targetFpp"), Double.class)); + final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); + tokenizedValue.tokens().forEach(token -> filter.put(token.toString())); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + try { + filter.writeTo(filterBAOS); + filterBAOS.close(); + } + catch (IOException e) { + throw new UncheckedIOException(new IOException("Error writing filter bytes: " + e.getMessage())); + } + return filterBAOS.toByteArray(); + } + + private void insertFilterType(Record record) { + final Table namedTable = DSL.table(DSL.name(("term_" + bloomTermId + "_" + this.table.getName()))); + final Field[] insertFields = { + DSL.field("term_id", BIGINTUNSIGNED.nullable(false)), + DSL.field("type_id", BIGINTUNSIGNED.nullable(false)), + DSL.field(DSL.name(namedTable.getName(), "filter"), byte[].class) + }; + final Field[] valueFields = { + DSL.val(bloomTermId, ULong.class), + DSL.val(record.getValue(BLOOMDB.FILTERTYPE.ID), ULong.class), + DSL.val(filterBAOSFromRecord(record), byte[].class) + }; + ctx + .insertInto(namedTable) + .columns(insertFields) + .values(valueFields) + .execute(); + } + + + public void insert() { + recordsInMetadata.toResult().forEach(this::insertFilterType); + } + + /** + * Expects DSLContext values to be the same instance + * + * @param object object compared + * @returs true if object is equal + */ + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final TableFilters cast = (TableFilters) object; + return this.ctx == cast.ctx && this.tokenizedValue.equals(cast.tokenizedValue) && this.table.equals(cast.table) + && this.bloomTermId == cast.bloomTermId; + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/TableRecords.java b/src/main/java/com/teragrep/pth_06/planner/TableRecords.java new file mode 100644 index 00000000..95b9fb92 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/TableRecords.java @@ -0,0 +1,54 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import org.jooq.Record; +import org.jooq.Result; + +public interface TableRecords { + + Result toResult(); +} diff --git a/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java b/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java new file mode 100644 index 00000000..b659ec85 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java @@ -0,0 +1,81 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.blf_01.Token; +import com.teragrep.blf_01.Tokenizer; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.HashSet; +import java.util.Set; + +public final class TokenizedValue { + + public final String value; + + public TokenizedValue(String value) { + this.value = value; + } + + public Set tokens() { + return new HashSet<>( + new Tokenizer(0).tokenize(new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8))) + ); + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final TokenizedValue cast = (TokenizedValue) object; + return this.value.equals(cast.value); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java index 3aa61f39..3ef9043b 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java @@ -46,6 +46,7 @@ package com.teragrep.pth_06.planner.walker; import com.teragrep.pth_06.config.ConditionConfig; +import com.teragrep.pth_06.planner.walker.conditions.BloomQueryCondition; import com.teragrep.pth_06.planner.walker.conditions.ElementCondition; import com.teragrep.pth_06.planner.walker.conditions.ValidElement; import org.jooq.Condition; @@ -69,25 +70,31 @@ public final class ConditionWalker extends XmlWalker { private final boolean bloomEnabled; + private final boolean withoutFilters; private final Logger LOGGER = LoggerFactory.getLogger(ConditionWalker.class); // Default query is full private boolean streamQuery = false; private final DSLContext ctx; - private final Set> patternMatchSet; + private final Set> combinedMatchSet; private long bloomTermId = 0; /** * Constructor without connection. Used during unit-tests. Enables jooq-query construction. */ public ConditionWalker() { - this(null, false); + this(null, false, false); } public ConditionWalker(DSLContext ctx, boolean bloomEnabled) { + this(ctx, bloomEnabled, false); + } + + public ConditionWalker(DSLContext ctx, boolean bloomEnabled, boolean withoutFilters) { super(); this.ctx = ctx; this.bloomEnabled = bloomEnabled; - this.patternMatchSet = new HashSet<>(); + this.withoutFilters = withoutFilters; + this.combinedMatchSet = new HashSet<>(); } public Condition fromString(String inXml, boolean streamQuery) throws Exception { @@ -101,7 +108,7 @@ public Condition fromString(String inXml, boolean streamQuery) throws Exception * @return Set of Tables that had a pattern match */ public Set> patternMatchTables() { - return patternMatchSet; + return combinedMatchSet; } @Override @@ -154,15 +161,14 @@ public Condition emitUnaryOperation(String op, Element current) throws Exception } Condition emitElem(final Element current) { - final ElementCondition elementCondition = new ElementCondition( + final BloomQueryCondition bloomQueryCondition = new ElementCondition( new ValidElement(current), - new ConditionConfig(ctx, streamQuery, bloomEnabled), - bloomTermId + new ConditionConfig(ctx, streamQuery, bloomEnabled, withoutFilters, bloomTermId) ); - if (elementCondition.isBloomSearchCondition()) { - patternMatchTables().addAll(elementCondition.patternMatchTables()); + if (bloomQueryCondition.isBloomSearchCondition()) { + patternMatchTables().addAll(bloomQueryCondition.patternMatchTables()); bloomTermId++; } - return elementCondition.condition(); + return bloomQueryCondition.condition(); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java new file mode 100644 index 00000000..e8017083 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java @@ -0,0 +1,60 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner.walker.conditions; + +import org.jooq.Condition; +import org.jooq.Table; + +import java.util.Set; + +public interface BloomQueryCondition { + + Condition condition(); + + boolean isBloomSearchCondition(); + + Set> patternMatchTables(); +} diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java new file mode 100644 index 00000000..0c70576e --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java @@ -0,0 +1,94 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner.walker.conditions; + +import org.jooq.*; +import org.jooq.impl.DSL; +import org.jooq.types.ULong; + +import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; + +public final class CategoryTableCondition implements QueryCondition { + + private final Table comparedTo; + private final long bloomTermId; + + public CategoryTableCondition(Table comparedTo, long bloomTermId) { + this.comparedTo = comparedTo; + this.bloomTermId = bloomTermId; + } + + public Condition condition() { + final Table categoryTable = DSL.table(DSL.name(("term_" + bloomTermId + "_" + comparedTo.getName()))); + final Field termIdField = DSL.field("term_id", BIGINTUNSIGNED.nullable(false)); + final Field typeIdField = DSL.field("type_id", BIGINTUNSIGNED.nullable(false)); + final Field filterField = DSL.field(DSL.name(categoryTable.getName(), "filter"), byte[].class); + final SelectConditionStep> selectFilterStep = DSL + .select(filterField) + .from(categoryTable) + .where(termIdField.eq(ULong.valueOf(bloomTermId))) + .and(typeIdField.eq((Field) comparedTo.field("filter_type_id"))); + final Field filterColumn = selectFilterStep.asField(); + final Condition filterFieldCondition = DSL + .function("bloommatch", Boolean.class, filterColumn, comparedTo.field("filter")) + .eq(true); + // null check allows SQL to optimize query + final Condition notNullCondition = comparedTo.field("filter").isNotNull(); + return filterFieldCondition.and(notNullCondition); + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final CategoryTableCondition cast = (CategoryTableCondition) object; + return this.bloomTermId == cast.bloomTermId && this.comparedTo.equals(cast.comparedTo); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index f4360e54..c52822ff 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -45,7 +45,6 @@ */ package com.teragrep.pth_06.planner.walker.conditions; -import com.teragrep.blf_01.Tokenizer; import com.teragrep.pth_06.config.ConditionConfig; import org.jooq.Condition; import org.jooq.Table; @@ -55,29 +54,26 @@ import org.w3c.dom.Element; import java.util.HashSet; -import java.util.List; import java.util.Set; /** * Creates a query condition from provided dom element */ -public final class ElementCondition { +public final class ElementCondition implements BloomQueryCondition { private static final Logger LOGGER = LoggerFactory.getLogger(ElementCondition.class); private final ValidElement element; private final ConditionConfig config; - private final long bloomTermId; private final Set> tableSet; public ElementCondition(Element element, ConditionConfig config) { - this(new ValidElement(element), config, 0L); + this(new ValidElement(element), config); } - public ElementCondition(ValidElement element, ConditionConfig config, long bloomTermId) { + public ElementCondition(ValidElement element, ConditionConfig config) { this.element = element; this.config = config; - this.bloomTermId = bloomTermId; this.tableSet = new HashSet<>(); } @@ -112,17 +108,11 @@ public Condition condition() { } // value search if ("indexstatement".equalsIgnoreCase(tag) && "EQUALS".equals(operation) && config.bloomEnabled()) { - IndexStatementCondition indexStatementCondition = new IndexStatementCondition( - value, - config, - new Tokenizer(0), - condition, - bloomTermId - ); + BloomQueryCondition indexStatementCondition = new IndexStatementCondition(value, config, condition); condition = indexStatementCondition.condition(); - List> newMatches = indexStatementCondition.matchList(); - if (!newMatches.isEmpty()) { - tableSet.addAll(newMatches); + Set> indexStatementMatches = indexStatementCondition.patternMatchTables(); + if (!indexStatementMatches.isEmpty()) { + tableSet.addAll(indexStatementMatches); } } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index f9205b4d..24884d68 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -45,99 +45,88 @@ */ package com.teragrep.pth_06.planner.walker.conditions; -import com.teragrep.blf_01.Tokenizer; import com.teragrep.pth_06.config.ConditionConfig; -import com.teragrep.pth_06.planner.BloomFilterTempTable; -import com.teragrep.pth_06.planner.PatternMatch; +import com.teragrep.pth_06.planner.*; import org.jooq.Condition; import org.jooq.Table; import org.jooq.impl.DSL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; -public final class IndexStatementCondition implements QueryCondition { +public final class IndexStatementCondition implements QueryCondition, BloomQueryCondition { private final Logger LOGGER = LoggerFactory.getLogger(IndexStatementCondition.class); private final String value; private final ConditionConfig config; - private final Tokenizer tokenizer; private final Condition condition; - private final long bloomTermId; - private final List> tableList; + private final Set> tableSet; public IndexStatementCondition(String value, ConditionConfig config) { - this(value, config, new Tokenizer(0), DSL.noCondition(), 0L); + this(value, config, DSL.noCondition()); } - public IndexStatementCondition(String value, ConditionConfig config, Tokenizer tokenizer) { - this(value, config, tokenizer, DSL.noCondition(), 0L); - } - - public IndexStatementCondition(String value, ConditionConfig config, Tokenizer tokenizer, long bloomTermId) { - this(value, config, tokenizer, DSL.noCondition(), bloomTermId); - } - - public IndexStatementCondition( - String value, - ConditionConfig config, - Tokenizer tokenizer, - Condition condition, - long bloomTermId - ) { + public IndexStatementCondition(String value, ConditionConfig config, Condition condition) { this.value = value; this.config = config; - this.tokenizer = tokenizer; this.condition = condition; - this.bloomTermId = bloomTermId; - this.tableList = new ArrayList<>(); + this.tableSet = new HashSet<>(); } public Condition condition() { + if (!config.bloomEnabled()) { + LOGGER.debug("Indexstatement reached with bloom disabled"); + return condition; + } Condition newCondition = condition; LOGGER.info("indexstatement reached with search term <{}>", value); - PatternMatch patternMatch = new PatternMatch(config.context(), value); - if (tableList.isEmpty()) { - tableList.addAll(patternMatch.toList()); + final TokenizedValue tokenizedValue = new TokenizedValue(value); + if (tableSet.isEmpty()) { + PatternMatchTables patternMatchTables = new PatternMatchTables(config.context(), tokenizedValue); + tableSet.addAll(patternMatchTables.toList()); } - if (!tableList.isEmpty()) { + if (!tableSet.isEmpty()) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Found pattern match on <{}> table(s)", tableList.size()); + LOGGER.debug("Found pattern match on <{}> table(s)", tableSet.size()); } Condition bloomCondition = DSL.noCondition(); Condition noBloomCondition = DSL.noCondition(); - for (Table table : tableList) { - BloomFilterTempTable tempTable = new BloomFilterTempTable( - config.context(), - table, - bloomTermId, - patternMatch.tokenSet() - ); - Condition tableCondition = tempTable.generateCondition(); - bloomCondition = bloomCondition.or(tableCondition); + for (final Table table : tableSet) { + final CategoryTable categoryTable = + new Created( + new FiltersInserted( + new CategoryTableImpl(config, table, tokenizedValue)) + ); + final QueryCondition tableCondition = categoryTable.bloommatchCondition(); + bloomCondition = bloomCondition.or(tableCondition.condition()); noBloomCondition = noBloomCondition.and(table.field("filter").isNull()); } - newCondition = bloomCondition.or(noBloomCondition); + if (config.withoutFilters()) { + newCondition = noBloomCondition; + } else { + newCondition = bloomCondition.or(noBloomCondition); + } } return newCondition; } - public List> matchList() { - if (tableList.isEmpty()) { + @Override + public boolean isBloomSearchCondition() { + return config.bloomEnabled() && !config.streamQuery(); + } + + @Override + public Set> patternMatchTables() { + if (tableSet.isEmpty()) { condition(); } - return tableList; + return tableSet; } - /** - * @param object object compared against - * @return true if object is same class and all object values are equal (tokenizer values are expected to point to - * same reference) - */ @Override public boolean equals(final Object object) { if (this == object) @@ -147,6 +136,6 @@ public boolean equals(final Object object) { if (object.getClass() != this.getClass()) return false; final IndexStatementCondition cast = (IndexStatementCondition) object; - return this.value.equals(cast.value) && this.config.equals(cast.config) && this.tokenizer == cast.tokenizer; // expects same reference + return this.value.equals(cast.value) && this.config.equals(cast.config); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java new file mode 100644 index 00000000..5359704d --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java @@ -0,0 +1,99 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner.walker.conditions; + +import com.teragrep.blf_01.Token; +import com.teragrep.pth_06.planner.TokenizedValue; +import org.jooq.*; +import org.jooq.impl.DSL; + +import java.util.Set; + +import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; + +/** + * Combined regex match condition + *

+ * true if any of the tokens regex match against bloomdb.filtertype.pattern + */ +public final class PatternMatchCondition implements QueryCondition { + + private final TokenizedValue tokenizedValue; + + public PatternMatchCondition(String value) { + this(new TokenizedValue(value)); + } + + public PatternMatchCondition(TokenizedValue tokenizedValue) { + this.tokenizedValue = tokenizedValue; + } + + /** + * tokens = ['one, 'two'] -> ('one' regex like BLOOMDB.FILTERTYPE.PATTERN).or('two' regex like BLOOMDB.FILTERTYPE.PATTERN) + * @return combined condition regex matching any of the tokens against filtertype.pattern + */ + public Condition condition() { + final Set tokenSet = tokenizedValue.tokens(); + Condition patternCondition = DSL.noCondition(); + for (Token token : tokenSet) { + Field tokenStringField = DSL.val(token.toString()); + patternCondition = patternCondition.or(tokenStringField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN)); + } + return patternCondition; + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null) + return false; + if (object.getClass() != this.getClass()) + return false; + final PatternMatchCondition cast = (PatternMatchCondition) object; + return this.tokenizedValue.equals(cast.tokenizedValue); + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java similarity index 76% rename from src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java rename to src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index 83226235..ea61eec3 100644 --- a/src/test/java/com/teragrep/pth_06/planner/BloomFilterTempTableTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -45,7 +45,8 @@ */ package com.teragrep.pth_06.planner; -import com.teragrep.blf_01.Token; +import com.teragrep.pth_06.planner.walker.conditions.CategoryTableCondition; +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; import org.apache.spark.util.sketch.BloomFilter; import org.jooq.Condition; import org.jooq.DSLContext; @@ -60,15 +61,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Set; /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class BloomFilterTempTableTest { +public class CategoryTableImplTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; @@ -133,7 +134,7 @@ void tearDown() { } @Test - public void testEmptyParentTable() { + public void testNonCreatedEmptyTable() { DSLContext ctx = DSL.using(conn); Table table = ctx .meta() @@ -142,10 +143,41 @@ public void testEmptyParentTable() { .getTables() .get(0); - Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); - BloomFilterTempTable tempTable = new BloomFilterTempTable(ctx, table, 0L, tokenSet); - RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::generateCondition); - Assertions.assertEquals("Parent table was empty", ex.getMessage()); + TokenizedValue val = new TokenizedValue("test"); + Assertions.assertDoesNotThrow(new CategoryTableImpl(ctx, table, 0L, val)::bloommatchCondition); + } + + @Test + public void testCreatedWithEmptyTable() { + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + TokenizedValue val = new TokenizedValue("test"); + CategoryTable tempTable = new Created(new FiltersInserted(new CategoryTableImpl(ctx, table, 0L, val))); + RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::bloommatchCondition); + Assertions.assertEquals("Origin table was empty", ex.getMessage()); + } + + @Test + public void testCreation() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + TokenizedValue val = new TokenizedValue("test"); + CategoryTable created = new Created(new CategoryTableImpl(ctx, table, 0L, val)); + Assertions + .assertEquals(created.bloommatchCondition(), new CategoryTableImpl(ctx, table, 0L, val).bloommatchCondition()); } @Test @@ -159,15 +191,11 @@ public void testConditionGeneration() { .getTables() .get(0); - Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); - BloomFilterTempTable tempTable = new BloomFilterTempTable(ctx, table, 0L, tokenSet); - Condition condition = tempTable.generateCondition(); - String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_0_target\".\"filter\"\n" - + " from \"term_0_target\"\n" + " where (\n" + " term_id = 0\n" - + " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + " )\n" + " ),\n" - + " \"bloomdb\".\"target\".\"filter\"\n" + " ) = true\n" - + " and \"bloomdb\".\"target\".\"filter\" is not null\n" + ")"; - Assertions.assertEquals(e, condition.toString()); + TokenizedValue val = new TokenizedValue("test"); + CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 0L, val); + QueryCondition tableCond = tempTable.bloommatchCondition(); + QueryCondition expectedCond = new CategoryTableCondition(table, 0L); + Assertions.assertEquals(expectedCond, tableCond); } @Test @@ -180,10 +208,9 @@ public void testBloomTerm() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - - Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); - BloomFilterTempTable tempTable = new BloomFilterTempTable(ctx, table, 1L, tokenSet); - Condition condition = tempTable.generateCondition(); + TokenizedValue val = new TokenizedValue("test"); + CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 1L, val); + Condition condition = tempTable.bloommatchCondition().condition(); Assertions.assertTrue(condition.toString().contains("term_1_")); } @@ -203,9 +230,9 @@ public void testEquality() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - Set tokenSet = new PatternMatch(ctx, "test").tokenSet(); - BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, target1, 1L, tokenSet); - BloomFilterTempTable table2 = new BloomFilterTempTable(ctx, target2, 1L, tokenSet); + TokenizedValue val = new TokenizedValue("one"); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, target1, 1L, val); + CategoryTableImpl table2 = new CategoryTableImpl(ctx, target2, 1L, val); Assertions.assertEquals(table1, table2); Assertions.assertEquals(table2, table1); } @@ -220,10 +247,10 @@ public void testDifferentTokenSetNotEquals() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - Set set1 = new PatternMatch(ctx, "one").tokenSet(); - Set set2 = new PatternMatch(ctx, "two").tokenSet(); - BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, table, 1L, set1); - BloomFilterTempTable table2 = new BloomFilterTempTable(ctx, table, 1L, set2); + TokenizedValue val1 = new TokenizedValue("one"); + TokenizedValue val2 = new TokenizedValue("two"); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 1L, val1); + CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, val2); Assertions.assertNotEquals(table1, table2); Assertions.assertNotEquals(table2, table1); } @@ -238,9 +265,9 @@ public void testDifferentBloomTermNotEquals() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - Set set = new PatternMatch(ctx, "one").tokenSet(); - BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, table, 0L, set); - BloomFilterTempTable table2 = new BloomFilterTempTable(ctx, table, 1L, set); + TokenizedValue val = new TokenizedValue("one"); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, val); + CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, val); Assertions.assertNotEquals(table1, table2); Assertions.assertNotEquals(table2, table1); } @@ -256,9 +283,9 @@ public void testDifferentDSLContextNotEquals() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - Set set = new PatternMatch(ctx, "one").tokenSet(); - BloomFilterTempTable table1 = new BloomFilterTempTable(ctx, table, 0L, set); - BloomFilterTempTable table2 = new BloomFilterTempTable(ctx2, table, 0L, set); + TokenizedValue val = new TokenizedValue("one"); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, val); + CategoryTableImpl table2 = new CategoryTableImpl(ctx2, table, 0L, val); Assertions.assertNotEquals(table1, table2); Assertions.assertNotEquals(table2, table1); } diff --git a/src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java b/src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java similarity index 88% rename from src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java rename to src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java index 2a7b61ab..770b3c1c 100644 --- a/src/test/java/com/teragrep/pth_06/planner/PatternMatchTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java @@ -62,7 +62,7 @@ import java.util.stream.Collectors; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class PatternMatchTest { +public class PatternMatchTablesTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; @@ -131,8 +131,8 @@ void tearDown() { public void testSingleMatch() { DSLContext ctx = DSL.using(conn); String input = "192.168.1.1"; - PatternMatch patternMatch = new PatternMatch(ctx, input); - List> result = patternMatch.toList(); + PatternMatchTables patternMatchTables = new PatternMatchTables(ctx, input); + List> result = patternMatchTables.toList(); Assertions.assertEquals(1, result.size()); Assertions.assertEquals("pattern_test_ip", result.get(0).getName()); } @@ -141,8 +141,8 @@ public void testSingleMatch() { public void testSearchTermTokenizedMatch() { DSLContext ctx = DSL.using(conn); String input = "target_ip=192.168.1.1"; - PatternMatch patternMatch = new PatternMatch(ctx, input); - List> result = patternMatch.toList(); + PatternMatchTables patternMatchTables = new PatternMatchTables(ctx, input); + List> result = patternMatchTables.toList(); Assertions.assertEquals(1, result.size()); Assertions.assertEquals("pattern_test_ip", result.get(0).getName()); } @@ -151,9 +151,9 @@ public void testSearchTermTokenizedMatch() { public void testMultipleMatch() { DSLContext ctx = DSL.using(conn); String input = "255.255.255.255"; - PatternMatch patternMatch = new PatternMatch(ctx, input); - List> result = patternMatch.toList(); - List> result2 = patternMatch.toList(); + PatternMatchTables patternMatchTables = new PatternMatchTables(ctx, input); + List> result = patternMatchTables.toList(); + List> result2 = patternMatchTables.toList(); List tableNames = result.stream().map(Named::getName).collect(Collectors.toList()); Assertions.assertEquals(2, result.size()); Assertions.assertEquals(2, result2.size()); @@ -165,8 +165,8 @@ public void testMultipleMatch() { public void testNoMatch() { DSLContext ctx = DSL.using(conn); String input = "testinput"; - PatternMatch patternMatch = new PatternMatch(ctx, input); - List> result = patternMatch.toList(); + PatternMatchTables patternMatchTables = new PatternMatchTables(ctx, input); + List> result = patternMatchTables.toList(); Assertions.assertTrue(result.isEmpty()); } @@ -174,8 +174,8 @@ public void testNoMatch() { public void equalsTest() { DSLContext ctx = DSL.using(conn); String input = "testinput"; - PatternMatch eq1 = new PatternMatch(ctx, input); - PatternMatch eq2 = new PatternMatch(ctx, input); + PatternMatchTables eq1 = new PatternMatchTables(ctx, input); + PatternMatchTables eq2 = new PatternMatchTables(ctx, input); Assertions.assertEquals(eq1, eq2); Assertions.assertEquals(eq2, eq1); } @@ -183,8 +183,8 @@ public void equalsTest() { @Test public void differentInputNotEqualsTest() { DSLContext ctx = DSL.using(conn); - PatternMatch eq1 = new PatternMatch(ctx, "testinput"); - PatternMatch eq2 = new PatternMatch(ctx, "anotherinput"); + PatternMatchTables eq1 = new PatternMatchTables(ctx, "testinput"); + PatternMatchTables eq2 = new PatternMatchTables(ctx, "anotherinput"); Assertions.assertNotEquals(eq1, eq2); Assertions.assertNotEquals(eq2, eq1); } @@ -193,8 +193,8 @@ public void differentInputNotEqualsTest() { public void differentDSLContextNotEqualsTest() { DSLContext ctx1 = DSL.using(conn); DSLContext ctx2 = DSL.using(conn); - PatternMatch eq1 = new PatternMatch(ctx1, "testinput"); - PatternMatch eq2 = new PatternMatch(ctx2, "testinput"); + PatternMatchTables eq1 = new PatternMatchTables(ctx1, "testinput"); + PatternMatchTables eq2 = new PatternMatchTables(ctx2, "testinput"); Assertions.assertNotEquals(eq1, eq2); Assertions.assertNotEquals(eq2, eq1); } diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java new file mode 100644 index 00000000..c9834773 --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java @@ -0,0 +1,236 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.DSLContext; +import org.jooq.Record; +import org.jooq.Result; +import org.jooq.Table; +import org.jooq.impl.DSL; +import org.jooq.types.ULong; +import org.junit.jupiter.api.*; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class TableFilterTypesFromMetadataResultTest { + + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + public void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + conn.prepareStatement(filtertype).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, id * 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + }); + } + + @BeforeEach + void createTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS target").execute(); + String targetTable = "CREATE TABLE `target`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(targetTable).execute(); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS").execute(); //h2 clear database + conn.close(); + }); + } + + @Test + void testNoFilterTypes() { + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + TableFilterTypesFromMetadata result = new TableFilterTypesFromMetadata(ctx, table, 0L); + RuntimeException exception = Assertions.assertThrows(RuntimeException.class, result::toResult); + Assertions.assertEquals("Origin table was empty", exception.getMessage()); + } + + @Test + void testOneFilterType() { + insertSizedFilterIntoTargetTable(1); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + TableFilterTypesFromMetadata result = new TableFilterTypesFromMetadata(ctx, table, 0L); + Result records = result.toResult(); + Assertions.assertEquals(1, records.size()); + Assertions.assertEquals(ULong.valueOf(1000), records.get(0).get(1)); + Assertions.assertEquals(0.01, records.get(0).get(2)); + } + + @Test + void testMultipleFilterTypes() { + insertSizedFilterIntoTargetTable(1); + insertSizedFilterIntoTargetTable(2); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + TableFilterTypesFromMetadata result = new TableFilterTypesFromMetadata(ctx, table, 0L); + Result records = result.toResult(); + Assertions.assertEquals(2, records.size()); + Record first = records.get(0); + Record second = records.get(1); + Assertions.assertEquals(first.get(1), ULong.valueOf("1000")); + Assertions.assertEquals(second.get(1), ULong.valueOf("2000")); + } + + @Test + public void testEquality() { + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + TableFilterTypesFromMetadata result1 = new TableFilterTypesFromMetadata(ctx, table, 0L); + TableFilterTypesFromMetadata result2 = new TableFilterTypesFromMetadata(ctx, table, 0L); + Assertions.assertEquals(result1, result2); + Assertions.assertEquals(result2, result1); + } + + @Test + public void testNotEquals() { + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + TableFilterTypesFromMetadata result1 = new TableFilterTypesFromMetadata(ctx, table, 0L); + TableFilterTypesFromMetadata result2 = new TableFilterTypesFromMetadata(ctx, table, 1L); + TableFilterTypesFromMetadata result3 = new TableFilterTypesFromMetadata(ctx, null, 0L); + Assertions.assertNotEquals(result1, result2); + Assertions.assertNotEquals(result2, result1); + Assertions.assertNotEquals(result1, result3); + Assertions.assertNotEquals(result1, null); + } + + void insertSizedFilterIntoTargetTable(int filterTypeId) { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `target` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, filterTypeId); + stmt.setInt(2, filterTypeId); + stmt.setBytes(3, filterBAOS.toByteArray()); + int success = stmt.executeUpdate(); + Assertions.assertEquals(1, success); + }); + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java new file mode 100644 index 00000000..47e7734e --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java @@ -0,0 +1,213 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.DSLContext; +import org.jooq.Table; +import org.jooq.exception.DataAccessException; +import org.jooq.impl.DSL; +import org.junit.jupiter.api.*; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class TableFiltersTest { + + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + public void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + conn.prepareStatement(filtertype).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, id * 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + }); + } + + @BeforeEach + void createTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS target").execute(); + String targetTable = "CREATE TABLE `target`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(targetTable).execute(); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS").execute(); //h2 clear database + conn.close(); + }); + } + + @Test + public void testCreation() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + Assertions.assertDoesNotThrow(() -> new TableFilters(ctx, table, 0L, new TokenizedValue("test"))); + } + + @Test + public void testInsert() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + DataAccessException exception = Assertions + .assertThrows( + DataAccessException.class, () -> new TableFilters(ctx, table, 0L, new TokenizedValue("test")).insert() + ); + Assertions.assertTrue(exception.getMessage().contains("term_0_target\" (term_id, type_id, \"filter\")")); + } + + @Test + public void testEquals() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + TableFilters filter1 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); + TableFilters filter2 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); + Assertions.assertEquals(filter1, filter2); + Assertions.assertEquals(filter2, filter1); + } + + @Test + public void testNotEquals() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + TableFilters filter1 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); + TableFilters filter2 = new TableFilters(ctx, table, 1L, new TokenizedValue("test")); + TableFilters filter3 = new TableFilters(ctx, table, 0L, new TokenizedValue("mest")); + Assertions.assertNotEquals(filter1, filter2); + Assertions.assertNotEquals(filter1, filter3); + Assertions.assertNotEquals(filter1, null); + } + + void fillTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `target` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, 1); + stmt.setInt(2, 1); + stmt.setBytes(3, filterBAOS.toByteArray()); + stmt.executeUpdate(); + }); + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java new file mode 100644 index 00000000..6a5c6113 --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java @@ -0,0 +1,88 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.blf_01.Token; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Set; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +class TokenizedValueTest { + + @Test + void testTokenization() { + TokenizedValue result = new TokenizedValue("test.nest"); + Set tokens = result.tokens().stream().map(Token::toString).collect(Collectors.toSet()); + Assertions.assertEquals("test.nest", result.value); + Assertions.assertTrue(tokens.contains("nest")); + Assertions.assertTrue(tokens.contains("test")); + Assertions.assertTrue(tokens.contains(".")); + Assertions.assertTrue(tokens.contains("test.nest")); + } + + @Test + void testEquality() { + TokenizedValue value1 = new TokenizedValue("test"); + TokenizedValue value2 = new TokenizedValue("test"); + Assertions.assertEquals(value1, value2); + Assertions.assertEquals(value2, value1); + value1.tokens(); + Assertions.assertEquals(value2, value1); + } + + @Test + void testNotEquals() { + TokenizedValue value1 = new TokenizedValue("test"); + TokenizedValue value2 = new TokenizedValue("nest"); + Assertions.assertNotEquals(value1, value2); + Assertions.assertNotEquals(value2, value1); + Assertions.assertNotEquals(value1, null); + } +} diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java new file mode 100644 index 00000000..cf63ac01 --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java @@ -0,0 +1,228 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner.walker.conditions; + +import org.apache.spark.util.sketch.BloomFilter; +import org.jooq.DSLContext; +import org.jooq.Table; +import org.jooq.impl.DSL; +import org.junit.jupiter.api.*; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * + * @see org.jooq.QueryPart + */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class CategoryTableConditionTest { + + final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; + final String userName = "sa"; + final String password = ""; + final List patternList = new ArrayList<>( + Arrays + .asList( + "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", + "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" + ) + ); + final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); + + @BeforeAll + public void setup() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS filtertype").execute(); + String filtertype = "CREATE TABLE`filtertype`" + "(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `expectedElements` bigint(20) unsigned NOT NULL," + + " `targetFpp` DOUBLE(2) unsigned NOT NULL," + + " `pattern` VARCHAR(2048) NOT NULL," + + " UNIQUE KEY (`expectedElements`, `targetFpp`, `pattern`)" + ")"; + conn.prepareStatement(filtertype).execute(); + String typeSQL = "INSERT INTO `filtertype` (`id`,`expectedElements`, `targetFpp`, `pattern`) VALUES (?,?,?,?)"; + int id = 1; + for (String pattern : patternList) { + PreparedStatement filterType = conn.prepareStatement(typeSQL); + filterType.setInt(1, id); + filterType.setInt(2, 1000); + filterType.setDouble(3, 0.01); + filterType.setString(4, pattern); + filterType.executeUpdate(); + id++; + } + }); + } + + @BeforeEach + void createTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + conn.prepareStatement("DROP TABLE IF EXISTS target").execute(); + String targetTable = "CREATE TABLE `target`(" + + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `partition_id` bigint(20) unsigned NOT NULL UNIQUE," + + " `filter_type_id` bigint(20) unsigned NOT NULL," + + " `filter` longblob NOT NULL)"; + conn.prepareStatement(targetTable).execute(); + }); + } + + @AfterAll + void tearDown() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("DROP ALL OBJECTS").execute(); //h2 clear database + conn.close(); + }); + } + + @Test + void testCondition() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table target1 = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + CategoryTableCondition cond = new CategoryTableCondition(target1, 0L); + String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_0_target\".\"filter\"\n" + + " from \"term_0_target\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + " )\n" + " ),\n" + + " \"bloomdb\".\"target\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"target\".\"filter\" is not null\n" + ")"; + Assertions.assertEquals(e, cond.condition().toString()); + } + + @Test + void testBloomTermId() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table target1 = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + CategoryTableCondition cond = new CategoryTableCondition(target1, 1L); + String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_1_target\".\"filter\"\n" + + " from \"term_1_target\"\n" + " where (\n" + " term_id = 1\n" + + " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + " )\n" + " ),\n" + + " \"bloomdb\".\"target\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"target\".\"filter\" is not null\n" + ")"; + Assertions.assertEquals(e, cond.condition().toString()); + } + + @Test + public void testEquality() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table target1 = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + CategoryTableCondition cond1 = new CategoryTableCondition(target1, 1L); + CategoryTableCondition cond2 = new CategoryTableCondition(target1, 1L); + Assertions.assertEquals(cond1, cond2); + Assertions.assertEquals(cond2, cond1); + cond1.condition(); + Assertions.assertEquals(cond1, cond2); + } + + @Test + public void testNonEquality() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table target1 = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + CategoryTableCondition cond1 = new CategoryTableCondition(target1, 0L); + CategoryTableCondition cond2 = new CategoryTableCondition(target1, 1L); + CategoryTableCondition cond3 = new CategoryTableCondition(null, 1L); + Assertions.assertNotEquals(cond1, cond2); + Assertions.assertNotEquals(cond2, cond1); + Assertions.assertNotEquals(cond1, null); + Assertions.assertNotEquals(cond1, cond3); + } + + void fillTargetTable() { + Assertions.assertDoesNotThrow(() -> { + conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); + conn.prepareStatement("USE BLOOMDB").execute(); + String sql = "INSERT INTO `target` (`partition_id`, `filter_type_id`, `filter`) " + + "VALUES (?, (SELECT `id` FROM `filtertype` WHERE id=?), ?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + BloomFilter filter = BloomFilter.create(1000, 0.01); + final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); + Assertions.assertDoesNotThrow(() -> { + filter.writeTo(filterBAOS); + filterBAOS.close(); + }); + stmt.setInt(1, 1); + stmt.setInt(2, 1); + stmt.setBytes(3, filterBAOS.toByteArray()); + stmt.executeUpdate(); + }); + } + +} diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java index 9dd3cc16..defd6787 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java @@ -52,6 +52,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ public class EarliestConditionTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java index 4e9855cc..5288c943 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java @@ -62,6 +62,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ class ElementConditionTest { @@ -93,8 +94,8 @@ void testStreamTags() { void testProvidedElementMissingValue() { Element element = document.createElement("test"); element.setAttribute("operation", "EQUALS"); - ElementCondition elementCondition = new ElementCondition(element, config); - ElementCondition streamElementCondition = new ElementCondition(element, streamConfig); + BloomQueryCondition elementCondition = new ElementCondition(element, config); + BloomQueryCondition streamElementCondition = new ElementCondition(element, streamConfig); Assertions.assertThrows(IllegalStateException.class, elementCondition::condition); Assertions.assertThrows(IllegalStateException.class, streamElementCondition::condition); } @@ -103,8 +104,8 @@ void testProvidedElementMissingValue() { void testProvidedElementMissingOperation() { Element element = document.createElement("test"); element.setAttribute("value", "1000"); - ElementCondition elementCondition = new ElementCondition(element, config); - ElementCondition streamElementCondition = new ElementCondition(element, streamConfig); + BloomQueryCondition elementCondition = new ElementCondition(element, config); + BloomQueryCondition streamElementCondition = new ElementCondition(element, streamConfig); Assertions.assertThrows(IllegalStateException.class, elementCondition::condition); Assertions.assertThrows(IllegalStateException.class, streamElementCondition::condition); } @@ -117,14 +118,14 @@ void testIsIndexStatement() { Element element2 = document.createElement("index"); element2.setAttribute("value", "searchTerm"); element2.setAttribute("operation", "EQUALS"); - ElementCondition condition = new ElementCondition(element, config); + BloomQueryCondition condition = new ElementCondition(element, config); Assertions.assertTrue(condition.isBloomSearchCondition()); element.setAttribute("operation", "NOT_EQUALS"); - ElementCondition condition2 = new ElementCondition(element, config); + BloomQueryCondition condition2 = new ElementCondition(element, config); Assertions.assertFalse(condition2.isBloomSearchCondition()); - ElementCondition condition3 = new ElementCondition(element, streamConfig); + BloomQueryCondition condition3 = new ElementCondition(element, streamConfig); Assertions.assertFalse(condition3.isBloomSearchCondition()); - ElementCondition condition4 = new ElementCondition(element2, streamConfig); + BloomQueryCondition condition4 = new ElementCondition(element2, streamConfig); Assertions.assertFalse(condition4.isBloomSearchCondition()); } @@ -133,7 +134,7 @@ void testIndexStatementWithBadConnection() { Element element = document.createElement("indexstatement"); element.setAttribute("value", "searchTerm"); element.setAttribute("operation", "EQUALS"); - ElementCondition condition = new ElementCondition(element, config); + BloomQueryCondition condition = new ElementCondition(element, config); Assertions.assertTrue(condition.isBloomSearchCondition()); Assertions.assertThrows(DataAccessException.class, condition::condition); } @@ -191,9 +192,9 @@ void equalsTest() { Element element = document.createElement("index"); element.setAttribute("value", "f17"); element.setAttribute("operation", "EQUALS"); - ElementCondition eq1 = new ElementCondition(element, config); + BloomQueryCondition eq1 = new ElementCondition(element, config); eq1.condition(); - ElementCondition eq2 = new ElementCondition(element, config); + BloomQueryCondition eq2 = new ElementCondition(element, config); Assertions.assertEquals(eq1, eq2); } @@ -205,9 +206,9 @@ void notEqualsTest() { Element anotherElement = document.createElement("index"); anotherElement.setAttribute("value", "f11"); anotherElement.setAttribute("operation", "EQUALS"); - ElementCondition eq1 = new ElementCondition(element, config); - ElementCondition notEq = new ElementCondition(anotherElement, config); - ElementCondition notEq2 = new ElementCondition(element, streamConfig); + BloomQueryCondition eq1 = new ElementCondition(element, config); + BloomQueryCondition notEq = new ElementCondition(anotherElement, config); + BloomQueryCondition notEq2 = new ElementCondition(element, streamConfig); Assertions.assertNotEquals(eq1, notEq); Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, notEq2); @@ -224,8 +225,8 @@ void notEqualsDifferentConfigTest() { DSLContext ctx = DSL.using(conn); ConditionConfig cfg1 = new ConditionConfig(ctx, false); ConditionConfig cfg2 = new ConditionConfig(ctx, true); - ElementCondition eq = new ElementCondition(element, cfg1); - ElementCondition notEq = new ElementCondition(element, cfg2); + BloomQueryCondition eq = new ElementCondition(element, cfg1); + BloomQueryCondition notEq = new ElementCondition(element, cfg2); Assertions.assertNotEquals(eq, notEq); } @@ -240,8 +241,8 @@ void notEqualsDifferentConnectionTest() { DSLContext ctx2 = DSL.using(conn2); ConditionConfig cfg1 = new ConditionConfig(ctx, false); ConditionConfig cfg2 = new ConditionConfig(ctx2, false); - ElementCondition eq = new ElementCondition(element, cfg1); - ElementCondition notEq = new ElementCondition(element, cfg2); + BloomQueryCondition eq = new ElementCondition(element, cfg1); + BloomQueryCondition notEq = new ElementCondition(element, cfg2); Assertions.assertNotEquals(eq, notEq); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java index a4a5b8c4..e01e2f8e 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java @@ -52,6 +52,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ public class HostConditionTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java index 48fa3df6..42b628d0 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java @@ -52,6 +52,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ public class IndexConditionTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index f6321b87..432a6d09 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -45,7 +45,6 @@ */ package com.teragrep.pth_06.planner.walker.conditions; -import com.teragrep.blf_01.Tokenizer; import com.teragrep.pth_06.config.ConditionConfig; import org.apache.spark.util.sketch.BloomFilter; import org.jooq.Condition; @@ -67,6 +66,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -87,7 +87,6 @@ public class IndexStatementConditionTest { false, true ); - final Tokenizer tokenizer = new Tokenizer(0); final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); @BeforeAll @@ -144,9 +143,12 @@ void tearDown() { @Test void testConnectionException() { DSLContext ctx = DSL.using(new MockConnection(c -> new MockResult[0])); - ConditionConfig config = new ConditionConfig(ctx, false); - IndexStatementCondition cond = new IndexStatementCondition("test", config, tokenizer, DSL.trueCondition(), 0L); - Assertions.assertThrows(DataAccessException.class, cond::condition); + ConditionConfig config = new ConditionConfig(ctx, false, true); + ConditionConfig noBloomConfig = new ConditionConfig(ctx, false); + BloomQueryCondition cond1 = new IndexStatementCondition("test", config, DSL.trueCondition()); + BloomQueryCondition cond2 = new IndexStatementCondition("test", noBloomConfig, DSL.trueCondition()); + Assertions.assertThrows(DataAccessException.class, cond1::condition); + Assertions.assertDoesNotThrow(cond2::condition); } @Test @@ -155,19 +157,20 @@ void noMatchesTest() { Condition e1 = DSL.falseCondition(); Condition e2 = DSL.trueCondition(); ConditionConfig config = new ConditionConfig(ctx, false, true); - IndexStatementCondition cond1 = new IndexStatementCondition("test", config, tokenizer, e1, 0L); - IndexStatementCondition cond2 = new IndexStatementCondition("test", config, tokenizer, e2, 1L); + ConditionConfig withoutFiltersConfig = new ConditionConfig(ctx, false, true, true, 1L); + BloomQueryCondition cond1 = new IndexStatementCondition("test", config, e1); + BloomQueryCondition cond2 = new IndexStatementCondition("test", withoutFiltersConfig, e2); Assertions.assertEquals(e1, cond1.condition()); Assertions.assertEquals(e2, cond2.condition()); - Assertions.assertTrue(cond1.matchList().isEmpty()); - Assertions.assertTrue(cond2.matchList().isEmpty()); + Assertions.assertTrue(cond1.patternMatchTables().isEmpty()); + Assertions.assertTrue(cond2.patternMatchTables().isEmpty()); } @Test void oneMatchingTableTest() { DSLContext ctx = DSL.using(conn); ConditionConfig config = new ConditionConfig(ctx, false, true); - IndexStatementCondition cond = new IndexStatementCondition("192.168.1.1", config, tokenizer); + BloomQueryCondition cond = new IndexStatementCondition("192.168.1.1", config); String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip\".\"filter\"\n" + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" @@ -176,14 +179,35 @@ void oneMatchingTableTest() { + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is not null\n" + " )\n" + " or \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + ")"; Assertions.assertEquals(e, cond.condition().toString()); - Assertions.assertEquals(1, cond.matchList().size()); + Assertions.assertEquals(1, cond.patternMatchTables().size()); + } + + @Test + void testOneMatchWithoutFilters() { + DSLContext ctx = DSL.using(conn); + ConditionConfig config = new ConditionConfig(ctx, false, true, true); + BloomQueryCondition cond = new IndexStatementCondition("192.168.1.1", config); + String e = "\"bloomdb\".\"pattern_test_ip\".\"filter\" is null"; + Assertions.assertEquals(e, cond.condition().toString()); + Assertions.assertEquals(1, cond.patternMatchTables().size()); + } + + @Test + void testTwoMatchWithoutFilters() { + DSLContext ctx = DSL.using(conn); + ConditionConfig config = new ConditionConfig(ctx, false, true, true); + BloomQueryCondition cond = new IndexStatementCondition("255.255.255.255", config); + String e = "(\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + ")"; + Assertions.assertEquals(e, cond.condition().toString()); + Assertions.assertEquals(2, cond.patternMatchTables().size()); } @Test void twoMatchingTableTest() { DSLContext ctx = DSL.using(conn); ConditionConfig config = new ConditionConfig(ctx, false, true); - IndexStatementCondition cond = new IndexStatementCondition("255.255.255.255", config, tokenizer); + BloomQueryCondition cond = new IndexStatementCondition("255.255.255.255", config); String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip\".\"filter\"\n" + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" @@ -198,21 +222,21 @@ void twoMatchingTableTest() { + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + " )\n" + ")"; Assertions.assertEquals(e, cond.condition().toString()); - Assertions.assertEquals(2, cond.matchList().size()); + Assertions.assertEquals(2, cond.patternMatchTables().size()); } @Test void equalsTest() { - IndexStatementCondition eq1 = new IndexStatementCondition("946677600", mockConfig, tokenizer); - IndexStatementCondition eq2 = new IndexStatementCondition("946677600", mockConfig, tokenizer); + BloomQueryCondition eq1 = new IndexStatementCondition("946677600", mockConfig); + BloomQueryCondition eq2 = new IndexStatementCondition("946677600", mockConfig); Assertions.assertEquals(eq1, eq2); Assertions.assertEquals(eq2, eq1); } @Test void notEqualsTest() { - IndexStatementCondition eq1 = new IndexStatementCondition("946677600", mockConfig, tokenizer); - IndexStatementCondition notEq = new IndexStatementCondition("1000", mockConfig, tokenizer); + BloomQueryCondition eq1 = new IndexStatementCondition("946677600", mockConfig); + BloomQueryCondition notEq = new IndexStatementCondition("1000", mockConfig); Assertions.assertNotEquals(eq1, notEq); Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, null); diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java index f150da7e..0fc7e6eb 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java @@ -52,6 +52,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ class LatestConditionTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java new file mode 100644 index 00000000..c9561b86 --- /dev/null +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java @@ -0,0 +1,50 @@ +package com.teragrep.pth_06.planner.walker.conditions; + +import org.jooq.Condition; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. + * inherited from QueryPart + * + * @see org.jooq.QueryPart + */ +class PatternMatchConditionTest { + + @Test + void testSingleToken() { + Condition condition = new PatternMatchCondition("test").condition(); + String e = "('test' like_regex \"bloomdb\".\"filtertype\".\"pattern\")"; + Assertions.assertEquals(e, condition.toString()); + } + + @Test + void testMultipleTokens() { + Condition condition = new PatternMatchCondition("test.nest").condition(); + String e = "(\n" + + " ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('.' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('test' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + ")"; + Assertions.assertEquals(e, condition.toString()); + } + + @Test + void testEquality() { + PatternMatchCondition cond1 = new PatternMatchCondition("test"); + PatternMatchCondition cond2 = new PatternMatchCondition("test"); + Assertions.assertEquals(cond1, cond2); + cond1.condition(); + Assertions.assertEquals(cond2, cond1); + } + + @Test + void testNotEquals() { + PatternMatchCondition cond1 = new PatternMatchCondition("test"); + PatternMatchCondition cond2 = new PatternMatchCondition("next"); + Assertions.assertNotEquals(cond1, cond2); + Assertions.assertNotEquals(cond2, cond1); + } +} \ No newline at end of file diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java index eb6a2dc2..097e378a 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java @@ -52,6 +52,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ class SourceTypeConditionTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java index 2c7fd787..94685fb2 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java @@ -55,6 +55,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ class ValidElementTest { diff --git a/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java b/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java index 9d295004..60346b7e 100644 --- a/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java +++ b/src/test/java/com/teragrep/pth_06/walker/ConditionWalkerTest.java @@ -62,6 +62,7 @@ /** * Comparing Condition equality using toString() since jooq Condition uses just toString() to check for equality. * inherited from QueryPart + * * @see org.jooq.QueryPart */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -150,6 +151,16 @@ void bloomNoMatchStreamQueryTest() { Assertions.assertEquals(0, walker.patternMatchTables().size()); } + @Test + void bloomNoMatchStreamQueryWithoutFiltersTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true, true); + String q = ""; + String e = "\"streamdb\".\"stream\".\"directory\" like 'haproxy'"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, true)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(0, walker.patternMatchTables().size()); + } + @Test void singleTablePatternMatchStreamQueryTest() { ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); @@ -179,6 +190,19 @@ void singleTablePatternMatchTest() { .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); } + @Test + void singleTablePatternMatchWithoutFiltersTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true, true); + String q = ""; + String e = "(\n" + " \"getArchivedObjects_filter_table\".\"directory\" like 'haproxy'\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(1, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + } + @Test void twoTablePatternMatchTest() { ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); @@ -206,6 +230,22 @@ void twoTablePatternMatchTest() { .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip255"))); } + @Test + void twoTablePatternMatchWithoutFiltersTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true, true); + String q = ""; + String e = "(\n" + " \"getArchivedObjects_filter_table\".\"directory\" like 'haproxy'\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(2, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip255"))); + } + @Test void multipleSearchTermTestOneMatchTest() { ConditionWalker walker = new ConditionWalker(DSL.using(conn), true); @@ -257,6 +297,22 @@ void multipleSearchTermTwoAndOneMatchTest() { .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip255"))); } + @Test + void multipleSearchTermTwoAndOneMatchWithoutFiltersTest() { + ConditionWalker walker = new ConditionWalker(DSL.using(conn), true, true); + String q = ""; + String e = "(\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + + " and \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + ")"; + Condition cond = Assertions.assertDoesNotThrow(() -> walker.fromString(q, false)); + Assertions.assertEquals(e, cond.toString()); + Assertions.assertEquals(2, walker.patternMatchTables().size()); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip"))); + Assertions + .assertTrue(walker.patternMatchTables().stream().anyMatch(t -> t.getName().equals("pattern_test_ip255"))); + } + private void writeFilter(String tableName, int filterId) { Assertions.assertDoesNotThrow(() -> { conn.prepareStatement("CREATE SCHEMA IF NOT EXISTS BLOOMDB").execute(); From be3c266118292561d59b83a50e11469675c5d194 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Mon, 16 Sep 2024 15:31:41 +0300 Subject: [PATCH 10/20] apply spotless --- .../teragrep/pth_06/planner/TableFilters.java | 12 +--- .../conditions/IndexStatementCondition.java | 11 ++-- .../conditions/PatternMatchCondition.java | 4 +- ...ableFilterTypesFromMetadataResultTest.java | 1 - .../conditions/PatternMatchConditionTest.java | 57 ++++++++++++++++--- 5 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java index c556936a..620e4f42 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -52,7 +52,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.io.UncheckedIOException; import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; @@ -88,8 +87,8 @@ public TableFilters( } /** - * Extracts filter information from record, - * creates a bloom filter and returns the filter byte array + * Extracts filter information from record, creates a bloom filter and returns the filter byte array + * * @param record record with filter info * @return byte[] of the created filter */ @@ -121,14 +120,9 @@ private void insertFilterType(Record record) { DSL.val(record.getValue(BLOOMDB.FILTERTYPE.ID), ULong.class), DSL.val(filterBAOSFromRecord(record), byte[].class) }; - ctx - .insertInto(namedTable) - .columns(insertFields) - .values(valueFields) - .execute(); + ctx.insertInto(namedTable).columns(insertFields).values(valueFields).execute(); } - public void insert() { recordsInMetadata.toResult().forEach(this::insertFilterType); } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index 24884d68..35f0f748 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -96,18 +96,17 @@ public Condition condition() { Condition noBloomCondition = DSL.noCondition(); for (final Table table : tableSet) { - final CategoryTable categoryTable = - new Created( - new FiltersInserted( - new CategoryTableImpl(config, table, tokenizedValue)) - ); + final CategoryTable categoryTable = new Created( + new FiltersInserted(new CategoryTableImpl(config, table, tokenizedValue)) + ); final QueryCondition tableCondition = categoryTable.bloommatchCondition(); bloomCondition = bloomCondition.or(tableCondition.condition()); noBloomCondition = noBloomCondition.and(table.field("filter").isNull()); } if (config.withoutFilters()) { newCondition = noBloomCondition; - } else { + } + else { newCondition = bloomCondition.or(noBloomCondition); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java index 5359704d..a3348439 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java @@ -72,7 +72,9 @@ public PatternMatchCondition(TokenizedValue tokenizedValue) { } /** - * tokens = ['one, 'two'] -> ('one' regex like BLOOMDB.FILTERTYPE.PATTERN).or('two' regex like BLOOMDB.FILTERTYPE.PATTERN) + * tokens = ['one, 'two'] -> ('one' regex like BLOOMDB.FILTERTYPE.PATTERN).or('two' regex like + * BLOOMDB.FILTERTYPE.PATTERN) + * * @return combined condition regex matching any of the tokens against filtertype.pattern */ public Condition condition() { diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java index c9834773..de2860ef 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java @@ -61,7 +61,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; @TestInstance(TestInstance.Lifecycle.PER_CLASS) class TableFilterTypesFromMetadataResultTest { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java index c9561b86..fde20cfa 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java @@ -1,3 +1,48 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ package com.teragrep.pth_06.planner.walker.conditions; import org.jooq.Condition; @@ -22,12 +67,10 @@ void testSingleToken() { @Test void testMultipleTokens() { Condition condition = new PatternMatchCondition("test.nest").condition(); - String e = "(\n" + - " ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + - " or ('nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + - " or ('.' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + - " or ('test' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + - ")"; + String e = "(\n" + " ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('.' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('test' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + ")"; Assertions.assertEquals(e, condition.toString()); } @@ -47,4 +90,4 @@ void testNotEquals() { Assertions.assertNotEquals(cond1, cond2); Assertions.assertNotEquals(cond2, cond1); } -} \ No newline at end of file +} From 1c31037d5dbaf726f9ee31a51f907767b74e8cf3 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Wed, 18 Sep 2024 09:21:59 +0300 Subject: [PATCH 11/20] renaming of names and methods --- .../com/teragrep/pth_06/planner/PatternMatchTables.java | 6 +++--- src/main/java/com/teragrep/pth_06/planner/TableFilters.java | 6 +++--- .../planner/{FiltersInserted.java => WithFilterTypes.java} | 4 ++-- .../com/teragrep/pth_06/planner/walker/ConditionWalker.java | 6 ++++-- .../planner/walker/conditions/IndexStatementCondition.java | 3 ++- .../com/teragrep/pth_06/planner/CategoryTableImplTest.java | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) rename src/main/java/com/teragrep/pth_06/planner/{FiltersInserted.java => WithFilterTypes.java} (95%) diff --git a/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java b/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java index 7b91d5e6..91654674 100644 --- a/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java +++ b/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java @@ -46,6 +46,7 @@ package com.teragrep.pth_06.planner; import com.teragrep.pth_06.planner.walker.conditions.PatternMatchCondition; +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; import org.jooq.DSLContext; import org.jooq.Field; import org.jooq.Table; @@ -65,7 +66,7 @@ public final class PatternMatchTables { private static final Logger LOGGER = LoggerFactory.getLogger(PatternMatchTables.class); private final DSLContext ctx; - private final PatternMatchCondition patternMatchCondition; + private final QueryCondition patternMatchCondition; public PatternMatchTables(DSLContext ctx, String pattern) { this(ctx, new PatternMatchCondition(new TokenizedValue(pattern))); @@ -81,8 +82,7 @@ public PatternMatchTables(DSLContext ctx, PatternMatchCondition patternMatchCond } /** - * Finds all non-empty Tables from bloomdb that are not filtertype and that match regex condition from token set - * Note: Table records are not fetched fully + * List of tables from bloomdb that match patternMatchCondition Note: Table records are not fetched fully * * @return List of tables that matched condition and were not empty */ diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java index 620e4f42..91985e5f 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -87,12 +87,12 @@ public TableFilters( } /** - * Extracts filter information from record, creates a bloom filter and returns the filter byte array + * Extracts filter type from record, creates a bloom filter and returns the filters byte array * * @param record record with filter info * @return byte[] of the created filter */ - private byte[] filterBAOSFromRecord(Record record) { + private byte[] filterBytesFromRecord(final Record record) { final ULong expected = record.getValue(DSL.field(DSL.name(table.getName(), "expectedElements"), ULong.class)); final Double fpp = record.getValue(DSL.field(DSL.name(table.getName(), "targetFpp"), Double.class)); final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); @@ -118,7 +118,7 @@ private void insertFilterType(Record record) { final Field[] valueFields = { DSL.val(bloomTermId, ULong.class), DSL.val(record.getValue(BLOOMDB.FILTERTYPE.ID), ULong.class), - DSL.val(filterBAOSFromRecord(record), byte[].class) + DSL.val(filterBytesFromRecord(record), byte[].class) }; ctx.insertInto(namedTable).columns(insertFields).values(valueFields).execute(); } diff --git a/src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java b/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java similarity index 95% rename from src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java rename to src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java index f61a7da9..235de595 100644 --- a/src/main/java/com/teragrep/pth_06/planner/FiltersInserted.java +++ b/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java @@ -50,11 +50,11 @@ /** * Decorator that inserts category tables filter types into database */ -public final class FiltersInserted implements CategoryTable { +public final class WithFilterTypes implements CategoryTable { private final CategoryTable origin; - public FiltersInserted(final CategoryTable origin) { + public WithFilterTypes(final CategoryTable origin) { this.origin = origin; } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java index 3ef9043b..b706e02a 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java @@ -103,7 +103,7 @@ public Condition fromString(String inXml, boolean streamQuery) throws Exception } /** - * Set of all the tables that pattern matched with tokenized search terms the walkers has visited + * Set of all the tables that pattern matched with tokenized value search elements the walkers has traversed * * @return Set of Tables that had a pattern match */ @@ -166,7 +166,9 @@ Condition emitElem(final Element current) { new ConditionConfig(ctx, streamQuery, bloomEnabled, withoutFilters, bloomTermId) ); if (bloomQueryCondition.isBloomSearchCondition()) { - patternMatchTables().addAll(bloomQueryCondition.patternMatchTables()); + final Set> elementPatternMatchTables = bloomQueryCondition.patternMatchTables(); + // add tables condition found to walker pattern match tables + patternMatchTables().addAll(elementPatternMatchTables); bloomTermId++; } return bloomQueryCondition.condition(); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index 35f0f748..f18e06f3 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -96,8 +96,9 @@ public Condition condition() { Condition noBloomCondition = DSL.noCondition(); for (final Table table : tableSet) { + // create category temp table for this pattern match table final CategoryTable categoryTable = new Created( - new FiltersInserted(new CategoryTableImpl(config, table, tokenizedValue)) + new WithFilterTypes(new CategoryTableImpl(config, table, tokenizedValue)) ); final QueryCondition tableCondition = categoryTable.bloommatchCondition(); bloomCondition = bloomCondition.or(tableCondition.condition()); diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index ea61eec3..517f14d4 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -158,7 +158,7 @@ public void testCreatedWithEmptyTable() { .get(0); TokenizedValue val = new TokenizedValue("test"); - CategoryTable tempTable = new Created(new FiltersInserted(new CategoryTableImpl(ctx, table, 0L, val))); + CategoryTable tempTable = new Created(new WithFilterTypes(new CategoryTableImpl(ctx, table, 0L, val))); RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::bloommatchCondition); Assertions.assertEquals("Origin table was empty", ex.getMessage()); } From 0c3ffccb7d0d040dfc6f007356b9c0b05d79df61 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Wed, 18 Sep 2024 10:17:45 +0300 Subject: [PATCH 12/20] refactor ElementCondition to directly use IndexStatementCondition class to get pattern match tables --- .../teragrep/pth_06/planner/CategoryTableImpl.java | 9 +++++++-- .../com/teragrep/pth_06/planner/TableFilters.java | 14 +++++++------- .../walker/conditions/CategoryTableCondition.java | 9 +++++++-- .../walker/conditions/ElementCondition.java | 12 ++---------- .../teragrep/pth_06/planner/TableFiltersTest.java | 4 ++-- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java index 1cc60e55..ca8278d6 100644 --- a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java +++ b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java @@ -56,7 +56,7 @@ import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; /** - * Class to create a temp table that can create a bloommatch row condition to compare this filter bytes against origin + * Class to create a temp table of current search term and origin filter size * filter types. *

* Origin schema: @@ -146,9 +146,14 @@ public void create() { } public void insertFilterTypes() { - tableFilters.insert(); + tableFilters.insertIntoCategoryTable(); } + /** + * Row condition that selects the same sized filter arrays from this category table and the + * origin table. + * @return condition + */ public QueryCondition bloommatchCondition() { return tableCondition; } diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java index 91985e5f..dff54090 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -58,7 +58,7 @@ import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; /** - * Filter types of a table that can be inserted + * Filter types of a table that can be inserted into the tables category table */ public final class TableFilters { @@ -108,23 +108,23 @@ private byte[] filterBytesFromRecord(final Record record) { return filterBAOS.toByteArray(); } - private void insertFilterType(Record record) { - final Table namedTable = DSL.table(DSL.name(("term_" + bloomTermId + "_" + this.table.getName()))); + private void insertFilterRecordToCategoryTable(final Record record) { + final Table categoryTable = DSL.table(DSL.name(("term_" + bloomTermId + "_" + this.table.getName()))); final Field[] insertFields = { DSL.field("term_id", BIGINTUNSIGNED.nullable(false)), DSL.field("type_id", BIGINTUNSIGNED.nullable(false)), - DSL.field(DSL.name(namedTable.getName(), "filter"), byte[].class) + DSL.field(DSL.name(categoryTable.getName(), "filter"), byte[].class) }; final Field[] valueFields = { DSL.val(bloomTermId, ULong.class), DSL.val(record.getValue(BLOOMDB.FILTERTYPE.ID), ULong.class), DSL.val(filterBytesFromRecord(record), byte[].class) }; - ctx.insertInto(namedTable).columns(insertFields).values(valueFields).execute(); + ctx.insertInto(categoryTable).columns(insertFields).values(valueFields).execute(); } - public void insert() { - recordsInMetadata.toResult().forEach(this::insertFilterType); + public void insertIntoCategoryTable() { + recordsInMetadata.toResult().forEach(this::insertFilterRecordToCategoryTable); } /** diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java index 0c70576e..de4f1c62 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java @@ -51,6 +51,10 @@ import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; +/** + * Row condition that compares the compareTo tables bloom filter bytes against + * category table + */ public final class CategoryTableCondition implements QueryCondition { private final Table comparedTo; @@ -66,14 +70,15 @@ public Condition condition() { final Field termIdField = DSL.field("term_id", BIGINTUNSIGNED.nullable(false)); final Field typeIdField = DSL.field("type_id", BIGINTUNSIGNED.nullable(false)); final Field filterField = DSL.field(DSL.name(categoryTable.getName(), "filter"), byte[].class); + // select filter with correct bloom term id and filter type id from category table final SelectConditionStep> selectFilterStep = DSL .select(filterField) .from(categoryTable) .where(termIdField.eq(ULong.valueOf(bloomTermId))) .and(typeIdField.eq((Field) comparedTo.field("filter_type_id"))); - final Field filterColumn = selectFilterStep.asField(); + // compares category table filter byte[] against bloom filter byte[] final Condition filterFieldCondition = DSL - .function("bloommatch", Boolean.class, filterColumn, comparedTo.field("filter")) + .function("bloommatch", Boolean.class, selectFilterStep.asField(), comparedTo.field("filter")) .eq(true); // null check allows SQL to optimize query final Condition notNullCondition = comparedTo.field("filter").isNotNull(); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index c52822ff..da18b483 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -65,7 +65,6 @@ public final class ElementCondition implements BloomQueryCondition { private final ValidElement element; private final ConditionConfig config; - private final Set> tableSet; public ElementCondition(Element element, ConditionConfig config) { this(new ValidElement(element), config); @@ -74,7 +73,6 @@ public ElementCondition(Element element, ConditionConfig config) { public ElementCondition(ValidElement element, ConditionConfig config) { this.element = element; this.config = config; - this.tableSet = new HashSet<>(); } public Condition condition() { @@ -110,10 +108,6 @@ public Condition condition() { if ("indexstatement".equalsIgnoreCase(tag) && "EQUALS".equals(operation) && config.bloomEnabled()) { BloomQueryCondition indexStatementCondition = new IndexStatementCondition(value, config, condition); condition = indexStatementCondition.condition(); - Set> indexStatementMatches = indexStatementCondition.patternMatchTables(); - if (!indexStatementMatches.isEmpty()) { - tableSet.addAll(indexStatementMatches); - } } } // bloom search can return condition unmodified @@ -132,10 +126,8 @@ public boolean isBloomSearchCondition() { } public Set> patternMatchTables() { - if (tableSet.isEmpty()) { - condition(); - } - return tableSet; + final String value = element.value(); + return new IndexStatementCondition(value, config).patternMatchTables(); } @Override diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java index 47e7734e..d7eff384 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java @@ -139,7 +139,7 @@ public void testCreation() { } @Test - public void testInsert() { + public void testInsertIntoCategoryTable() { fillTargetTable(); DSLContext ctx = DSL.using(conn); Table table = ctx @@ -150,7 +150,7 @@ public void testInsert() { .get(0); DataAccessException exception = Assertions .assertThrows( - DataAccessException.class, () -> new TableFilters(ctx, table, 0L, new TokenizedValue("test")).insert() + DataAccessException.class, () -> new TableFilters(ctx, table, 0L, new TokenizedValue("test")).insertIntoCategoryTable() ); Assertions.assertTrue(exception.getMessage().contains("term_0_target\" (term_id, type_id, \"filter\")")); } From 0e00db073b0a094accf6aa5fb7ad3c6183271711 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Wed, 18 Sep 2024 10:54:03 +0300 Subject: [PATCH 13/20] Renaming and some comments --- .../com/teragrep/pth_06/planner/CategoryTable.java | 2 +- .../teragrep/pth_06/planner/CategoryTableImpl.java | 11 +++++------ .../java/com/teragrep/pth_06/planner/Created.java | 4 ++-- .../com/teragrep/pth_06/planner/TableFilters.java | 2 +- .../com/teragrep/pth_06/planner/WithFilterTypes.java | 6 +++--- .../walker/conditions/CategoryTableCondition.java | 3 +-- .../planner/walker/conditions/ElementCondition.java | 1 - .../com/teragrep/pth_06/planner/TableFiltersTest.java | 4 ++-- 8 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java b/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java index e9545f9f..f7b9618d 100644 --- a/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java +++ b/src/main/java/com/teragrep/pth_06/planner/CategoryTable.java @@ -51,7 +51,7 @@ public interface CategoryTable { void create(); - void insertFilterTypes(); + void insertFilters(); QueryCondition bloommatchCondition(); } diff --git a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java index ca8278d6..cef6e568 100644 --- a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java +++ b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java @@ -56,8 +56,7 @@ import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; /** - * Class to create a temp table of current search term and origin filter size - * filter types. + * Class to create a temp table of current search term and origin filter size filter types. *

* Origin schema: *

    @@ -145,13 +144,13 @@ public void create() { indexStep.execute(); } - public void insertFilterTypes() { - tableFilters.insertIntoCategoryTable(); + public void insertFilters() { + tableFilters.insertFiltersIntoCategoryTable(); } /** - * Row condition that selects the same sized filter arrays from this category table and the - * origin table. + * Row condition that selects the same sized filter arrays from this category table and the origin table. + * * @return condition */ public QueryCondition bloommatchCondition() { diff --git a/src/main/java/com/teragrep/pth_06/planner/Created.java b/src/main/java/com/teragrep/pth_06/planner/Created.java index 9a76d469..2d2af671 100644 --- a/src/main/java/com/teragrep/pth_06/planner/Created.java +++ b/src/main/java/com/teragrep/pth_06/planner/Created.java @@ -64,8 +64,8 @@ public void create() { } @Override - public void insertFilterTypes() { - origin.insertFilterTypes(); + public void insertFilters() { + origin.insertFilters(); } @Override diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java index dff54090..a1d9ca15 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -123,7 +123,7 @@ private void insertFilterRecordToCategoryTable(final Record record) { ctx.insertInto(categoryTable).columns(insertFields).values(valueFields).execute(); } - public void insertIntoCategoryTable() { + public void insertFiltersIntoCategoryTable() { recordsInMetadata.toResult().forEach(this::insertFilterRecordToCategoryTable); } diff --git a/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java b/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java index 235de595..3524a390 100644 --- a/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java +++ b/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java @@ -64,13 +64,13 @@ public void create() { } @Override - public void insertFilterTypes() { - origin.insertFilterTypes(); + public void insertFilters() { + origin.insertFilters(); } @Override public QueryCondition bloommatchCondition() { - insertFilterTypes(); + insertFilters(); return origin.bloommatchCondition(); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java index de4f1c62..6d328964 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableCondition.java @@ -52,8 +52,7 @@ import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; /** - * Row condition that compares the compareTo tables bloom filter bytes against - * category table + * Row condition that compares the compareTo tables bloom filter bytes against category table */ public final class CategoryTableCondition implements QueryCondition { diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index da18b483..60d57fc5 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -53,7 +53,6 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Element; -import java.util.HashSet; import java.util.Set; /** diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java index d7eff384..86d7c89f 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java @@ -139,7 +139,7 @@ public void testCreation() { } @Test - public void testInsertIntoCategoryTable() { + public void testInsertFiltersIntoCategoryTable() { fillTargetTable(); DSLContext ctx = DSL.using(conn); Table table = ctx @@ -150,7 +150,7 @@ public void testInsertIntoCategoryTable() { .get(0); DataAccessException exception = Assertions .assertThrows( - DataAccessException.class, () -> new TableFilters(ctx, table, 0L, new TokenizedValue("test")).insertIntoCategoryTable() + DataAccessException.class, () -> new TableFilters(ctx, table, 0L, new TokenizedValue("test")).insertFiltersIntoCategoryTable() ); Assertions.assertTrue(exception.getMessage().contains("term_0_target\" (term_id, type_id, \"filter\")")); } From 510ee97a14c1742f842ebdde2ef493dfccf830ff Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Fri, 20 Sep 2024 09:11:50 +0300 Subject: [PATCH 14/20] Remove decorators and use class methods, fix testing, clean equality test assertions --- .../com/teragrep/pth_06/planner/Created.java | 76 ------------------- .../pth_06/planner/WithFilterTypes.java | 76 ------------------- .../conditions/IndexStatementCondition.java | 6 +- .../pth_06/planner/CategoryTableImplTest.java | 31 +++++--- ...ableFilterTypesFromMetadataResultTest.java | 2 - .../pth_06/planner/TableFiltersTest.java | 2 - .../pth_06/planner/TokenizedValueTest.java | 3 + .../CategoryTableConditionTest.java | 3 - .../conditions/EarliestConditionTest.java | 3 - .../conditions/ElementConditionTest.java | 2 - .../walker/conditions/HostConditionTest.java | 3 - .../walker/conditions/IndexConditionTest.java | 2 - .../IndexStatementConditionTest.java | 3 - .../conditions/LatestConditionTest.java | 3 - .../conditions/PatternMatchConditionTest.java | 3 - .../conditions/SourceTypeConditionTest.java | 3 - .../walker/conditions/ValidElementTest.java | 3 - 17 files changed, 27 insertions(+), 197 deletions(-) delete mode 100644 src/main/java/com/teragrep/pth_06/planner/Created.java delete mode 100644 src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java diff --git a/src/main/java/com/teragrep/pth_06/planner/Created.java b/src/main/java/com/teragrep/pth_06/planner/Created.java deleted file mode 100644 index 2d2af671..00000000 --- a/src/main/java/com/teragrep/pth_06/planner/Created.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -package com.teragrep.pth_06.planner; - -import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; - -/** - * Decorator that creates category table - */ -public final class Created implements CategoryTable { - - private final CategoryTable origin; - - public Created(final CategoryTable origin) { - this.origin = origin; - } - - @Override - public void create() { - origin.create(); - } - - @Override - public void insertFilters() { - origin.insertFilters(); - } - - @Override - public QueryCondition bloommatchCondition() { - create(); - return origin.bloommatchCondition(); - } -} diff --git a/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java b/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java deleted file mode 100644 index 3524a390..00000000 --- a/src/main/java/com/teragrep/pth_06/planner/WithFilterTypes.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Teragrep Archive Datasource (pth_06) - * Copyright (C) 2021-2024 Suomen Kanuuna Oy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional permission under GNU Affero General Public License version 3 - * section 7 - * - * If you modify this Program, or any covered work, by linking or combining it - * with other code, such other code is not for that reason alone subject to any - * of the requirements of the GNU Affero GPL version 3 as long as this Program - * is the same Program as licensed from Suomen Kanuuna Oy without any additional - * modifications. - * - * Supplemented terms under GNU Affero General Public License version 3 - * section 7 - * - * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified - * versions must be marked as "Modified version of" The Program. - * - * Names of the licensors and authors may not be used for publicity purposes. - * - * No rights are granted for use of trade names, trademarks, or service marks - * which are in The Program if any. - * - * Licensee must indemnify licensors and authors for any liability that these - * contractual assumptions impose on licensors and authors. - * - * To the extent this program is licensed as part of the Commercial versions of - * Teragrep, the applicable Commercial License may apply to this file if you as - * a licensee so wish it. - */ -package com.teragrep.pth_06.planner; - -import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; - -/** - * Decorator that inserts category tables filter types into database - */ -public final class WithFilterTypes implements CategoryTable { - - private final CategoryTable origin; - - public WithFilterTypes(final CategoryTable origin) { - this.origin = origin; - } - - @Override - public void create() { - origin.create(); - } - - @Override - public void insertFilters() { - origin.insertFilters(); - } - - @Override - public QueryCondition bloommatchCondition() { - insertFilters(); - return origin.bloommatchCondition(); - } -} diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index f18e06f3..f128992a 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -97,9 +97,9 @@ public Condition condition() { for (final Table table : tableSet) { // create category temp table for this pattern match table - final CategoryTable categoryTable = new Created( - new WithFilterTypes(new CategoryTableImpl(config, table, tokenizedValue)) - ); + final CategoryTable categoryTable = new CategoryTableImpl(config, table, tokenizedValue); + categoryTable.create(); + categoryTable.insertFilters(); final QueryCondition tableCondition = categoryTable.bloommatchCondition(); bloomCondition = bloomCondition.or(tableCondition.condition()); noBloomCondition = noBloomCondition.and(table.field("filter").isNull()); diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index 517f14d4..8d6def82 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -158,8 +158,9 @@ public void testCreatedWithEmptyTable() { .get(0); TokenizedValue val = new TokenizedValue("test"); - CategoryTable tempTable = new Created(new WithFilterTypes(new CategoryTableImpl(ctx, table, 0L, val))); - RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::bloommatchCondition); + CategoryTable tempTable = new CategoryTableImpl(ctx, table, 0L, val); + tempTable.create(); + RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::insertFilters); Assertions.assertEquals("Origin table was empty", ex.getMessage()); } @@ -175,7 +176,8 @@ public void testCreation() { .get(0); TokenizedValue val = new TokenizedValue("test"); - CategoryTable created = new Created(new CategoryTableImpl(ctx, table, 0L, val)); + CategoryTable created = new CategoryTableImpl(ctx, table, 0L, val); + created.create(); Assertions .assertEquals(created.bloommatchCondition(), new CategoryTableImpl(ctx, table, 0L, val).bloommatchCondition()); } @@ -193,9 +195,22 @@ public void testConditionGeneration() { TokenizedValue val = new TokenizedValue("test"); CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 0L, val); - QueryCondition tableCond = tempTable.bloommatchCondition(); - QueryCondition expectedCond = new CategoryTableCondition(table, 0L); - Assertions.assertEquals(expectedCond, tableCond); + Condition tableCond = tempTable.bloommatchCondition().condition(); + String e = "(\n" + + " bloommatch(\n" + + " (\n" + + " select \"term_0_target\".\"filter\"\n" + + " from \"term_0_target\"\n" + + " where (\n" + + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + + " )\n" + + " ),\n" + + " \"bloomdb\".\"target\".\"filter\"\n" + + " ) = true\n" + + " and \"bloomdb\".\"target\".\"filter\" is not null\n" + + ")"; + Assertions.assertEquals(e, tableCond.toString()); } @Test @@ -234,7 +249,6 @@ public void testEquality() { CategoryTableImpl table1 = new CategoryTableImpl(ctx, target1, 1L, val); CategoryTableImpl table2 = new CategoryTableImpl(ctx, target2, 1L, val); Assertions.assertEquals(table1, table2); - Assertions.assertEquals(table2, table1); } @Test @@ -252,7 +266,6 @@ public void testDifferentTokenSetNotEquals() { CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 1L, val1); CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, val2); Assertions.assertNotEquals(table1, table2); - Assertions.assertNotEquals(table2, table1); } @Test @@ -269,7 +282,6 @@ public void testDifferentBloomTermNotEquals() { CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, val); CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, val); Assertions.assertNotEquals(table1, table2); - Assertions.assertNotEquals(table2, table1); } @Test @@ -287,7 +299,6 @@ public void testDifferentDSLContextNotEquals() { CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, val); CategoryTableImpl table2 = new CategoryTableImpl(ctx2, table, 0L, val); Assertions.assertNotEquals(table1, table2); - Assertions.assertNotEquals(table2, table1); } void fillTargetTable() { diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java index de2860ef..95a880a6 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java @@ -206,9 +206,7 @@ public void testNotEquals() { TableFilterTypesFromMetadata result2 = new TableFilterTypesFromMetadata(ctx, table, 1L); TableFilterTypesFromMetadata result3 = new TableFilterTypesFromMetadata(ctx, null, 0L); Assertions.assertNotEquals(result1, result2); - Assertions.assertNotEquals(result2, result1); Assertions.assertNotEquals(result1, result3); - Assertions.assertNotEquals(result1, null); } void insertSizedFilterIntoTargetTable(int filterTypeId) { diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java index 86d7c89f..9f903f65 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java @@ -169,7 +169,6 @@ public void testEquals() { TableFilters filter1 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); TableFilters filter2 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); Assertions.assertEquals(filter1, filter2); - Assertions.assertEquals(filter2, filter1); } @Test @@ -188,7 +187,6 @@ public void testNotEquals() { TableFilters filter3 = new TableFilters(ctx, table, 0L, new TokenizedValue("mest")); Assertions.assertNotEquals(filter1, filter2); Assertions.assertNotEquals(filter1, filter3); - Assertions.assertNotEquals(filter1, null); } void fillTargetTable() { diff --git a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java index 6a5c6113..c5bec969 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java @@ -49,6 +49,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -65,6 +67,7 @@ void testTokenization() { Assertions.assertTrue(tokens.contains("test")); Assertions.assertTrue(tokens.contains(".")); Assertions.assertTrue(tokens.contains("test.nest")); + Assertions.assertEquals(4, tokens.size()); } @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java index cf63ac01..8c088ebd 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java @@ -181,7 +181,6 @@ public void testEquality() { CategoryTableCondition cond1 = new CategoryTableCondition(target1, 1L); CategoryTableCondition cond2 = new CategoryTableCondition(target1, 1L); Assertions.assertEquals(cond1, cond2); - Assertions.assertEquals(cond2, cond1); cond1.condition(); Assertions.assertEquals(cond1, cond2); } @@ -200,8 +199,6 @@ public void testNonEquality() { CategoryTableCondition cond2 = new CategoryTableCondition(target1, 1L); CategoryTableCondition cond3 = new CategoryTableCondition(null, 1L); Assertions.assertNotEquals(cond1, cond2); - Assertions.assertNotEquals(cond2, cond1); - Assertions.assertNotEquals(cond1, null); Assertions.assertNotEquals(cond1, cond3); } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java index defd6787..352305f3 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/EarliestConditionTest.java @@ -72,7 +72,6 @@ void equalsTest() { eq1.condition(); EarliestCondition eq2 = new EarliestCondition("946677600"); Assertions.assertEquals(eq1, eq2); - Assertions.assertEquals(eq2, eq1); } @Test @@ -80,7 +79,5 @@ void notEqualsTest() { EarliestCondition eq1 = new EarliestCondition("946677600"); EarliestCondition notEq = new EarliestCondition("1000"); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); - Assertions.assertNotEquals(eq1, null); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java index 5288c943..f977a86f 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java @@ -210,10 +210,8 @@ void notEqualsTest() { BloomQueryCondition notEq = new ElementCondition(anotherElement, config); BloomQueryCondition notEq2 = new ElementCondition(element, streamConfig); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, notEq2); Assertions.assertNotEquals(notEq, notEq2); - Assertions.assertNotEquals(eq1, null); } @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java index e01e2f8e..91eb44c8 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/HostConditionTest.java @@ -90,7 +90,6 @@ void equalsTest() { eq3.condition(); HostCondition eq4 = new HostCondition("946677600", "EQUALS", true); Assertions.assertEquals(eq1, eq2); - Assertions.assertEquals(eq2, eq1); Assertions.assertEquals(eq3, eq4); } @@ -100,8 +99,6 @@ void notEqualsTest() { HostCondition notEq = new HostCondition("1000", "EQUALS", false); HostCondition notEq2 = new HostCondition("946677600", "EQUALS", true); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); - Assertions.assertNotEquals(eq1, null); Assertions.assertNotEquals(eq1, notEq2); Assertions.assertNotEquals(notEq, notEq2); } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java index 42b628d0..5913f1d6 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexConditionTest.java @@ -95,9 +95,7 @@ void notEqualsTest() { IndexCondition notEq = new IndexCondition("1000", "EQUALS", false); IndexCondition notEq2 = new IndexCondition("946677600", "EQUALS", true); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); Assertions.assertNotEquals(eq1, notEq2); Assertions.assertNotEquals(notEq, notEq2); - Assertions.assertNotEquals(eq1, null); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index 432a6d09..2dd46a0e 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -230,7 +230,6 @@ void equalsTest() { BloomQueryCondition eq1 = new IndexStatementCondition("946677600", mockConfig); BloomQueryCondition eq2 = new IndexStatementCondition("946677600", mockConfig); Assertions.assertEquals(eq1, eq2); - Assertions.assertEquals(eq2, eq1); } @Test @@ -238,8 +237,6 @@ void notEqualsTest() { BloomQueryCondition eq1 = new IndexStatementCondition("946677600", mockConfig); BloomQueryCondition notEq = new IndexStatementCondition("1000", mockConfig); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); - Assertions.assertNotEquals(eq1, null); } private void writeFilter(String tableName, int filterId) { diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java index 0fc7e6eb..7e8fc2f8 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/LatestConditionTest.java @@ -84,7 +84,6 @@ void equalsTest() { eq3.condition(); LatestCondition eq4 = new LatestCondition("946720800"); Assertions.assertEquals(eq1, eq2); - Assertions.assertEquals(eq2, eq1); Assertions.assertEquals(eq3, eq4); } @@ -93,7 +92,5 @@ void notEqualsTest() { LatestCondition eq1 = new LatestCondition("946720800"); LatestCondition notEq = new LatestCondition("1000"); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); - Assertions.assertNotEquals(eq1, null); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java index fde20cfa..505c10a2 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java @@ -79,8 +79,6 @@ void testEquality() { PatternMatchCondition cond1 = new PatternMatchCondition("test"); PatternMatchCondition cond2 = new PatternMatchCondition("test"); Assertions.assertEquals(cond1, cond2); - cond1.condition(); - Assertions.assertEquals(cond2, cond1); } @Test @@ -88,6 +86,5 @@ void testNotEquals() { PatternMatchCondition cond1 = new PatternMatchCondition("test"); PatternMatchCondition cond2 = new PatternMatchCondition("next"); Assertions.assertNotEquals(cond1, cond2); - Assertions.assertNotEquals(cond2, cond1); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java index 097e378a..1e0b8130 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/SourceTypeConditionTest.java @@ -86,7 +86,6 @@ void equalsTest() { eq3.condition(); SourceTypeCondition eq4 = new SourceTypeCondition("946677600", "EQUALS", true); Assertions.assertEquals(eq1, eq2); - Assertions.assertEquals(eq2, eq1); Assertions.assertEquals(eq3, eq4); } @@ -96,8 +95,6 @@ void notEqualsTest() { SourceTypeCondition notEq = new SourceTypeCondition("1000", "EQUALS", false); SourceTypeCondition notEq2 = new SourceTypeCondition("1000", "EQUALS", true); Assertions.assertNotEquals(eq1, notEq); - Assertions.assertNotEquals(notEq, eq1); - Assertions.assertNotEquals(eq1, null); Assertions.assertNotEquals(eq1, notEq2); Assertions.assertNotEquals(notEq, notEq2); } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java index 94685fb2..ea811cb8 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ValidElementTest.java @@ -100,7 +100,6 @@ void equalityTest() { ValidElement eq1 = new ValidElement(element); ValidElement eq2 = new ValidElement(element); Assertions.assertEquals(eq1, eq2); - Assertions.assertEquals(eq2, eq1); } @Test @@ -114,7 +113,6 @@ void notEqualValueTest() { ValidElement eq1 = new ValidElement(element1); ValidElement eq2 = new ValidElement(element2); Assertions.assertNotEquals(eq1, eq2); - Assertions.assertNotEquals(eq2, eq1); } @Test @@ -128,6 +126,5 @@ void notEqualOperationTest() { ValidElement eq1 = new ValidElement(element1); ValidElement eq2 = new ValidElement(element2); Assertions.assertNotEquals(eq1, eq2); - Assertions.assertNotEquals(eq2, eq1); } } From 0585e92dde20bb157b7dd0e36716eaf8c0d0a225 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Fri, 20 Sep 2024 09:12:21 +0300 Subject: [PATCH 15/20] apply spotless --- .../pth_06/planner/CategoryTableImplTest.java | 21 +++++-------------- .../pth_06/planner/TokenizedValueTest.java | 2 -- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index 8d6def82..4463cbcf 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -45,8 +45,6 @@ */ package com.teragrep.pth_06.planner; -import com.teragrep.pth_06.planner.walker.conditions.CategoryTableCondition; -import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; import org.apache.spark.util.sketch.BloomFilter; import org.jooq.Condition; import org.jooq.DSLContext; @@ -196,20 +194,11 @@ public void testConditionGeneration() { TokenizedValue val = new TokenizedValue("test"); CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 0L, val); Condition tableCond = tempTable.bloommatchCondition().condition(); - String e = "(\n" + - " bloommatch(\n" + - " (\n" + - " select \"term_0_target\".\"filter\"\n" + - " from \"term_0_target\"\n" + - " where (\n" + - " term_id = 0\n" + - " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + - " )\n" + - " ),\n" + - " \"bloomdb\".\"target\".\"filter\"\n" + - " ) = true\n" + - " and \"bloomdb\".\"target\".\"filter\" is not null\n" + - ")"; + String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_0_target\".\"filter\"\n" + + " from \"term_0_target\"\n" + " where (\n" + " term_id = 0\n" + + " and type_id = \"bloomdb\".\"target\".\"filter_type_id\"\n" + " )\n" + " ),\n" + + " \"bloomdb\".\"target\".\"filter\"\n" + " ) = true\n" + + " and \"bloomdb\".\"target\".\"filter\" is not null\n" + ")"; Assertions.assertEquals(e, tableCond.toString()); } diff --git a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java index c5bec969..b06fc1d6 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java @@ -49,8 +49,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; From e988a860c49d1c9bd27fb685d9fccdf8046637ee Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Fri, 20 Sep 2024 09:21:31 +0300 Subject: [PATCH 16/20] create testing patterns to Strings first add comments for clarity --- .../pth_06/planner/PatternMatchTablesTest.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java b/src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java index 770b3c1c..36aaa431 100644 --- a/src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/PatternMatchTablesTest.java @@ -67,13 +67,11 @@ public class PatternMatchTablesTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; final String password = ""; - final List patternList = new ArrayList<>( - Arrays - .asList( - "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", - "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" - ) - ); + // matches IPv4 + final String ipRegex = "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + // matches IPv4 starting with 255. + final String ipStartingWith255 = "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + final List patternList = new ArrayList<>(Arrays.asList(ipRegex, ipStartingWith255)); final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); @BeforeAll From 4cdfd50af2ffdf1efaaea6719112b6137c0e5184 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Tue, 24 Sep 2024 12:50:29 +0300 Subject: [PATCH 17/20] disable search term tokenization --- .../pth_06/planner/CategoryTableImpl.java | 8 ++--- .../pth_06/planner/PatternMatchTables.java | 6 +--- .../teragrep/pth_06/planner/TableFilters.java | 14 ++++---- .../conditions/IndexStatementCondition.java | 6 ++-- .../conditions/PatternMatchCondition.java | 29 +++------------- .../pth_06/planner/CategoryTableImplTest.java | 34 ++++++++----------- .../pth_06/planner/TableFiltersTest.java | 16 ++++----- .../pth_06/planner/TokenizedValueTest.java | 2 -- .../conditions/PatternMatchConditionTest.java | 2 ++ 9 files changed, 42 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java index cef6e568..3c0a1c7a 100644 --- a/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java +++ b/src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java @@ -91,23 +91,23 @@ public final class CategoryTableImpl implements CategoryTable { private final CategoryTableCondition tableCondition; private final TableFilters tableFilters; - public CategoryTableImpl(ConditionConfig config, Table originTable, TokenizedValue tokenizedValue) { + public CategoryTableImpl(ConditionConfig config, Table originTable, String value) { this( config.context(), originTable, config.bloomTermId(), new CategoryTableCondition(originTable, config.bloomTermId()), - new TableFilters(config.context(), originTable, config.bloomTermId(), tokenizedValue) + new TableFilters(config.context(), originTable, config.bloomTermId(), value) ); } - public CategoryTableImpl(DSLContext ctx, Table originTable, long bloomTermId, TokenizedValue tokenizedValue) { + public CategoryTableImpl(DSLContext ctx, Table originTable, long bloomTermId, String value) { this( ctx, originTable, bloomTermId, new CategoryTableCondition(originTable, bloomTermId), - new TableFilters(ctx, originTable, bloomTermId, tokenizedValue) + new TableFilters(ctx, originTable, bloomTermId, value) ); } diff --git a/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java b/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java index 91654674..94a7fe7f 100644 --- a/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java +++ b/src/main/java/com/teragrep/pth_06/planner/PatternMatchTables.java @@ -69,11 +69,7 @@ public final class PatternMatchTables { private final QueryCondition patternMatchCondition; public PatternMatchTables(DSLContext ctx, String pattern) { - this(ctx, new PatternMatchCondition(new TokenizedValue(pattern))); - } - - public PatternMatchTables(DSLContext ctx, TokenizedValue tokenizedValue) { - this(ctx, new PatternMatchCondition(tokenizedValue)); + this(ctx, new PatternMatchCondition(pattern)); } public PatternMatchTables(DSLContext ctx, PatternMatchCondition patternMatchCondition) { diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java index a1d9ca15..8f7c9217 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -65,24 +65,24 @@ public final class TableFilters { private final DSLContext ctx; private final Table table; private final long bloomTermId; - private final TokenizedValue tokenizedValue; + private final String value; private final TableRecords recordsInMetadata; - public TableFilters(DSLContext ctx, Table table, long bloomTermId, TokenizedValue tokenizedValue) { - this(ctx, table, bloomTermId, tokenizedValue, new TableFilterTypesFromMetadata(ctx, table, bloomTermId)); + public TableFilters(DSLContext ctx, Table table, long bloomTermId, String value) { + this(ctx, table, bloomTermId, value, new TableFilterTypesFromMetadata(ctx, table, bloomTermId)); } public TableFilters( DSLContext ctx, Table table, long bloomTermId, - TokenizedValue tokenizedValue, + String value, TableFilterTypesFromMetadata recordsInMetadata ) { this.ctx = ctx; this.table = table; this.bloomTermId = bloomTermId; - this.tokenizedValue = tokenizedValue; + this.value = value; this.recordsInMetadata = recordsInMetadata; } @@ -96,7 +96,7 @@ private byte[] filterBytesFromRecord(final Record record) { final ULong expected = record.getValue(DSL.field(DSL.name(table.getName(), "expectedElements"), ULong.class)); final Double fpp = record.getValue(DSL.field(DSL.name(table.getName(), "targetFpp"), Double.class)); final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); - tokenizedValue.tokens().forEach(token -> filter.put(token.toString())); + filter.put(value); final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); try { filter.writeTo(filterBAOS); @@ -142,7 +142,7 @@ public boolean equals(final Object object) { if (object.getClass() != this.getClass()) return false; final TableFilters cast = (TableFilters) object; - return this.ctx == cast.ctx && this.tokenizedValue.equals(cast.tokenizedValue) && this.table.equals(cast.table) + return this.ctx == cast.ctx && this.value.equals(cast.value) && this.table.equals(cast.table) && this.bloomTermId == cast.bloomTermId; } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index f128992a..0a0f9acc 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -82,10 +82,8 @@ public Condition condition() { return condition; } Condition newCondition = condition; - LOGGER.info("indexstatement reached with search term <{}>", value); - final TokenizedValue tokenizedValue = new TokenizedValue(value); if (tableSet.isEmpty()) { - PatternMatchTables patternMatchTables = new PatternMatchTables(config.context(), tokenizedValue); + PatternMatchTables patternMatchTables = new PatternMatchTables(config.context(), value); tableSet.addAll(patternMatchTables.toList()); } if (!tableSet.isEmpty()) { @@ -97,7 +95,7 @@ public Condition condition() { for (final Table table : tableSet) { // create category temp table for this pattern match table - final CategoryTable categoryTable = new CategoryTableImpl(config, table, tokenizedValue); + final CategoryTable categoryTable = new CategoryTableImpl(config, table, value); categoryTable.create(); categoryTable.insertFilters(); final QueryCondition tableCondition = categoryTable.bloommatchCondition(); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java index a3348439..fc847c53 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java @@ -45,13 +45,9 @@ */ package com.teragrep.pth_06.planner.walker.conditions; -import com.teragrep.blf_01.Token; -import com.teragrep.pth_06.planner.TokenizedValue; import org.jooq.*; import org.jooq.impl.DSL; -import java.util.Set; - import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; /** @@ -61,30 +57,15 @@ */ public final class PatternMatchCondition implements QueryCondition { - private final TokenizedValue tokenizedValue; + private final String value; public PatternMatchCondition(String value) { - this(new TokenizedValue(value)); - } - - public PatternMatchCondition(TokenizedValue tokenizedValue) { - this.tokenizedValue = tokenizedValue; + this.value = value; } - /** - * tokens = ['one, 'two'] -> ('one' regex like BLOOMDB.FILTERTYPE.PATTERN).or('two' regex like - * BLOOMDB.FILTERTYPE.PATTERN) - * - * @return combined condition regex matching any of the tokens against filtertype.pattern - */ public Condition condition() { - final Set tokenSet = tokenizedValue.tokens(); - Condition patternCondition = DSL.noCondition(); - for (Token token : tokenSet) { - Field tokenStringField = DSL.val(token.toString()); - patternCondition = patternCondition.or(tokenStringField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN)); - } - return patternCondition; + final Field valueField = DSL.val(value); + return valueField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN); } @Override @@ -96,6 +77,6 @@ public boolean equals(final Object object) { if (object.getClass() != this.getClass()) return false; final PatternMatchCondition cast = (PatternMatchCondition) object; - return this.tokenizedValue.equals(cast.tokenizedValue); + return this.value.equals(cast.value); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index 4463cbcf..b2ae2359 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -141,8 +141,7 @@ public void testNonCreatedEmptyTable() { .getTables() .get(0); - TokenizedValue val = new TokenizedValue("test"); - Assertions.assertDoesNotThrow(new CategoryTableImpl(ctx, table, 0L, val)::bloommatchCondition); + Assertions.assertDoesNotThrow(new CategoryTableImpl(ctx, table, 0L, "test")::bloommatchCondition); } @Test @@ -155,8 +154,7 @@ public void testCreatedWithEmptyTable() { .getTables() .get(0); - TokenizedValue val = new TokenizedValue("test"); - CategoryTable tempTable = new CategoryTableImpl(ctx, table, 0L, val); + CategoryTable tempTable = new CategoryTableImpl(ctx, table, 0L, "test"); tempTable.create(); RuntimeException ex = Assertions.assertThrows(RuntimeException.class, tempTable::insertFilters); Assertions.assertEquals("Origin table was empty", ex.getMessage()); @@ -173,11 +171,10 @@ public void testCreation() { .getTables() .get(0); - TokenizedValue val = new TokenizedValue("test"); - CategoryTable created = new CategoryTableImpl(ctx, table, 0L, val); + CategoryTable created = new CategoryTableImpl(ctx, table, 0L, "test"); created.create(); Assertions - .assertEquals(created.bloommatchCondition(), new CategoryTableImpl(ctx, table, 0L, val).bloommatchCondition()); + .assertEquals(created.bloommatchCondition(), new CategoryTableImpl(ctx, table, 0L, "test").bloommatchCondition()); } @Test @@ -192,7 +189,7 @@ public void testConditionGeneration() { .get(0); TokenizedValue val = new TokenizedValue("test"); - CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 0L, val); + CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 0L, "test"); Condition tableCond = tempTable.bloommatchCondition().condition(); String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_0_target\".\"filter\"\n" + " from \"term_0_target\"\n" + " where (\n" + " term_id = 0\n" @@ -213,7 +210,7 @@ public void testBloomTerm() { .getTables() .get(0); TokenizedValue val = new TokenizedValue("test"); - CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 1L, val); + CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 1L, "test"); Condition condition = tempTable.bloommatchCondition().condition(); Assertions.assertTrue(condition.toString().contains("term_1_")); } @@ -235,8 +232,8 @@ public void testEquality() { .getTables() .get(0); TokenizedValue val = new TokenizedValue("one"); - CategoryTableImpl table1 = new CategoryTableImpl(ctx, target1, 1L, val); - CategoryTableImpl table2 = new CategoryTableImpl(ctx, target2, 1L, val); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, target1, 1L, "one"); + CategoryTableImpl table2 = new CategoryTableImpl(ctx, target2, 1L, "one"); Assertions.assertEquals(table1, table2); } @@ -250,10 +247,8 @@ public void testDifferentTokenSetNotEquals() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - TokenizedValue val1 = new TokenizedValue("one"); - TokenizedValue val2 = new TokenizedValue("two"); - CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 1L, val1); - CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, val2); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 1L, "one"); + CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, "two"); Assertions.assertNotEquals(table1, table2); } @@ -267,9 +262,8 @@ public void testDifferentBloomTermNotEquals() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - TokenizedValue val = new TokenizedValue("one"); - CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, val); - CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, val); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, "one"); + CategoryTableImpl table2 = new CategoryTableImpl(ctx, table, 1L, "one"); Assertions.assertNotEquals(table1, table2); } @@ -285,8 +279,8 @@ public void testDifferentDSLContextNotEquals() { .getTables() .get(0); TokenizedValue val = new TokenizedValue("one"); - CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, val); - CategoryTableImpl table2 = new CategoryTableImpl(ctx2, table, 0L, val); + CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, "one"); + CategoryTableImpl table2 = new CategoryTableImpl(ctx2, table, 0L, "one"); Assertions.assertNotEquals(table1, table2); } diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java index 9f903f65..1f9a651d 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java @@ -135,7 +135,7 @@ public void testCreation() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - Assertions.assertDoesNotThrow(() -> new TableFilters(ctx, table, 0L, new TokenizedValue("test"))); + Assertions.assertDoesNotThrow(() -> new TableFilters(ctx, table, 0L, "test")); } @Test @@ -149,9 +149,7 @@ public void testInsertFiltersIntoCategoryTable() { .getTables() .get(0); DataAccessException exception = Assertions - .assertThrows( - DataAccessException.class, () -> new TableFilters(ctx, table, 0L, new TokenizedValue("test")).insertFiltersIntoCategoryTable() - ); + .assertThrows(DataAccessException.class, () -> new TableFilters(ctx, table, 0L, "test").insertFiltersIntoCategoryTable()); Assertions.assertTrue(exception.getMessage().contains("term_0_target\" (term_id, type_id, \"filter\")")); } @@ -166,8 +164,8 @@ public void testEquals() { .getTables() .get(0); - TableFilters filter1 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); - TableFilters filter2 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); + TableFilters filter1 = new TableFilters(ctx, table, 0L, "test"); + TableFilters filter2 = new TableFilters(ctx, table, 0L, "test"); Assertions.assertEquals(filter1, filter2); } @@ -182,9 +180,9 @@ public void testNotEquals() { .getTables() .get(0); - TableFilters filter1 = new TableFilters(ctx, table, 0L, new TokenizedValue("test")); - TableFilters filter2 = new TableFilters(ctx, table, 1L, new TokenizedValue("test")); - TableFilters filter3 = new TableFilters(ctx, table, 0L, new TokenizedValue("mest")); + TableFilters filter1 = new TableFilters(ctx, table, 0L, "test"); + TableFilters filter2 = new TableFilters(ctx, table, 1L, "test"); + TableFilters filter3 = new TableFilters(ctx, table, 0L, "mest"); Assertions.assertNotEquals(filter1, filter2); Assertions.assertNotEquals(filter1, filter3); } diff --git a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java index b06fc1d6..3536b6d5 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java @@ -52,8 +52,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.junit.jupiter.api.Assertions.*; - class TokenizedValueTest { @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java index 505c10a2..4c92f8b7 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java @@ -47,6 +47,7 @@ import org.jooq.Condition; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** @@ -65,6 +66,7 @@ void testSingleToken() { } @Test + @Disabled("Search term tokenization is not enabled in this version") void testMultipleTokens() { Condition condition = new PatternMatchCondition("test.nest").condition(); String e = "(\n" + " ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" From b0ce41933bcba681abcd5ea346d971c87ac1c777 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Tue, 24 Sep 2024 13:53:45 +0300 Subject: [PATCH 18/20] clean up code and separate condition interfaces, use decorators for category table building and remove interfaces from tests --- .../pth_06/planner/CreatedCategoryTable.java | 76 +++++++++++++++++++ .../planner/SearchTermFiltersInserted.java | 76 +++++++++++++++++++ .../planner/walker/ConditionWalker.java | 9 +-- .../conditions/BloomQueryCondition.java | 3 - .../walker/conditions/ElementCondition.java | 6 +- .../conditions/IndexStatementCondition.java | 26 +++---- .../pth_06/planner/CategoryTableImplTest.java | 10 +-- .../conditions/ElementConditionTest.java | 36 ++++----- .../IndexStatementConditionTest.java | 24 +++--- 9 files changed, 202 insertions(+), 64 deletions(-) create mode 100644 src/main/java/com/teragrep/pth_06/planner/CreatedCategoryTable.java create mode 100644 src/main/java/com/teragrep/pth_06/planner/SearchTermFiltersInserted.java diff --git a/src/main/java/com/teragrep/pth_06/planner/CreatedCategoryTable.java b/src/main/java/com/teragrep/pth_06/planner/CreatedCategoryTable.java new file mode 100644 index 00000000..86a67441 --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/CreatedCategoryTable.java @@ -0,0 +1,76 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; + +/** + * Decorator that inserts category tables filter types into database + */ +public final class CreatedCategoryTable implements CategoryTable { + + private final CategoryTable origin; + + public CreatedCategoryTable(final CategoryTable origin) { + this.origin = origin; + } + + @Override + public void create() { + origin.create(); + } + + @Override + public void insertFilters() { + origin.insertFilters(); + } + + @Override + public QueryCondition bloommatchCondition() { + create(); + return origin.bloommatchCondition(); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/SearchTermFiltersInserted.java b/src/main/java/com/teragrep/pth_06/planner/SearchTermFiltersInserted.java new file mode 100644 index 00000000..a214b22c --- /dev/null +++ b/src/main/java/com/teragrep/pth_06/planner/SearchTermFiltersInserted.java @@ -0,0 +1,76 @@ +/* + * Teragrep Archive Datasource (pth_06) + * Copyright (C) 2021-2024 Suomen Kanuuna Oy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * + * Additional permission under GNU Affero General Public License version 3 + * section 7 + * + * If you modify this Program, or any covered work, by linking or combining it + * with other code, such other code is not for that reason alone subject to any + * of the requirements of the GNU Affero GPL version 3 as long as this Program + * is the same Program as licensed from Suomen Kanuuna Oy without any additional + * modifications. + * + * Supplemented terms under GNU Affero General Public License version 3 + * section 7 + * + * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified + * versions must be marked as "Modified version of" The Program. + * + * Names of the licensors and authors may not be used for publicity purposes. + * + * No rights are granted for use of trade names, trademarks, or service marks + * which are in The Program if any. + * + * Licensee must indemnify licensors and authors for any liability that these + * contractual assumptions impose on licensors and authors. + * + * To the extent this program is licensed as part of the Commercial versions of + * Teragrep, the applicable Commercial License may apply to this file if you as + * a licensee so wish it. + */ +package com.teragrep.pth_06.planner; + +import com.teragrep.pth_06.planner.walker.conditions.QueryCondition; + +/** + * Decorator that inserts category tables filter types into database + */ +public final class SearchTermFiltersInserted implements CategoryTable { + + private final CategoryTable origin; + + public SearchTermFiltersInserted(final CategoryTable origin) { + this.origin = origin; + } + + @Override + public void create() { + origin.create(); + } + + @Override + public void insertFilters() { + origin.insertFilters(); + } + + @Override + public QueryCondition bloommatchCondition() { + insertFilters(); + return origin.bloommatchCondition(); + } +} diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java index b706e02a..24ceffd1 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/ConditionWalker.java @@ -46,7 +46,6 @@ package com.teragrep.pth_06.planner.walker; import com.teragrep.pth_06.config.ConditionConfig; -import com.teragrep.pth_06.planner.walker.conditions.BloomQueryCondition; import com.teragrep.pth_06.planner.walker.conditions.ElementCondition; import com.teragrep.pth_06.planner.walker.conditions.ValidElement; import org.jooq.Condition; @@ -161,16 +160,16 @@ public Condition emitUnaryOperation(String op, Element current) throws Exception } Condition emitElem(final Element current) { - final BloomQueryCondition bloomQueryCondition = new ElementCondition( + final ElementCondition elementCondition = new ElementCondition( new ValidElement(current), new ConditionConfig(ctx, streamQuery, bloomEnabled, withoutFilters, bloomTermId) ); - if (bloomQueryCondition.isBloomSearchCondition()) { - final Set> elementPatternMatchTables = bloomQueryCondition.patternMatchTables(); + if (elementCondition.isBloomSearchCondition()) { + final Set> elementPatternMatchTables = elementCondition.patternMatchTables(); // add tables condition found to walker pattern match tables patternMatchTables().addAll(elementPatternMatchTables); bloomTermId++; } - return bloomQueryCondition.condition(); + return elementCondition.condition(); } } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java index e8017083..198260c3 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/BloomQueryCondition.java @@ -45,15 +45,12 @@ */ package com.teragrep.pth_06.planner.walker.conditions; -import org.jooq.Condition; import org.jooq.Table; import java.util.Set; public interface BloomQueryCondition { - Condition condition(); - boolean isBloomSearchCondition(); Set> patternMatchTables(); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java index 60d57fc5..51adb310 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/ElementCondition.java @@ -58,7 +58,7 @@ /** * Creates a query condition from provided dom element */ -public final class ElementCondition implements BloomQueryCondition { +public final class ElementCondition implements QueryCondition, BloomQueryCondition { private static final Logger LOGGER = LoggerFactory.getLogger(ElementCondition.class); @@ -105,8 +105,8 @@ public Condition condition() { } // value search if ("indexstatement".equalsIgnoreCase(tag) && "EQUALS".equals(operation) && config.bloomEnabled()) { - BloomQueryCondition indexStatementCondition = new IndexStatementCondition(value, config, condition); - condition = indexStatementCondition.condition(); + QueryCondition indexStatement = new IndexStatementCondition(value, config, condition); + condition = indexStatement.condition(); } } // bloom search can return condition unmodified diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index 0a0f9acc..4002e8b6 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -83,31 +83,27 @@ public Condition condition() { } Condition newCondition = condition; if (tableSet.isEmpty()) { - PatternMatchTables patternMatchTables = new PatternMatchTables(config.context(), value); + final PatternMatchTables patternMatchTables = new PatternMatchTables(config.context(), value); tableSet.addAll(patternMatchTables.toList()); } if (!tableSet.isEmpty()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Found pattern match on <{}> table(s)", tableSet.size()); } - Condition bloomCondition = DSL.noCondition(); - Condition noBloomCondition = DSL.noCondition(); + Condition combinedTableCondition = DSL.noCondition(); + Condition combinedNullFilterCondition = DSL.noCondition(); for (final Table table : tableSet) { - // create category temp table for this pattern match table - final CategoryTable categoryTable = new CategoryTableImpl(config, table, value); - categoryTable.create(); - categoryTable.insertFilters(); + final CategoryTable categoryTable = new CreatedCategoryTable( + new SearchTermFiltersInserted(new CategoryTableImpl(config, table, value)) + ); + final Condition nullFilterCondition = table.field("filter").isNull(); final QueryCondition tableCondition = categoryTable.bloommatchCondition(); - bloomCondition = bloomCondition.or(tableCondition.condition()); - noBloomCondition = noBloomCondition.and(table.field("filter").isNull()); - } - if (config.withoutFilters()) { - newCondition = noBloomCondition; - } - else { - newCondition = bloomCondition.or(noBloomCondition); + combinedTableCondition = combinedTableCondition.or(tableCondition.condition()); + combinedNullFilterCondition = combinedNullFilterCondition.and(nullFilterCondition); } + newCondition = config.withoutFilters() ? combinedNullFilterCondition : combinedTableCondition + .or(combinedNullFilterCondition); } return newCondition; } diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index b2ae2359..0aa7bffe 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -171,10 +171,8 @@ public void testCreation() { .getTables() .get(0); - CategoryTable created = new CategoryTableImpl(ctx, table, 0L, "test"); - created.create(); - Assertions - .assertEquals(created.bloommatchCondition(), new CategoryTableImpl(ctx, table, 0L, "test").bloommatchCondition()); + CategoryTable categoryTable = new CategoryTableImpl(ctx, table, 0L, "test"); + Assertions.assertDoesNotThrow(categoryTable::create); } @Test @@ -188,7 +186,6 @@ public void testConditionGeneration() { .getTables() .get(0); - TokenizedValue val = new TokenizedValue("test"); CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 0L, "test"); Condition tableCond = tempTable.bloommatchCondition().condition(); String e = "(\n" + " bloommatch(\n" + " (\n" + " select \"term_0_target\".\"filter\"\n" @@ -209,7 +206,6 @@ public void testBloomTerm() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - TokenizedValue val = new TokenizedValue("test"); CategoryTableImpl tempTable = new CategoryTableImpl(ctx, table, 1L, "test"); Condition condition = tempTable.bloommatchCondition().condition(); Assertions.assertTrue(condition.toString().contains("term_1_")); @@ -231,7 +227,6 @@ public void testEquality() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - TokenizedValue val = new TokenizedValue("one"); CategoryTableImpl table1 = new CategoryTableImpl(ctx, target1, 1L, "one"); CategoryTableImpl table2 = new CategoryTableImpl(ctx, target2, 1L, "one"); Assertions.assertEquals(table1, table2); @@ -278,7 +273,6 @@ public void testDifferentDSLContextNotEquals() { .filterTables(t -> !t.getName().equals("filtertype")) .getTables() .get(0); - TokenizedValue val = new TokenizedValue("one"); CategoryTableImpl table1 = new CategoryTableImpl(ctx, table, 0L, "one"); CategoryTableImpl table2 = new CategoryTableImpl(ctx2, table, 0L, "one"); Assertions.assertNotEquals(table1, table2); diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java index f977a86f..30f614ed 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/ElementConditionTest.java @@ -94,8 +94,8 @@ void testStreamTags() { void testProvidedElementMissingValue() { Element element = document.createElement("test"); element.setAttribute("operation", "EQUALS"); - BloomQueryCondition elementCondition = new ElementCondition(element, config); - BloomQueryCondition streamElementCondition = new ElementCondition(element, streamConfig); + ElementCondition elementCondition = new ElementCondition(element, config); + ElementCondition streamElementCondition = new ElementCondition(element, streamConfig); Assertions.assertThrows(IllegalStateException.class, elementCondition::condition); Assertions.assertThrows(IllegalStateException.class, streamElementCondition::condition); } @@ -104,8 +104,8 @@ void testProvidedElementMissingValue() { void testProvidedElementMissingOperation() { Element element = document.createElement("test"); element.setAttribute("value", "1000"); - BloomQueryCondition elementCondition = new ElementCondition(element, config); - BloomQueryCondition streamElementCondition = new ElementCondition(element, streamConfig); + ElementCondition elementCondition = new ElementCondition(element, config); + ElementCondition streamElementCondition = new ElementCondition(element, streamConfig); Assertions.assertThrows(IllegalStateException.class, elementCondition::condition); Assertions.assertThrows(IllegalStateException.class, streamElementCondition::condition); } @@ -118,14 +118,14 @@ void testIsIndexStatement() { Element element2 = document.createElement("index"); element2.setAttribute("value", "searchTerm"); element2.setAttribute("operation", "EQUALS"); - BloomQueryCondition condition = new ElementCondition(element, config); + ElementCondition condition = new ElementCondition(element, config); Assertions.assertTrue(condition.isBloomSearchCondition()); element.setAttribute("operation", "NOT_EQUALS"); - BloomQueryCondition condition2 = new ElementCondition(element, config); + ElementCondition condition2 = new ElementCondition(element, config); Assertions.assertFalse(condition2.isBloomSearchCondition()); - BloomQueryCondition condition3 = new ElementCondition(element, streamConfig); + ElementCondition condition3 = new ElementCondition(element, streamConfig); Assertions.assertFalse(condition3.isBloomSearchCondition()); - BloomQueryCondition condition4 = new ElementCondition(element2, streamConfig); + ElementCondition condition4 = new ElementCondition(element2, streamConfig); Assertions.assertFalse(condition4.isBloomSearchCondition()); } @@ -134,7 +134,7 @@ void testIndexStatementWithBadConnection() { Element element = document.createElement("indexstatement"); element.setAttribute("value", "searchTerm"); element.setAttribute("operation", "EQUALS"); - BloomQueryCondition condition = new ElementCondition(element, config); + ElementCondition condition = new ElementCondition(element, config); Assertions.assertTrue(condition.isBloomSearchCondition()); Assertions.assertThrows(DataAccessException.class, condition::condition); } @@ -192,9 +192,9 @@ void equalsTest() { Element element = document.createElement("index"); element.setAttribute("value", "f17"); element.setAttribute("operation", "EQUALS"); - BloomQueryCondition eq1 = new ElementCondition(element, config); + ElementCondition eq1 = new ElementCondition(element, config); eq1.condition(); - BloomQueryCondition eq2 = new ElementCondition(element, config); + ElementCondition eq2 = new ElementCondition(element, config); Assertions.assertEquals(eq1, eq2); } @@ -206,9 +206,9 @@ void notEqualsTest() { Element anotherElement = document.createElement("index"); anotherElement.setAttribute("value", "f11"); anotherElement.setAttribute("operation", "EQUALS"); - BloomQueryCondition eq1 = new ElementCondition(element, config); - BloomQueryCondition notEq = new ElementCondition(anotherElement, config); - BloomQueryCondition notEq2 = new ElementCondition(element, streamConfig); + ElementCondition eq1 = new ElementCondition(element, config); + ElementCondition notEq = new ElementCondition(anotherElement, config); + ElementCondition notEq2 = new ElementCondition(element, streamConfig); Assertions.assertNotEquals(eq1, notEq); Assertions.assertNotEquals(eq1, notEq2); Assertions.assertNotEquals(notEq, notEq2); @@ -223,8 +223,8 @@ void notEqualsDifferentConfigTest() { DSLContext ctx = DSL.using(conn); ConditionConfig cfg1 = new ConditionConfig(ctx, false); ConditionConfig cfg2 = new ConditionConfig(ctx, true); - BloomQueryCondition eq = new ElementCondition(element, cfg1); - BloomQueryCondition notEq = new ElementCondition(element, cfg2); + ElementCondition eq = new ElementCondition(element, cfg1); + ElementCondition notEq = new ElementCondition(element, cfg2); Assertions.assertNotEquals(eq, notEq); } @@ -239,8 +239,8 @@ void notEqualsDifferentConnectionTest() { DSLContext ctx2 = DSL.using(conn2); ConditionConfig cfg1 = new ConditionConfig(ctx, false); ConditionConfig cfg2 = new ConditionConfig(ctx2, false); - BloomQueryCondition eq = new ElementCondition(element, cfg1); - BloomQueryCondition notEq = new ElementCondition(element, cfg2); + ElementCondition eq = new ElementCondition(element, cfg1); + ElementCondition notEq = new ElementCondition(element, cfg2); Assertions.assertNotEquals(eq, notEq); } } diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index 2dd46a0e..70f48f7d 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -145,8 +145,8 @@ void testConnectionException() { DSLContext ctx = DSL.using(new MockConnection(c -> new MockResult[0])); ConditionConfig config = new ConditionConfig(ctx, false, true); ConditionConfig noBloomConfig = new ConditionConfig(ctx, false); - BloomQueryCondition cond1 = new IndexStatementCondition("test", config, DSL.trueCondition()); - BloomQueryCondition cond2 = new IndexStatementCondition("test", noBloomConfig, DSL.trueCondition()); + IndexStatementCondition cond1 = new IndexStatementCondition("test", config, DSL.trueCondition()); + IndexStatementCondition cond2 = new IndexStatementCondition("test", noBloomConfig, DSL.trueCondition()); Assertions.assertThrows(DataAccessException.class, cond1::condition); Assertions.assertDoesNotThrow(cond2::condition); } @@ -158,8 +158,8 @@ void noMatchesTest() { Condition e2 = DSL.trueCondition(); ConditionConfig config = new ConditionConfig(ctx, false, true); ConditionConfig withoutFiltersConfig = new ConditionConfig(ctx, false, true, true, 1L); - BloomQueryCondition cond1 = new IndexStatementCondition("test", config, e1); - BloomQueryCondition cond2 = new IndexStatementCondition("test", withoutFiltersConfig, e2); + IndexStatementCondition cond1 = new IndexStatementCondition("test", config, e1); + IndexStatementCondition cond2 = new IndexStatementCondition("test", withoutFiltersConfig, e2); Assertions.assertEquals(e1, cond1.condition()); Assertions.assertEquals(e2, cond2.condition()); Assertions.assertTrue(cond1.patternMatchTables().isEmpty()); @@ -170,7 +170,7 @@ void noMatchesTest() { void oneMatchingTableTest() { DSLContext ctx = DSL.using(conn); ConditionConfig config = new ConditionConfig(ctx, false, true); - BloomQueryCondition cond = new IndexStatementCondition("192.168.1.1", config); + IndexStatementCondition cond = new IndexStatementCondition("192.168.1.1", config); String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip\".\"filter\"\n" + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" @@ -186,7 +186,7 @@ void oneMatchingTableTest() { void testOneMatchWithoutFilters() { DSLContext ctx = DSL.using(conn); ConditionConfig config = new ConditionConfig(ctx, false, true, true); - BloomQueryCondition cond = new IndexStatementCondition("192.168.1.1", config); + IndexStatementCondition cond = new IndexStatementCondition("192.168.1.1", config); String e = "\"bloomdb\".\"pattern_test_ip\".\"filter\" is null"; Assertions.assertEquals(e, cond.condition().toString()); Assertions.assertEquals(1, cond.patternMatchTables().size()); @@ -196,7 +196,7 @@ void testOneMatchWithoutFilters() { void testTwoMatchWithoutFilters() { DSLContext ctx = DSL.using(conn); ConditionConfig config = new ConditionConfig(ctx, false, true, true); - BloomQueryCondition cond = new IndexStatementCondition("255.255.255.255", config); + IndexStatementCondition cond = new IndexStatementCondition("255.255.255.255", config); String e = "(\n" + " \"bloomdb\".\"pattern_test_ip\".\"filter\" is null\n" + " and \"bloomdb\".\"pattern_test_ip255\".\"filter\" is null\n" + ")"; Assertions.assertEquals(e, cond.condition().toString()); @@ -207,7 +207,7 @@ void testTwoMatchWithoutFilters() { void twoMatchingTableTest() { DSLContext ctx = DSL.using(conn); ConditionConfig config = new ConditionConfig(ctx, false, true); - BloomQueryCondition cond = new IndexStatementCondition("255.255.255.255", config); + IndexStatementCondition cond = new IndexStatementCondition("255.255.255.255", config); String e = "(\n" + " (\n" + " bloommatch(\n" + " (\n" + " select \"term_0_pattern_test_ip\".\"filter\"\n" + " from \"term_0_pattern_test_ip\"\n" + " where (\n" + " term_id = 0\n" @@ -227,15 +227,15 @@ void twoMatchingTableTest() { @Test void equalsTest() { - BloomQueryCondition eq1 = new IndexStatementCondition("946677600", mockConfig); - BloomQueryCondition eq2 = new IndexStatementCondition("946677600", mockConfig); + IndexStatementCondition eq1 = new IndexStatementCondition("946677600", mockConfig); + IndexStatementCondition eq2 = new IndexStatementCondition("946677600", mockConfig); Assertions.assertEquals(eq1, eq2); } @Test void notEqualsTest() { - BloomQueryCondition eq1 = new IndexStatementCondition("946677600", mockConfig); - BloomQueryCondition notEq = new IndexStatementCondition("1000", mockConfig); + IndexStatementCondition eq1 = new IndexStatementCondition("946677600", mockConfig); + IndexStatementCondition notEq = new IndexStatementCondition("1000", mockConfig); Assertions.assertNotEquals(eq1, notEq); } From 21d018fae9dffa8ee87e39c2cc606b6df8333e69 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Tue, 24 Sep 2024 15:15:03 +0300 Subject: [PATCH 19/20] enable tokenization of search term, filter category table filter tokens using pattern from each filter_type_id --- .../planner/TableFilterTypesFromMetadata.java | 3 +- .../teragrep/pth_06/planner/TableFilters.java | 30 +++++++++++++++---- .../conditions/PatternMatchCondition.java | 18 ++++++++--- .../pth_06/planner/CategoryTableImplTest.java | 28 ++++++++++++----- ...ableFilterTypesFromMetadataResultTest.java | 12 ++++---- .../pth_06/planner/TableFiltersTest.java | 29 +++++++++++++----- .../CategoryTableConditionTest.java | 12 ++++---- .../IndexStatementConditionTest.java | 12 ++++---- .../conditions/PatternMatchConditionTest.java | 2 -- 9 files changed, 98 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java b/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java index e4ba078e..d5962952 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadata.java @@ -79,7 +79,8 @@ public Result toResult() { final SelectField[] resultFields = { BLOOMDB.FILTERTYPE.ID, joined.field("expectedElements").as(expectedField), - joined.field("targetFpp").as(fppField) + joined.field("targetFpp").as(fppField), + joined.field("pattern") }; // Fetch filtertype values from metadata final Result records = ctx diff --git a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java index 8f7c9217..d5ff1086 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TableFilters.java +++ b/src/main/java/com/teragrep/pth_06/planner/TableFilters.java @@ -45,6 +45,7 @@ */ package com.teragrep.pth_06.planner; +import com.teragrep.blf_01.Token; import org.apache.spark.util.sketch.BloomFilter; import org.jooq.*; import org.jooq.impl.DSL; @@ -53,6 +54,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UncheckedIOException; +import java.util.regex.Pattern; import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB; import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED; @@ -65,18 +67,24 @@ public final class TableFilters { private final DSLContext ctx; private final Table table; private final long bloomTermId; - private final String value; + private final TokenizedValue value; private final TableRecords recordsInMetadata; - public TableFilters(DSLContext ctx, Table table, long bloomTermId, String value) { - this(ctx, table, bloomTermId, value, new TableFilterTypesFromMetadata(ctx, table, bloomTermId)); + public TableFilters(DSLContext ctx, Table table, long bloomTermId, String input) { + this( + ctx, + table, + bloomTermId, + new TokenizedValue(input), + new TableFilterTypesFromMetadata(ctx, table, bloomTermId) + ); } public TableFilters( DSLContext ctx, Table table, long bloomTermId, - String value, + TokenizedValue value, TableFilterTypesFromMetadata recordsInMetadata ) { this.ctx = ctx; @@ -95,8 +103,20 @@ public TableFilters( private byte[] filterBytesFromRecord(final Record record) { final ULong expected = record.getValue(DSL.field(DSL.name(table.getName(), "expectedElements"), ULong.class)); final Double fpp = record.getValue(DSL.field(DSL.name(table.getName(), "targetFpp"), Double.class)); + final String pattern = record.getValue(BLOOMDB.FILTERTYPE.PATTERN, String.class); final BloomFilter filter = BloomFilter.create(expected.longValue(), fpp); - filter.put(value); + final Pattern compiled = Pattern.compile(pattern); + boolean isEmpty = true; + for (final Token token : value.tokens()) { + final String tokenString = token.toString(); + if (compiled.matcher(tokenString).matches()) { + isEmpty = false; + filter.put(tokenString); + } + } + if (isEmpty) { + throw new IllegalStateException("Trying to insert empty filter"); + } final ByteArrayOutputStream filterBAOS = new ByteArrayOutputStream(); try { filter.writeTo(filterBAOS); diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java index fc847c53..f4ad5808 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchCondition.java @@ -45,6 +45,8 @@ */ package com.teragrep.pth_06.planner.walker.conditions; +import com.teragrep.blf_01.Token; +import com.teragrep.pth_06.planner.TokenizedValue; import org.jooq.*; import org.jooq.impl.DSL; @@ -57,15 +59,23 @@ */ public final class PatternMatchCondition implements QueryCondition { - private final String value; + private final TokenizedValue value; - public PatternMatchCondition(String value) { + public PatternMatchCondition(String input) { + this(new TokenizedValue(input)); + } + + public PatternMatchCondition(TokenizedValue value) { this.value = value; } public Condition condition() { - final Field valueField = DSL.val(value); - return valueField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN); + Condition patternCondition = DSL.noCondition(); + for (Token token : value.tokens()) { + Field tokenStringField = DSL.val(token.toString()); + patternCondition = patternCondition.or(tokenStringField.likeRegex(BLOOMDB.FILTERTYPE.PATTERN)); + } + return patternCondition; } @Override diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index 0aa7bffe..b34a4913 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -72,13 +72,11 @@ public class CategoryTableImplTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; final String password = ""; - final List patternList = new ArrayList<>( - Arrays - .asList( - "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", - "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" - ) - ); + // matches IPv4 + final String ipRegex = "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + // matches IPv4 starting with 255. + final String ipStartingWith255 = "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + final List patternList = new ArrayList<>(Arrays.asList(ipRegex, ipStartingWith255)); final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); @BeforeAll @@ -175,6 +173,22 @@ public void testCreation() { Assertions.assertDoesNotThrow(categoryTable::create); } + @Test + public void testFilterInsertion() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + + CategoryTable categoryTable = new CategoryTableImpl(ctx, table, 0L, "192.168.1.1"); + Assertions.assertDoesNotThrow(categoryTable::create); + Assertions.assertDoesNotThrow(categoryTable::insertFilters); + } + @Test public void testConditionGeneration() { fillTargetTable(); diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java index 95a880a6..50516717 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFilterTypesFromMetadataResultTest.java @@ -68,13 +68,11 @@ class TableFilterTypesFromMetadataResultTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; final String password = ""; - final List patternList = new ArrayList<>( - Arrays - .asList( - "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", - "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" - ) - ); + // matches IPv4 + final String ipRegex = "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + // matches IPv4 starting with 255. + final String ipStartingWith255 = "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + final List patternList = new ArrayList<>(Arrays.asList(ipRegex, ipStartingWith255)); final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); @BeforeAll diff --git a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java index 1f9a651d..5ab27f18 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TableFiltersTest.java @@ -66,13 +66,11 @@ class TableFiltersTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; final String password = ""; - final List patternList = new ArrayList<>( - Arrays - .asList( - "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", - "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" - ) - ); + // matches IPv4 + final String ipRegex = "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + // matches IPv4 starting with 255. + final String ipStartingWith255 = "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + final List patternList = new ArrayList<>(Arrays.asList(ipRegex, ipStartingWith255)); final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); @BeforeAll @@ -149,10 +147,25 @@ public void testInsertFiltersIntoCategoryTable() { .getTables() .get(0); DataAccessException exception = Assertions - .assertThrows(DataAccessException.class, () -> new TableFilters(ctx, table, 0L, "test").insertFiltersIntoCategoryTable()); + .assertThrows(DataAccessException.class, () -> new TableFilters(ctx, table, 0L, "192.168.1.1").insertFiltersIntoCategoryTable()); Assertions.assertTrue(exception.getMessage().contains("term_0_target\" (term_id, type_id, \"filter\")")); } + @Test + public void testInsertFiltersWithoutPatternMatch() { + fillTargetTable(); + DSLContext ctx = DSL.using(conn); + Table table = ctx + .meta() + .filterSchemas(s -> s.getName().equals("bloomdb")) + .filterTables(t -> !t.getName().equals("filtertype")) + .getTables() + .get(0); + IllegalStateException exception = Assertions + .assertThrows(IllegalStateException.class, () -> new TableFilters(ctx, table, 0L, "nomatch").insertFiltersIntoCategoryTable()); + Assertions.assertTrue(exception.getMessage().contains("Trying to insert empty filter")); + } + @Test public void testEquals() { fillTargetTable(); diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java index 8c088ebd..c57e2312 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/CategoryTableConditionTest.java @@ -71,13 +71,11 @@ class CategoryTableConditionTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; final String password = ""; - final List patternList = new ArrayList<>( - Arrays - .asList( - "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", - "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" - ) - ); + // matches IPv4 + final String ipRegex = "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + // matches IPv4 starting with 255. + final String ipStartingWith255 = "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + final List patternList = new ArrayList<>(Arrays.asList(ipRegex, ipStartingWith255)); final Connection conn = Assertions.assertDoesNotThrow(() -> DriverManager.getConnection(url, userName, password)); @BeforeAll diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java index 70f48f7d..b180b2dc 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementConditionTest.java @@ -75,13 +75,11 @@ public class IndexStatementConditionTest { final String url = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"; final String userName = "sa"; final String password = ""; - final List patternList = new ArrayList<>( - Arrays - .asList( - "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}", - "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}" - ) - ); + // matches IPv4 + final String ipRegex = "(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + // matches IPv4 starting with 255. + final String ipStartingWith255 = "(\\b25[0-5]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"; + final List patternList = new ArrayList<>(Arrays.asList(ipRegex, ipStartingWith255)); final ConditionConfig mockConfig = new ConditionConfig( DSL.using(new MockConnection(ctx -> new MockResult[0])), false, diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java index 4c92f8b7..505c10a2 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java @@ -47,7 +47,6 @@ import org.jooq.Condition; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** @@ -66,7 +65,6 @@ void testSingleToken() { } @Test - @Disabled("Search term tokenization is not enabled in this version") void testMultipleTokens() { Condition condition = new PatternMatchCondition("test.nest").condition(); String e = "(\n" + " ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" From ae8359dcafae6385f0ef50765bbbae032bcd96b2 Mon Sep 17 00:00:00 2001 From: elliVM <47@teragrep.com> Date: Tue, 24 Sep 2024 16:42:14 +0300 Subject: [PATCH 20/20] TokenizedValue finds minor tokens, add tests that correct tokens are inserted to category table, some code cleanup --- .../teragrep/pth_06/planner/TokenizedValue.java | 2 +- .../conditions/IndexStatementCondition.java | 8 ++++++-- .../pth_06/planner/CategoryTableImplTest.java | 16 ++++++++++++++-- .../pth_06/planner/TokenizedValueTest.java | 4 +++- .../conditions/PatternMatchConditionTest.java | 4 +++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java b/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java index b659ec85..3d5bc6c1 100644 --- a/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java +++ b/src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java @@ -63,7 +63,7 @@ public TokenizedValue(String value) { public Set tokens() { return new HashSet<>( - new Tokenizer(0).tokenize(new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8))) + new Tokenizer(32).tokenize(new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8))) ); } diff --git a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java index 4002e8b6..cf1cfced 100644 --- a/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java +++ b/src/main/java/com/teragrep/pth_06/planner/walker/conditions/IndexStatementCondition.java @@ -102,8 +102,12 @@ public Condition condition() { combinedTableCondition = combinedTableCondition.or(tableCondition.condition()); combinedNullFilterCondition = combinedNullFilterCondition.and(nullFilterCondition); } - newCondition = config.withoutFilters() ? combinedNullFilterCondition : combinedTableCondition - .or(combinedNullFilterCondition); + if (config.withoutFilters()) { + newCondition = combinedNullFilterCondition; + } + else { + newCondition = combinedTableCondition.or(combinedNullFilterCondition); + } } return newCondition; } diff --git a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java index b34a4913..60469640 100644 --- a/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/CategoryTableImplTest.java @@ -52,10 +52,12 @@ import org.jooq.impl.DSL; import org.junit.jupiter.api.*; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -169,7 +171,7 @@ public void testCreation() { .getTables() .get(0); - CategoryTable categoryTable = new CategoryTableImpl(ctx, table, 0L, "test"); + CategoryTable categoryTable = new CategoryTableImpl(ctx, table, 0L, "192.168.1.1"); Assertions.assertDoesNotThrow(categoryTable::create); } @@ -184,9 +186,19 @@ public void testFilterInsertion() { .getTables() .get(0); - CategoryTable categoryTable = new CategoryTableImpl(ctx, table, 0L, "192.168.1.1"); + CategoryTable categoryTable = new CategoryTableImpl(ctx, table, 0L, "ip=192.168.1.1"); Assertions.assertDoesNotThrow(categoryTable::create); Assertions.assertDoesNotThrow(categoryTable::insertFilters); + BloomFilter filter = Assertions.assertDoesNotThrow(() -> { + ResultSet rs = conn.prepareStatement("SELECT * FROM term_0_target").executeQuery(); + rs.absolute(1); + byte[] bytes = rs.getBytes(4); + return BloomFilter.readFrom(new ByteArrayInputStream(bytes)); + }); + // check that category table filter only has pattern matching tokens + Assertions.assertTrue(filter.mightContain("192.168.1.1")); + Assertions.assertFalse(filter.mightContain("ip=192.168.1.1")); + Assertions.assertFalse(filter.mightContain("168.1.1")); } @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java index 3536b6d5..69c2ee2d 100644 --- a/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/TokenizedValueTest.java @@ -63,7 +63,9 @@ void testTokenization() { Assertions.assertTrue(tokens.contains("test")); Assertions.assertTrue(tokens.contains(".")); Assertions.assertTrue(tokens.contains("test.nest")); - Assertions.assertEquals(4, tokens.size()); + Assertions.assertTrue(tokens.contains(".nest")); + Assertions.assertTrue(tokens.contains("test.")); + Assertions.assertEquals(6, tokens.size()); } @Test diff --git a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java index 505c10a2..fd486989 100644 --- a/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java +++ b/src/test/java/com/teragrep/pth_06/planner/walker/conditions/PatternMatchConditionTest.java @@ -67,7 +67,9 @@ void testSingleToken() { @Test void testMultipleTokens() { Condition condition = new PatternMatchCondition("test.nest").condition(); - String e = "(\n" + " ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + String e = "(\n" + " ('test.' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + + " or ('test.nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + " or ('nest' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + " or ('.' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + " or ('test' like_regex \"bloomdb\".\"filtertype\".\"pattern\")\n" + ")";