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));
}
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" });
}
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));
}
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));
}
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);
}
Aggregations