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