Skip to content

Commit

Permalink
add table default impl of exist and create
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <[email protected]>
  • Loading branch information
penghuo committed Oct 27, 2022
1 parent 5c7b22a commit b286742
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/opensearch/sql/storage/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ public interface Table {

/**
* Check if current table exists.
*
* @return true if exists, otherwise false
*/
boolean exists();
default boolean exists() {
throw new UnsupportedOperationException("Unsupported Operation");
}

/**
* Create table given table schema.
*
* @param schema table schema
*/
void create(Map<String, ExprType> schema);
default void create(Map<String, ExprType> schema) {
throw new UnsupportedOperationException("Unsupported Operation");
}

/**
* Get the {@link ExprType} for each field in the table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.opensearch.sql.planner.physical.catalog;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
Expand Down Expand Up @@ -46,4 +47,21 @@ void testImplement() {
assertTrue(physicalPlan instanceof CatalogTableScan);
}

// todo. temporary added for code coverage. remove if required.
@Test
void testExist() {
UnsupportedOperationException exception =
assertThrows(UnsupportedOperationException.class,
() -> new CatalogTable(catalogService).exists());
assertEquals("Unsupported Operation", exception.getMessage());
}

// todo. temporary added for code coverage. remove if required.
@Test
void testCreateTable() {
UnsupportedOperationException exception =
assertThrows(UnsupportedOperationException.class,
() -> new CatalogTable(catalogService).create(new HashMap<>()));
assertEquals("Unsupported Operation", exception.getMessage());
}
}

0 comments on commit b286742

Please sign in to comment.