-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SQL conversion of conditions (#3252)
- Loading branch information
Showing
54 changed files
with
845 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 22 additions & 5 deletions
27
...c/main/java/com/bakdata/conquery/models/datasets/concepts/conditions/PrefixCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,51 @@ | ||
package com.bakdata.conquery.models.datasets.concepts.conditions; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
|
||
import com.bakdata.conquery.io.cps.CPSType; | ||
import com.bakdata.conquery.sql.conversion.cqelement.concept.CTConditionContext; | ||
import com.bakdata.conquery.sql.conversion.model.filter.ConditionType; | ||
import com.bakdata.conquery.sql.conversion.model.filter.WhereCondition; | ||
import com.bakdata.conquery.sql.conversion.model.filter.WhereConditionWrapper; | ||
import com.bakdata.conquery.util.CalculatedValue; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.jooq.Condition; | ||
import org.jooq.Field; | ||
import org.jooq.impl.DSL; | ||
|
||
/** | ||
* This condition requires each value to start with one of the given values. | ||
*/ | ||
@CPSType(id="PREFIX_LIST", base=CTCondition.class) | ||
@CPSType(id = "PREFIX_LIST", base = CTCondition.class) | ||
@ToString | ||
public class PrefixCondition implements CTCondition { | ||
|
||
@Setter @Getter @NotEmpty | ||
@Setter | ||
@Getter | ||
@NotEmpty | ||
private String[] prefixes; | ||
|
||
@Override | ||
public boolean matches(String value, CalculatedValue<Map<String, Object>> rowMap) { | ||
for(String p:prefixes) { | ||
if(value.startsWith(p)) { | ||
for (String p : prefixes) { | ||
if (value.startsWith(p)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public WhereCondition convertToSqlCondition(CTConditionContext context) { | ||
Field<String> field = DSL.field(DSL.name(context.getConnectorTable().getName(), context.getConnectorColumn().getName()), String.class); | ||
String pattern = Arrays.stream(prefixes).collect(Collectors.joining("|", "", "%")); | ||
Condition condition = context.getFunctionProvider().likeRegex(field, pattern); | ||
return new WhereConditionWrapper(condition, ConditionType.PREPROCESSING); | ||
} | ||
} |
Oops, something went wrong.