|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.esql.generator.command.pipe; |
| 9 | + |
| 10 | +import org.elasticsearch.xpack.esql.generator.Column; |
| 11 | +import org.elasticsearch.xpack.esql.generator.QueryExecutor; |
| 12 | +import org.elasticsearch.xpack.esql.generator.command.CommandGenerator; |
| 13 | + |
| 14 | +import java.util.List; |
| 15 | +import java.util.Map; |
| 16 | + |
| 17 | +import static org.elasticsearch.test.ESTestCase.randomDoubleBetween; |
| 18 | + |
| 19 | +public class SampleGenerator implements CommandGenerator { |
| 20 | + |
| 21 | + public static final String SAMPLE = "sample"; |
| 22 | + public static final CommandGenerator INSTANCE = new SampleGenerator(); |
| 23 | + |
| 24 | + @Override |
| 25 | + public CommandDescription generate( |
| 26 | + List<CommandDescription> previousCommands, |
| 27 | + List<Column> previousOutput, |
| 28 | + QuerySchema schema, |
| 29 | + QueryExecutor executor |
| 30 | + ) { |
| 31 | + double n = randomDoubleBetween(0.0, 1.0, false); |
| 32 | + String cmd = " | SAMPLE " + n; |
| 33 | + return new CommandDescription(SAMPLE, this, cmd, Map.of()); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public ValidationResult validateOutput( |
| 38 | + List<CommandDescription> previousCommands, |
| 39 | + CommandDescription commandDescription, |
| 40 | + List<Column> previousColumns, |
| 41 | + List<List<Object>> previousOutput, |
| 42 | + List<Column> columns, |
| 43 | + List<List<Object>> output |
| 44 | + ) { |
| 45 | + return CommandGenerator.expectSameColumns(previousColumns, columns); |
| 46 | + } |
| 47 | +} |
0 commit comments