@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle)
{
ElasticsearchTableHandle handle = (ElasticsearchTableHandle) tableHandle;
ElasticsearchTableDescription table = client.getTable(handle.getSchemaName(), handle.getTableName());
if (table == null) {
throw new TableNotFoundException(handle.getSchemaTableName());
}
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
int index = 0;
for (ColumnMetadata column : client.getColumnMetadata(table)) {
Map<String, Object> properties = column.getProperties();
int ordinalPosition = (Integer) properties.get("ordinalPosition");
int position = ordinalPosition == -1 ? index : ordinalPosition;
columnHandles.put(column.getName(),
new ElasticsearchColumnHandle(
column.getName(),
column.getType(),
String.valueOf(properties.get("jsonPath")),
String.valueOf(properties.get("jsonType")),
position,
(Boolean) properties.get("isList")));
index++;
}
return columnHandles.build();
}