|
| 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.plugin; |
| 9 | + |
| 10 | +import org.elasticsearch.cluster.block.ClusterBlockException; |
| 11 | +import org.elasticsearch.xpack.esql.VerificationException; |
| 12 | +import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; |
| 13 | +import org.elasticsearch.xpack.esql.action.EsqlQueryResponse; |
| 14 | + |
| 15 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 16 | +import static org.elasticsearch.xpack.esql.action.EsqlQueryRequest.syncEsqlQueryRequest; |
| 17 | +import static org.hamcrest.Matchers.containsString; |
| 18 | +import static org.hamcrest.Matchers.equalTo; |
| 19 | + |
| 20 | +public class IndexResolutionIT extends AbstractEsqlIntegTestCase { |
| 21 | + |
| 22 | + public void testResolvesConcreteIndex() { |
| 23 | + assertAcked(client().admin().indices().prepareCreate("index-1")); |
| 24 | + indexRandom(true, "index-1", 10); |
| 25 | + |
| 26 | + try (var response = run(syncEsqlQueryRequest().query("FROM index-1"))) { |
| 27 | + assertOk(response); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + public void testResolvesAlias() { |
| 32 | + assertAcked(client().admin().indices().prepareCreate("index-1")); |
| 33 | + indexRandom(true, "index-1", 10); |
| 34 | + assertAcked(client().admin().indices().prepareAliases(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).addAlias("index-1", "alias-1")); |
| 35 | + |
| 36 | + try (var response = run(syncEsqlQueryRequest().query("FROM alias-1"))) { |
| 37 | + assertOk(response); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public void testResolvesDataStream() { |
| 42 | + // TODO |
| 43 | + } |
| 44 | + |
| 45 | + public void testResolvesPattern() { |
| 46 | + assertAcked(client().admin().indices().prepareCreate("index-1")); |
| 47 | + indexRandom(true, "index-1", 10); |
| 48 | + assertAcked(client().admin().indices().prepareCreate("index-2")); |
| 49 | + indexRandom(true, "index-2", 10); |
| 50 | + |
| 51 | + try (var response = run(syncEsqlQueryRequest().query("FROM index-*"))) { |
| 52 | + assertOk(response); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public void testDoesNotResolveMissingIndex() { |
| 57 | + expectThrows( |
| 58 | + VerificationException.class, |
| 59 | + containsString("Unknown index [no-such-index]"), |
| 60 | + () -> run(syncEsqlQueryRequest().query("FROM no-such-index")) |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + public void testDoesNotResolveEmptyPattern() { |
| 65 | + expectThrows( |
| 66 | + VerificationException.class, |
| 67 | + containsString("Unknown index [index-*]"), |
| 68 | + () -> run(syncEsqlQueryRequest().query("FROM index-*")) |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + public void testDoesNotResolveClosedIndex() { |
| 73 | + assertAcked(client().admin().indices().prepareCreate("index-1")); |
| 74 | + indexRandom(true, "index-1", 10); |
| 75 | + assertAcked(client().admin().indices().prepareClose("index-1")); |
| 76 | + |
| 77 | + expectThrows( |
| 78 | + ClusterBlockException.class, |
| 79 | + containsString("index [index-1] blocked by: [FORBIDDEN/4/index closed]"), |
| 80 | + () -> run(syncEsqlQueryRequest().query("FROM index-1")) |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + public void testPartialResolution() { |
| 85 | + // TODO |
| 86 | + } |
| 87 | + |
| 88 | + private static void assertOk(EsqlQueryResponse response) { |
| 89 | + assertThat(response.isPartial(), equalTo(false)); |
| 90 | + } |
| 91 | +} |
0 commit comments