Search in sources :

Example 6 with View

use of com.hazelcast.sql.impl.schema.view.View in project hazelcast by hazelcast.

the class TableResolverImplTest method when_createsDuplicateViewsIfReplaceAndIfNotExists_then_succeeds.

@Test
public void when_createsDuplicateViewsIfReplaceAndIfNotExists_then_succeeds() {
    // given
    View view = view();
    // when
    catalog.createView(view, true, true);
    // then
    verify(tableStorage).putIfAbsent(eq(view.name()), isA(View.class));
}
Also used : View(com.hazelcast.sql.impl.schema.view.View) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with View

use of com.hazelcast.sql.impl.schema.view.View in project hazelcast by hazelcast.

the class MappingColumnsTableTest method test_rows.

@Test
public void test_rows() {
    // given
    Mapping mapping = new Mapping("table-name", "table-external-name", "table-type", singletonList(new MappingField("table-field-name", INT, "table-field-external-name")), emptyMap());
    View view = new View("view-name", "select * from table-name", false, singletonList("col1"), singletonList(INT));
    MappingColumnsTable mappingColumnsTable = new MappingColumnsTable("catalog", null, "schema", singletonList(mapping), singletonList(view));
    // when
    List<Object[]> rows = mappingColumnsTable.rows();
    // then
    assertThat(rows).containsExactlyInAnyOrder(new Object[] { "catalog", "schema", "table-name", "table-field-name", "table-field-external-name", 1, "true", "INTEGER" }, new Object[] { "catalog", "schema", "view-name", "col1", null, 1, "true", "INTEGER" });
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) View(com.hazelcast.sql.impl.schema.view.View) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with View

use of com.hazelcast.sql.impl.schema.view.View in project hazelcast by hazelcast.

the class TableResolverImplTest method when_createsViewIfNotExists_then_succeeds.

@Test
public void when_createsViewIfNotExists_then_succeeds() {
    // given
    View view = view();
    given(tableStorage.putIfAbsent(view.name(), view)).willReturn(true);
    // when
    catalog.createView(view, false, true);
    // then
    verify(tableStorage).putIfAbsent(eq(view.name()), isA(View.class));
}
Also used : View(com.hazelcast.sql.impl.schema.view.View) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with View

use of com.hazelcast.sql.impl.schema.view.View in project hazelcast by hazelcast.

the class TableResolverImplTest method when_createsView_then_succeeds.

// endregion
// region view storage tests
@Test
public void when_createsView_then_succeeds() {
    // given
    View view = view();
    given(tableStorage.putIfAbsent(view.name(), view)).willReturn(true);
    // when
    catalog.createView(view, false, false);
    // then
    verify(tableStorage).putIfAbsent(eq(view.name()), isA(View.class));
}
Also used : View(com.hazelcast.sql.impl.schema.view.View) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with View

use of com.hazelcast.sql.impl.schema.view.View in project hazelcast by hazelcast.

the class PlanExecutor method execute.

SqlResult execute(CreateViewPlan plan) {
    OptimizerContext context = plan.context();
    SqlNode sqlNode = context.parse(plan.viewQuery()).getNode();
    RelNode relNode = context.convert(sqlNode).getRel();
    List<RelDataTypeField> fieldList = relNode.getRowType().getFieldList();
    List<String> fieldNames = new ArrayList<>();
    List<QueryDataType> fieldTypes = new ArrayList<>();
    for (RelDataTypeField field : fieldList) {
        fieldNames.add(field.getName());
        fieldTypes.add(toHazelcastType(field.getType()));
    }
    View view = new View(plan.viewName(), plan.viewQuery(), plan.isStream(), fieldNames, fieldTypes);
    if (plan.isReplace()) {
        View existingView = catalog.getView(plan.viewName());
        if (existingView != null) {
            checkViewNewRowType(existingView, view);
        }
    }
    catalog.createView(view, plan.isReplace(), plan.ifNotExists());
    return UpdateSqlResultImpl.createUpdateCountResult(0);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelNode(org.apache.calcite.rel.RelNode) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) View(com.hazelcast.sql.impl.schema.view.View) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

View (com.hazelcast.sql.impl.schema.view.View)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Mapping (com.hazelcast.sql.impl.schema.Mapping)4 MappingField (com.hazelcast.sql.impl.schema.MappingField)4 ArrayList (java.util.ArrayList)4 QueryException (com.hazelcast.sql.impl.QueryException)2 EntryEvent (com.hazelcast.core.EntryEvent)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 SqlConnector (com.hazelcast.jet.sql.impl.connector.SqlConnector)1 SqlConnectorCache (com.hazelcast.jet.sql.impl.connector.SqlConnectorCache)1 MappingColumnsTable (com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable)1 MappingsTable (com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable)1 TablesTable (com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable)1 ViewsTable (com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable)1 ViewTable (com.hazelcast.jet.sql.impl.connector.virtual.ViewTable)1 NodeEngine (com.hazelcast.spi.impl.NodeEngine)1 CATALOG (com.hazelcast.sql.impl.QueryUtils.CATALOG)1