You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "kgyrtkirk (via GitHub)" <gi...@apache.org> on 2024/05/03 10:33:25 UTC
[PR] Enable quidem tests to use different suppliers (druid)
kgyrtkirk opened a new pull request, #16382:
URL: https://github.com/apache/druid/pull/16382
* enable quidem uri support for `druidtest:///?Supplier=Nested` and similar
* changes the way `SqlTestFrameworkConfig` is being applied; all options will have their own annotation (its kinda impossible to detect that an annotation has a set value or its the default)
* enables hierarchical processing of config annotation (was needed to enable class level supplier annotation)
* moves uri processing related string2config stuff into `SqlTestFrameworkConfig`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592527091
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
Review Comment:
I've introduced a set of classes/processor/etc to disperse this method to the config options...its different for sure :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk merged PR #16382:
URL: https://github.com/apache/druid/pull/16382
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593839599
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
Review Comment:
this newly added by-name lookup will not interfere with existing tests; as in those cases a ComponentSupplier class is specified as a java class explicitly in the annotation - however in case it comes from a jdbc-uri it will need the lookup.
run all `Calcite*Test` on master and on this branch - didn't seen any relevant difference in the runtimes
<details>
<summary>testrun on master</summary>
```
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.druid.sql.calcite.CalciteNestedDataQueryTest
[INFO] Tests run: 145, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.255 s -- in org.apache.druid.sql.calcite.CalciteNestedDataQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteArraysQueryTest
[INFO] Tests run: 156, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.42 s -- in org.apache.druid.sql.calcite.CalciteArraysQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteUnionQueryTest
[INFO] Tests run: 14, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.881 s -- in org.apache.druid.sql.calcite.CalciteUnionQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSysQueryTest
[WARN] Tests run: 4, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 2.646 s -- in org.apache.druid.sql.calcite.CalciteSysQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteLookupFunctionQueryTest
[INFO] Tests run: 90, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.361 s -- in org.apache.druid.sql.calcite.CalciteLookupFunctionQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteStrictInsertTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.488 s -- in org.apache.druid.sql.calcite.CalciteStrictInsertTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSimpleQueryTest
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.734 s -- in org.apache.druid.sql.calcite.CalciteSimpleQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteParameterQueryTest
[INFO] Tests run: 20, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.874 s -- in org.apache.druid.sql.calcite.CalciteParameterQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteJoinQueryTest
[WARN] Tests run: 586, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 16.89 s -- in org.apache.druid.sql.calcite.CalciteJoinQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteCatalogInsertTest
[INFO] Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.637 s -- in org.apache.druid.sql.calcite.CalciteCatalogInsertTest
[INFO] Running org.apache.druid.sql.calcite.CalciteExplainQueryTest
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.514 s -- in org.apache.druid.sql.calcite.CalciteExplainQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteExportTest
[WARN] Tests run: 13, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 2.472 s -- in org.apache.druid.sql.calcite.CalciteExportTest
[INFO] Running org.apache.druid.sql.calcite.CalciteWindowQueryTest
[WARN] Tests run: 41, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 4.641 s -- in org.apache.druid.sql.calcite.CalciteWindowQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteTableAppendTest
[INFO] Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.469 s -- in org.apache.druid.sql.calcite.CalciteTableAppendTest
[INFO] Running org.apache.druid.sql.calcite.CalciteReplaceDmlTest
[INFO] Tests run: 46, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.769 s -- in org.apache.druid.sql.calcite.CalciteReplaceDmlTest
[INFO] Running org.apache.druid.sql.calcite.planner.CalcitePlannerModuleTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.435 s -- in org.apache.druid.sql.calcite.planner.CalcitePlannerModuleTest
[INFO] Running org.apache.druid.sql.calcite.planner.CalcitesTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s -- in org.apache.druid.sql.calcite.planner.CalcitesTest
[INFO] Running org.apache.druid.sql.calcite.CalciteCorrelatedQueryTest
[INFO] Tests run: 35, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.919 s -- in org.apache.druid.sql.calcite.CalciteCorrelatedQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteQueryTest
[WARN] Tests run: 389, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 13.97 s -- in org.apache.druid.sql.calcite.CalciteQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSubqueryTest
[INFO] Tests run: 44, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.449 s -- in org.apache.druid.sql.calcite.CalciteSubqueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteInsertDmlTest
[INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.959 s -- in org.apache.druid.sql.calcite.CalciteInsertDmlTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSelectQueryTest
[INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.949 s -- in org.apache.druid.sql.calcite.CalciteSelectQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteMultiValueStringQueryTest
[INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.020 s -- in org.apache.druid.sql.calcite.CalciteMultiValueStringQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteCatalogReplaceTest
[INFO] Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.566 s -- in org.apache.druid.sql.calcite.CalciteCatalogReplaceTest
[INFO] Running org.apache.druid.sql.calcite.CalciteTimeBoundaryQueryTest
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.472 s -- in org.apache.druid.sql.calcite.CalciteTimeBoundaryQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteScanSignatureTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.472 s -- in org.apache.druid.sql.calcite.CalciteScanSignatureTest
[INFO]
[INFO] Results:
[INFO]
[WARN] Tests run: 1845, Failures: 0, Errors: 0, Skipped: 11
[INFO]
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.23:check (check-java-api) @ druid-sql ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO] Segment walltime 124 s, segment projects service time 124 s, effective/maximum degree of concurrency 1.00/11
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:04 min (Wall Clock)
[INFO] Finished at: 2024-05-08T10:54:19Z
[INFO] ------------------------------------------------------------------------
```
</details>
<details>
<summary>testrun on branch</summary>
```
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.druid.sql.calcite.CalciteNestedDataQueryTest
[INFO] Tests run: 145, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.195 s -- in org.apache.druid.sql.calcite.CalciteNestedDataQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteArraysQueryTest
[INFO] Tests run: 156, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.17 s -- in org.apache.druid.sql.calcite.CalciteArraysQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteUnionQueryTest
[INFO] Tests run: 14, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.815 s -- in org.apache.druid.sql.calcite.CalciteUnionQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSysQueryTest
[WARN] Tests run: 4, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 2.628 s -- in org.apache.druid.sql.calcite.CalciteSysQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteLookupFunctionQueryTest
[INFO] Tests run: 90, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.194 s -- in org.apache.druid.sql.calcite.CalciteLookupFunctionQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteStrictInsertTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.519 s -- in org.apache.druid.sql.calcite.CalciteStrictInsertTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSimpleQueryTest
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.774 s -- in org.apache.druid.sql.calcite.CalciteSimpleQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteParameterQueryTest
[INFO] Tests run: 20, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.923 s -- in org.apache.druid.sql.calcite.CalciteParameterQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteJoinQueryTest
[WARN] Tests run: 586, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 16.70 s -- in org.apache.druid.sql.calcite.CalciteJoinQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteCatalogInsertTest
[INFO] Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.681 s -- in org.apache.druid.sql.calcite.CalciteCatalogInsertTest
[INFO] Running org.apache.druid.sql.calcite.CalciteExplainQueryTest
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.536 s -- in org.apache.druid.sql.calcite.CalciteExplainQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteExportTest
[WARN] Tests run: 13, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 2.483 s -- in org.apache.druid.sql.calcite.CalciteExportTest
[INFO] Running org.apache.druid.sql.calcite.CalciteWindowQueryTest
[WARN] Tests run: 41, Failures: 0, Errors: 0, Skipped: 2, Time elapsed: 4.509 s -- in org.apache.druid.sql.calcite.CalciteWindowQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteTableAppendTest
[INFO] Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.490 s -- in org.apache.druid.sql.calcite.CalciteTableAppendTest
[INFO] Running org.apache.druid.sql.calcite.CalciteReplaceDmlTest
[INFO] Tests run: 46, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.813 s -- in org.apache.druid.sql.calcite.CalciteReplaceDmlTest
[INFO] Running org.apache.druid.sql.calcite.planner.CalcitePlannerModuleTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.428 s -- in org.apache.druid.sql.calcite.planner.CalcitePlannerModuleTest
[INFO] Running org.apache.druid.sql.calcite.planner.CalcitesTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s -- in org.apache.druid.sql.calcite.planner.CalcitesTest
[INFO] Running org.apache.druid.sql.calcite.CalciteCorrelatedQueryTest
[INFO] Tests run: 35, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.061 s -- in org.apache.druid.sql.calcite.CalciteCorrelatedQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteQueryTest
[WARN] Tests run: 389, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 14.12 s -- in org.apache.druid.sql.calcite.CalciteQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSubqueryTest
[INFO] Tests run: 44, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.475 s -- in org.apache.druid.sql.calcite.CalciteSubqueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteInsertDmlTest
[INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.018 s -- in org.apache.druid.sql.calcite.CalciteInsertDmlTest
[INFO] Running org.apache.druid.sql.calcite.CalciteSelectQueryTest
[INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.973 s -- in org.apache.druid.sql.calcite.CalciteSelectQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteMultiValueStringQueryTest
[INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.062 s -- in org.apache.druid.sql.calcite.CalciteMultiValueStringQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteCatalogReplaceTest
[INFO] Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.681 s -- in org.apache.druid.sql.calcite.CalciteCatalogReplaceTest
[INFO] Running org.apache.druid.sql.calcite.CalciteTimeBoundaryQueryTest
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.577 s -- in org.apache.druid.sql.calcite.CalciteTimeBoundaryQueryTest
[INFO] Running org.apache.druid.sql.calcite.CalciteScanSignatureTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.448 s -- in org.apache.druid.sql.calcite.CalciteScanSignatureTest
[INFO]
[INFO] Results:
[INFO]
[WARN] Tests run: 1845, Failures: 0, Errors: 0, Skipped: 11
[INFO]
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.23:check (check-java-api) @ druid-sql ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO] Segment walltime 126 s, segment projects service time 126 s, effective/maximum degree of concurrency 1.00/11
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:06 min (Wall Clock)
[INFO] Finished at: 2024-05-08T10:52:09Z
[INFO] ------------------------------------------------------------------------
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593790838
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
Review Comment:
I'll added that in the next patch!
...I have done a typo yesterday and it was very annoying!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592399919
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
Review Comment:
this was an unnecessary check; it may have been never null
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592477014
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
Review Comment:
unfortunately - some of these options have no close relation to the `QueryContext`
Other way around could be to move these processing things next to the options - but that seemed a bit too much at first
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592093567
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfigTest.java:
##########
@@ -20,15 +20,85 @@
package org.apache.druid.sql.calcite;
import nl.jqno.equalsverifier.EqualsVerifier;
+import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.MinTopNThreshold;
+import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.NumMergeBuffers;
+import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ResultCache;
+import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode;
import org.junit.jupiter.api.Test;
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class SqlTestFrameworkConfigTest
{
@Test
public void testEquals()
{
- EqualsVerifier.forClass(SqlTestFrameworkConfig.SqlTestFrameworkConfigInstance.class)
+ EqualsVerifier.forClass(SqlTestFrameworkConfig.class)
.usingGetClass()
.verify();
}
+
+ @ResultCache(ResultCacheMode.ENABLED)
+ static class B
+ {
+ }
+
+ @NumMergeBuffers(3)
+ static class C extends B
+ {
+ @MinTopNThreshold(1)
+ public void imaginaryTestMethod1()
+ {
+ }
+
+ public void imaginaryTestMethod2()
+ {
+ }
+ }
+
+ @MinTopNThreshold(2)
+ static class D extends C
+ {
+ @NumMergeBuffers(1)
Review Comment:
added new testcase :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593790838
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
Review Comment:
I'll add that in the next patch!
...I have done a typo yesterday and it was very annoying!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592472051
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -169,40 +280,25 @@ public void afterAll(ExtensionContext context)
@Override
public void beforeEach(ExtensionContext context)
{
- method = context.getTestMethod().get();
- setConfig(method.getAnnotation(SqlTestFrameworkConfig.class));
+ setConfig(context);
}
- @SqlTestFrameworkConfig
- public SqlTestFrameworkConfig defaultConfig()
+ private void setConfig(ExtensionContext context)
{
- try {
- SqlTestFrameworkConfig annotation = getClass()
- .getMethod("defaultConfig")
- .getAnnotation(SqlTestFrameworkConfig.class);
- return annotation;
- }
- catch (NoSuchMethodException | SecurityException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void setConfig(SqlTestFrameworkConfig annotation)
- {
- if (annotation == null) {
- annotation = defaultConfig();
- }
- config = new SqlTestFrameworkConfigInstance(annotation);
+ method = context.getTestMethod().get();
+ Class<?> testClass = context.getTestClass().get();
+ List<Annotation> annotations = collectAnnotations(testClass, method);
+ config = new SqlTestFrameworkConfig(annotations);
}
- public SqlTestFrameworkConfigInstance getConfig()
+ public SqlTestFrameworkConfig getConfig()
{
return config;
}
- public SqlTestFramework get()
+ public SqlTestFramework get() throws Exception
{
- return configStore.getConfigurationInstance(config, testHostSupplier).framework;
+ return configStore.getConfigurationInstance(config, x -> x).framework;
Review Comment:
The `AvaticaServer` related things are added by wrapping the supplier with a delegate; in normal operation that's not needed.
I think that could be removed later - as it would be better to package that part into a module or something
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593637779
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
Review Comment:
Thanks for the new set of changes, they look good to me :+1:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1591898272
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
Review Comment:
I've renamed it.
I believe the reason I've shortened this to `Supplier` was due to the fact that these could be specified in the jdbc uri; and long key names could take up a lot of extra line-space - at the cost of readability.
Right now I've "accepted" to follow a convention of only accepting the configuration key if it fully matches with the annotation's name; so`druidtest:///?ComponentSupplier=Something` instead of `druidtest:///?componentsupplier=Something` or `druidtest:///?Componentsupplier=Something` ; I was wondering about adding the ability to match the options in an ignore case manner...but writing all this down....it might be more annoying to typo an option name (whenever its short or long) and not getting the expected behaviour....maybe I should instead add a validation for the provided config keys
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593631761
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
Review Comment:
Thanks for the clarification and changes! And yes, I think adding a validation for config keys in future might be good - since these configs are only used in tests, hence I think it makes sense for us to be strict in accepting them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1595064687
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
Review Comment:
ah, I see. Sorry I missed that! Although, the few quidem tests we have right now would invoke the lookup right?
Also, thanks for checking the time difference between the runtimes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1591064457
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
Review Comment:
should this be named `ComponentSupplier` for clarity?
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
Review Comment:
is there any plan to support a query context map syntax instead of annotations per config? that might be helpful in writing newer tests without changing the core code.
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
Review Comment:
maybe `Cannot handle conversion of key [%s] with value [%s] of type [%s]` - any other wording with the info is also ok to me.
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfigTest.java:
##########
@@ -20,15 +20,85 @@
package org.apache.druid.sql.calcite;
import nl.jqno.equalsverifier.EqualsVerifier;
+import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.MinTopNThreshold;
+import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.NumMergeBuffers;
+import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ResultCache;
+import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode;
import org.junit.jupiter.api.Test;
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class SqlTestFrameworkConfigTest
{
@Test
public void testEquals()
{
- EqualsVerifier.forClass(SqlTestFrameworkConfig.SqlTestFrameworkConfigInstance.class)
+ EqualsVerifier.forClass(SqlTestFrameworkConfig.class)
.usingGetClass()
.verify();
}
+
+ @ResultCache(ResultCacheMode.ENABLED)
+ static class B
+ {
+ }
+
+ @NumMergeBuffers(3)
+ static class C extends B
+ {
+ @MinTopNThreshold(1)
+ public void imaginaryTestMethod1()
+ {
+ }
+
+ public void imaginaryTestMethod2()
+ {
+ }
+ }
+
+ @MinTopNThreshold(2)
+ static class D extends C
+ {
+ @NumMergeBuffers(1)
Review Comment:
maybe could have another method `imaginaryTestMethod4` which has annotations `ResultCache(ResultCacheMode.DISABLED)` and `MinTopNThreshold(1)`
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
Review Comment:
can throw with an appropriate error message in else
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
+ .getSubTypesOf(QueryComponentSupplier.class);
+ Set<String> knownNames = new HashSet<String>();
+
+ for (Class<? extends QueryComponentSupplier> cl : subTypes) {
+ if (cl.getSimpleName().equals(name)) {
+ return cl;
+ }
+ knownNames.add(cl.getSimpleName());
+ }
+ throw new IAE("supplier [%s] is not known; known are [%s]", name, knownNames);
Review Comment:
suggestion for better wording - like using `Query component supplier` instead of `supplier`
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
Review Comment:
this would not support a component supplier defined in an extension which has a proprietary package name.
also, we should cache this set probably
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -169,40 +280,25 @@ public void afterAll(ExtensionContext context)
@Override
public void beforeEach(ExtensionContext context)
{
- method = context.getTestMethod().get();
- setConfig(method.getAnnotation(SqlTestFrameworkConfig.class));
+ setConfig(context);
}
- @SqlTestFrameworkConfig
- public SqlTestFrameworkConfig defaultConfig()
+ private void setConfig(ExtensionContext context)
{
- try {
- SqlTestFrameworkConfig annotation = getClass()
- .getMethod("defaultConfig")
- .getAnnotation(SqlTestFrameworkConfig.class);
- return annotation;
- }
- catch (NoSuchMethodException | SecurityException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void setConfig(SqlTestFrameworkConfig annotation)
- {
- if (annotation == null) {
- annotation = defaultConfig();
- }
- config = new SqlTestFrameworkConfigInstance(annotation);
+ method = context.getTestMethod().get();
+ Class<?> testClass = context.getTestClass().get();
+ List<Annotation> annotations = collectAnnotations(testClass, method);
+ config = new SqlTestFrameworkConfig(annotations);
}
- public SqlTestFrameworkConfigInstance getConfig()
+ public SqlTestFrameworkConfig getConfig()
{
return config;
}
- public SqlTestFramework get()
+ public SqlTestFramework get() throws Exception
{
- return configStore.getConfigurationInstance(config, testHostSupplier).framework;
+ return configStore.getConfigurationInstance(config, x -> x).framework;
Review Comment:
maybe we can eliminate the identity lambda?
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
Review Comment:
unfortunately, we don't have the serde logic of each property attached to the property object - rather that is handled by the `QueryContext` class.
I think maybe taking input a whole `QueryContext` might be helpful with managing these serde too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593636821
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
Review Comment:
Ok, I see... the current setup makes sense if the configs allowed are only for the environment.
And I agree that removing the `minTopNThreashold` from this syntax would be helpful in future - to avoid bad culture.
Although, I'm not sure if I understand how someone can specify the context properties right now for a test. Is it possible as of now to do that?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1595119229
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
Review Comment:
yes - they use this method; and they will benefit from these caches more-and-more as we will get more cases!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1591916011
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
Review Comment:
I've not planned anything for queryContext - because that can be changed at a query-by-query basis in the testBuilder; these configs should only include things which make the backing test environment different.
I was always seen `minTopNThreashold` which might have been mis-categorized to be specified as test environment config instead of just overriding it in the querycontext.
I'll see if it can be removed in a followup - unnecessary configuration axes may just increase the configuration space and possibly cause slow down if different values are provided for them without much benefits
I you have in mind something like:
```java
@QueryContext( enableWindowing = true )
class SomeTest {
@Test
@QueryContext( minTopNThreshold = 11 )
{
}
}
```
that's also possible ; but haven't thinked about it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592570164
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -37,76 +45,168 @@
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
+import java.util.stream.Collectors;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
+ *
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ static ConfigOptionProcessor<Integer> PROCESSOR = new ConfigOptionProcessor<Integer>(NumMergeBuffers.class)
+ {
+ @Override
+ public Integer fromString(String str)
+ {
+ return Integer.valueOf(str);
Review Comment:
## Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
[Show more details](https://github.com/apache/druid/security/code-scanning/7353)
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -37,76 +45,168 @@
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
+import java.util.stream.Collectors;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
+ *
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ static ConfigOptionProcessor<Integer> PROCESSOR = new ConfigOptionProcessor<Integer>(NumMergeBuffers.class)
+ {
+ @Override
+ public Integer fromString(String str)
+ {
+ return Integer.valueOf(str);
+ }
+ };
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ static ConfigOptionProcessor<Integer> PROCESSOR = new ConfigOptionProcessor<Integer>(MinTopNThreshold.class)
+ {
+ @Override
+ public Integer fromString(String str)
+ {
+ return Integer.valueOf(str);
Review Comment:
## Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
[Show more details](https://github.com/apache/druid/security/code-scanning/7354)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593642429
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
Review Comment:
The current implementation of using a chained method with calcite and root package, along with the caching looks good to me 👍 One more thing to look at for performance changes could be to check the runtimes of SQL module tests in master vs this PR - hopefully they should be pretty close.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "rohangarg (via GitHub)" <gi...@apache.org>.
rohangarg commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1595066415
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
Review Comment:
Thanks for the pointer for queryContext :+1:
Oh I see, yes your explanation for `TopNQueryConfig` does make sense to me. And agree that we could remove it in the future in exchange for the context param - but we'd need to find a way to support the old config name too without the explicit config class for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1592442285
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
+ {
+ int value();
+ }
- ResultCacheMode resultCache() default ResultCacheMode.DISABLED;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @ResultCache(ResultCacheMode.DISABLED)
+ public @interface ResultCache
+ {
+ ResultCacheMode value();
+ }
/**
- * Non-annotation version of {@link SqlTestFrameworkConfig}.
- *
- * Makes it less convoluted to work with configurations created at runtime.
+ * Declares which {@link QueryComponentSupplier} must be used for the class.
*/
- class SqlTestFrameworkConfigInstance
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Supplier(StandardComponentSupplier.class)
+ public @interface Supplier
{
- public final int numMergeBuffers;
- public final int minTopNThreshold;
- public final ResultCacheMode resultCache;
+ Class<? extends QueryComponentSupplier> value();
+ }
- public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation)
- {
- numMergeBuffers = annotation.numMergeBuffers();
- minTopNThreshold = annotation.minTopNThreshold();
- resultCache = annotation.resultCache();
+ public final int numMergeBuffers;
+ public final int minTopNThreshold;
+ public final ResultCacheMode resultCache;
+ public final Class<? extends QueryComponentSupplier> supplier;
+
+ public SqlTestFrameworkConfig(List<Annotation> annotations)
+ {
+ try {
+ numMergeBuffers = getValueFromAnnotation(annotations, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromAnnotation(annotations, MinTopNThreshold.class);
+ resultCache = getValueFromAnnotation(annotations, ResultCache.class);
+ supplier = getValueFromAnnotation(annotations, Supplier.class);
+ }
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public int hashCode()
- {
- return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache);
+ public SqlTestFrameworkConfig(Map<String, String> queryParams)
+ {
+ try {
+ numMergeBuffers = getValueFromMap(queryParams, NumMergeBuffers.class);
+ minTopNThreshold = getValueFromMap(queryParams, MinTopNThreshold.class);
+ resultCache = getValueFromMap(queryParams, ResultCache.class);
+ supplier = getValueFromMap(queryParams, Supplier.class);
}
+ catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
+ @SuppressWarnings("unchecked")
+ private <T> T getValueFromMap(Map<String, String> map, Class<? extends Annotation> annotationClass)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException
+ {
+ String value = map.get(annotationClass.getSimpleName());
+ if (value == null) {
+ return defaultValue(annotationClass);
+ }
+ Class<?> type = annotationClass.getMethod("value").getReturnType();
+
+ if (type == int.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (type == Class.class) {
+
+ Object clazz = getQueryComponentSupplierForName(value);
+ if (clazz != null) {
+ return (T) clazz;
+ }
+
+ }
+ throw new RuntimeException("don't know how to handle conversion to " + type);
+ }
+
+ private Object getQueryComponentSupplierForName(String name)
+ {
+ Set<Class<? extends QueryComponentSupplier>> subTypes = new Reflections("org.apache.druid")
Review Comment:
yes; only classes under the `org.apache.druid` will be considered - what do you suggest?
* use `ServiceLoader` to register implementations - I would prefer this ; but seems unnecessarily complication
* scan all packages?
* something else?
I've replaced it with the following logic:
* introduced a `LoadingCache` which is keyed by `packageName`
* lookup first tries the `org.apache.druid.sql.calcite` package
* falls back to asks for the root package - and if there are no matches even there -> it returns with an error
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enable quidem tests to use different suppliers (druid)
Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16382:
URL: https://github.com/apache/druid/pull/16382#discussion_r1593811590
##########
sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java:
##########
@@ -36,77 +39,200 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
/**
- * Annotation to specify desired framework settings.
+ * Specifies current framework settings.
*
- * This class provides junit rule facilities to build the framework accordingly
- * to the annotation. These rules also cache the previously created frameworks.
+ * Intended usage from tests is via the annotations:
+ * @SqlTestFrameworkConfig.MinTopNThreshold(33)
+ *
+ * In case of annotations used; it picks up all annotations from:
+ * * the method
+ * * its enclosing class and its parents
+ * if none contains a specific setting the default is being taken.
+ *
+ * All configurable setting should have:
+ * * an annotation with `value` with the desired type
+ * * the annotation itself should be annotated with itslef to set the default value
+ * * a field should be added to the main config class
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface SqlTestFrameworkConfig
+public class SqlTestFrameworkConfig
{
- int numMergeBuffers() default 0;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @NumMergeBuffers(0)
+ public @interface NumMergeBuffers
+ {
+ int value();
+ }
- int minTopNThreshold() default TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD;
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @MinTopNThreshold(TopNQueryConfig.DEFAULT_MIN_TOPN_THRESHOLD)
+ public @interface MinTopNThreshold
Review Comment:
by using `testBuilder().queryContext()` additional querycontext variables can be set (see an example [here](https://github.com/apache/druid/blob/dded473ac0a87e67033cd5dbbe67f1c9fa4b335d/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java#L202-L206))
looking closer at `TopNQueryConfig` ; there seems to be 2 things:
* **(A)** there is a `TopNQueryConfig` [class](https://github.com/apache/druid/blob/dded473ac0a87e67033cd5dbbe67f1c9fa4b335d/processing/src/main/java/org/apache/druid/query/topn/TopNQueryConfig.java#L34) which is jackon serializable
* **(B)** but `TopNQueryToolChest` also enables a `QueryContext` key to override that value [here](https://github.com/apache/druid/blob/dded473ac0a87e67033cd5dbbe67f1c9fa4b335d/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java#L629-L630)
I think the test system was probably built to configure the `A` approach and later probably `B` was also added...
since querycontext defaults can be configured globally - I think keeping the `A` might be redundant ; and it might worth considering the removal of it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org