|
@@ -0,0 +1,47 @@
|
|
|
+/*
|
|
|
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
+ * or more contributor license agreements. Licensed under the Elastic License
|
|
|
+ * 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
+ * 2.0.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.elasticsearch.xpack.esql.generator.command.pipe;
|
|
|
+
|
|
|
+import org.elasticsearch.xpack.esql.generator.Column;
|
|
|
+import org.elasticsearch.xpack.esql.generator.QueryExecutor;
|
|
|
+import org.elasticsearch.xpack.esql.generator.command.CommandGenerator;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.elasticsearch.test.ESTestCase.randomDoubleBetween;
|
|
|
+
|
|
|
+public class SampleGenerator implements CommandGenerator {
|
|
|
+
|
|
|
+ public static final String SAMPLE = "sample";
|
|
|
+ public static final CommandGenerator INSTANCE = new SampleGenerator();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommandDescription generate(
|
|
|
+ List<CommandDescription> previousCommands,
|
|
|
+ List<Column> previousOutput,
|
|
|
+ QuerySchema schema,
|
|
|
+ QueryExecutor executor
|
|
|
+ ) {
|
|
|
+ double n = randomDoubleBetween(0.0, 1.0, false);
|
|
|
+ String cmd = " | SAMPLE " + n;
|
|
|
+ return new CommandDescription(SAMPLE, this, cmd, Map.of());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ValidationResult validateOutput(
|
|
|
+ List<CommandDescription> previousCommands,
|
|
|
+ CommandDescription commandDescription,
|
|
|
+ List<Column> previousColumns,
|
|
|
+ List<List<Object>> previousOutput,
|
|
|
+ List<Column> columns,
|
|
|
+ List<List<Object>> output
|
|
|
+ ) {
|
|
|
+ return CommandGenerator.expectSameColumns(previousColumns, columns);
|
|
|
+ }
|
|
|
+}
|