kgyrtkirk commented on code in PR #15096: URL: https://github.com/apache/druid/pull/15096#discussion_r1348421573
########## sql/src/test/java/org/apache/druid/sql/calcite/DrillWindowQueryTest.java: ########## @@ -36,98 +37,221 @@ import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.Numbers; import org.apache.druid.java.util.common.RE; -import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.parsers.TimestampParser; +import org.apache.druid.query.QueryContexts; import org.apache.druid.query.QueryRunnerFactoryConglomerate; import org.apache.druid.segment.IndexBuilder; import org.apache.druid.segment.QueryableIndex; +import org.apache.druid.segment.column.ColumnType; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.join.JoinableFactoryWrapper; import org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMediumFactory; +import org.apache.druid.sql.calcite.NegativeTest.Modes; +import org.apache.druid.sql.calcite.NegativeTest.NegativeTestProcessor; +import org.apache.druid.sql.calcite.planner.PlannerConfig; +import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.util.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.NumberedShardSpec; +import org.joda.time.DateTime; +import org.joda.time.LocalTime; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Set; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** - * These test cases are borrowed from the drill-test-framework at https://github.com/apache/drill-test-framework + * These test cases are borrowed from the drill-test-framework at + * https://github.com/apache/drill-test-framework * <p> - * The Drill data sources are just accessing parquet files directly, we ingest and index the data first via JSON - * (so that we avoid pulling in the parquet dependencies here) and then run the queries over that. + * The Drill data sources are just accessing parquet files directly, we ingest + * and index the data first via JSON (so that we avoid pulling in the parquet + * dependencies here) and then run the queries over that. * <p> - * The setup of the ingestion is done via code in this class, so any new data source needs to be added through that - * manner. That said, these tests are primarily being added to bootstrap our own test coverage of window - * functions, so it is believed that most iteration on tests will happen through the CalciteWindowQueryTest - * instead of this class. + * The setup of the ingestion is done via code in this class, so any new data + * source needs to be added through that manner. That said, these tests are + * primarily being added to bootstrap our own test coverage of window functions, + * so it is believed that most iteration on tests will happen through the + * CalciteWindowQueryTest instead of this class. */ -@RunWith(Parameterized.class) public class DrillWindowQueryTest extends BaseCalciteQueryTest { - private static final Logger log = new Logger(DrillWindowQueryTest.class); + private static final ObjectMapper MAPPER = new DefaultObjectMapper(); + private DrillTestCase testCase = null; static { NullHandling.initializeForTests(); } - @Parameterized.Parameters(name = "{0}") - public static Object parametersForWindowQueryTest() throws Exception + @Rule + public TestRule disableWhenNonSqlCompat = DisableUnless.SQL_COMPATIBLE; + + @Rule + public NegativeTestProcessor ignoreProcessor = new NegativeTestProcessor(); + + @Rule + public DrillTestCaseLoaderRule drillTestCaseRule = new DrillTestCaseLoaderRule(); + + @Test + public void ensureAllDeclared() throws Exception { final URL windowQueriesUrl = ClassLoader.getSystemResource("drill/window/queries/"); - File windowFolder = new File(windowQueriesUrl.toURI()); - int windowFolderPrefixSize = windowFolder.getAbsolutePath().length() + 1 /* 1 for the ending slash */; + Path windowFolder = new File(windowQueriesUrl.toURI()).toPath(); - return FileUtils - .streamFiles(windowFolder, true, "q") + Set<String> allCases = FileUtils + .streamFiles(windowFolder.toFile(), true, "q") .map(file -> { - final String filePath = file.getAbsolutePath(); - return filePath.substring(windowFolderPrefixSize, filePath.length() - 2); + return windowFolder.relativize(file.toPath()).toString(); }) - .sorted() - .toArray(); + .sorted().collect(Collectors.toSet()); + + for (Method method : DrillWindowQueryTest.class.getDeclaredMethods()) { + DrillTest ann = method.getAnnotation(DrillTest.class); + if (method.getAnnotation(Test.class) == null || ann == null) { + continue; + } + if (allCases.remove(ann.value() + ".q")) { + continue; + } + fail("found testcase referencing invalid file: " + method.getName()); Review Comment: changed it to: ``` fail(String.format("Testcase [%s] references invalid file [%s].", method.getName(), ann.value())); ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
