Search in sources :

Example 16 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class MappingsTable method rows.

@Override
protected List<Object[]> rows() {
    List<Object[]> rows = new ArrayList<>(mappings.size());
    for (Mapping mapping : mappings) {
        Object[] row = new Object[] { catalog(), mappingsSchema, mapping.name(), mapping.externalName(), mapping.type(), uncheckCall(() -> JsonUtil.toJson(mapping.options())) };
        rows.add(row);
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) Mapping(com.hazelcast.sql.impl.schema.Mapping)

Example 17 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TablesStorage method awaitMappingOnAllMembers.

/**
 * Temporary measure to ensure schema is propagated to all the members.
 */
@SuppressWarnings("BusyWait")
private void awaitMappingOnAllMembers(String name, IdentifiedDataSerializable metadata) {
    Data keyData = nodeEngine.getSerializationService().toData(name);
    int keyPartitionId = nodeEngine.getPartitionService().getPartitionId(keyData);
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Address> memberAddresses = getMemberAddresses();
    for (int i = 0; i < MAX_CHECK_ATTEMPTS && !memberAddresses.isEmpty(); i++) {
        List<CompletableFuture<Address>> futures = memberAddresses.stream().map(memberAddress -> {
            Operation operation = new GetOperation(CATALOG_MAP_NAME, keyData).setPartitionId(keyPartitionId).setValidateTarget(false);
            return operationService.createInvocationBuilder(ReplicatedMapService.SERVICE_NAME, operation, memberAddress).setTryCount(1).invoke().toCompletableFuture().thenApply(result -> Objects.equals(metadata, result) ? memberAddress : null);
        }).collect(toList());
        for (CompletableFuture<Address> future : futures) {
            try {
                memberAddresses.remove(future.join());
            } catch (Exception e) {
                logger.warning("Error occurred while trying to fetch mapping: " + e.getMessage(), e);
            }
        }
        if (!memberAddresses.isEmpty()) {
            try {
                Thread.sleep(SLEEP_MILLIS);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}
Also used : EntryEvent(com.hazelcast.core.EntryEvent) Address(com.hazelcast.cluster.Address) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Member(com.hazelcast.cluster.Member) Collection(java.util.Collection) Data(com.hazelcast.internal.serialization.Data) EntryListener(com.hazelcast.core.EntryListener) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) Objects(java.util.Objects) Mapping(com.hazelcast.sql.impl.schema.Mapping) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ILogger(com.hazelcast.logging.ILogger) GetOperation(com.hazelcast.replicatedmap.impl.operation.GetOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MemberSelectors(com.hazelcast.cluster.memberselector.MemberSelectors) View(com.hazelcast.sql.impl.schema.view.View) MapEvent(com.hazelcast.map.MapEvent) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Collectors.toSet(java.util.stream.Collectors.toSet) GetOperation(com.hazelcast.replicatedmap.impl.operation.GetOperation) Address(com.hazelcast.cluster.Address) Data(com.hazelcast.internal.serialization.Data) GetOperation(com.hazelcast.replicatedmap.impl.operation.GetOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) CompletableFuture(java.util.concurrent.CompletableFuture) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 18 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class MetadataResolver method resolve.

@Nullable
@Override
public Mapping resolve(String iMapName) {
    MapService service = nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext context = service.getMapServiceContext();
    MapContainer container = context.getExistingMapContainer(iMapName);
    if (container == null) {
        return null;
    }
    boolean hd = container.getMapConfig().getInMemoryFormat() == InMemoryFormat.NATIVE;
    Metadata metadata = hd ? resolveFromHd(container) : resolveFromHeap(iMapName, context);
    return metadata == null ? null : new Mapping(iMapName, iMapName, TYPE_NAME, metadata.fields(), metadata.options());
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer) Nullable(javax.annotation.Nullable)

Example 19 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class HazelcastSqlValidator method newValidationError.

@Override
public CalciteContextException newValidationError(SqlNode node, Resources.ExInst<SqlValidatorException> e) {
    assert node != null;
    CalciteContextException exception = SqlUtil.newContextException(node.getParserPosition(), e);
    if (OBJECT_NOT_FOUND.equals(ResourceUtil.key(e)) || OBJECT_NOT_FOUND_WITHIN.equals(ResourceUtil.key(e))) {
        Object[] arguments = ResourceUtil.args(e);
        String identifier = (arguments != null && arguments.length > 0) ? String.valueOf(arguments[0]) : null;
        Mapping mapping = identifier != null ? iMapResolver.resolve(identifier) : null;
        String sql = mapping != null ? SqlCreateMapping.unparse(mapping) : null;
        String message = sql != null ? ValidatorResource.imapNotMapped(e.str(), identifier, sql) : e.str();
        throw QueryException.error(SqlErrorCode.OBJECT_NOT_FOUND, message, exception, sql);
    }
    return exception;
}
Also used : CalciteContextException(org.apache.calcite.runtime.CalciteContextException) SqlCreateMapping(com.hazelcast.jet.sql.impl.parse.SqlCreateMapping) Mapping(com.hazelcast.sql.impl.schema.Mapping)

Example 20 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImpl method resolveMapping.

private Mapping resolveMapping(Mapping mapping) {
    String type = mapping.type();
    Map<String, String> options = mapping.options();
    SqlConnector connector = connectorCache.forType(type);
    List<MappingField> resolvedFields = connector.resolveAndValidateFields(nodeEngine, options, mapping.fields());
    return new Mapping(mapping.name(), mapping.externalName(), type, new ArrayList<>(resolvedFields), new LinkedHashMap<>(options));
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Aggregations

Mapping (com.hazelcast.sql.impl.schema.Mapping)20 MappingField (com.hazelcast.sql.impl.schema.MappingField)11 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 View (com.hazelcast.sql.impl.schema.view.View)6 ArrayList (java.util.ArrayList)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 MemberSelectors (com.hazelcast.cluster.memberselector.MemberSelectors)2 EntryEvent (com.hazelcast.core.EntryEvent)2 CreateMappingPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan)2 SqlCreateMapping (com.hazelcast.jet.sql.impl.parse.SqlCreateMapping)2 ILogger (com.hazelcast.logging.ILogger)2 QueryException (com.hazelcast.sql.impl.QueryException)2 List (java.util.List)2 Objects (java.util.Objects)2 Collectors.toList (java.util.stream.Collectors.toList)2 Nullable (javax.annotation.Nullable)2 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1