Search in sources :

Example 1 with SchemaSearchResultData

use of com.thinkbiganalytics.search.rest.model.SchemaSearchResultData in project kylo by Teradata.

the class SolrSearchResultTransform method getSchemaSearchResultData.

private SchemaSearchResultData getSchemaSearchResultData(Map<String, Object> solrDocumentFieldValueMap, QueryResponse solrResponse) {
    SchemaSearchResultData schemaSearchResultData = new SchemaSearchResultData();
    schemaSearchResultData.setDatabaseName(toString(solrDocumentFieldValueMap.get("databaseName")));
    schemaSearchResultData.setDatabaseOwner(toString(solrDocumentFieldValueMap.get("databaseOwner")));
    schemaSearchResultData.setTableCreateTime(toString(solrDocumentFieldValueMap.get("tableCreateTime")));
    schemaSearchResultData.setTableName(toString(solrDocumentFieldValueMap.get("tableName")));
    schemaSearchResultData.setTableType(toString(solrDocumentFieldValueMap.get("tableType")));
    List<HiveColumn> hiveColumns = new ArrayList<>();
    List<Pair> highlightsList = new ArrayList<>();
    if (solrDocumentFieldValueMap.containsKey("columnName")) {
        hiveColumns.add(new HiveColumn(toString(solrDocumentFieldValueMap.get("columnName")), toString(solrDocumentFieldValueMap.get("columnType")), toString(solrDocumentFieldValueMap.get("columnComment"))));
    } else if (solrDocumentFieldValueMap.containsKey("hiveColumns")) {
        @SuppressWarnings("unchecked") final List<Map<String, Object>> columns = ObjectMapperSerializer.deserialize(toString(solrDocumentFieldValueMap.get("hiveColumns")), List.class);
        columns.forEach(column -> {
            hiveColumns.add(new HiveColumn(toString(column.get("columnName")), toString(column.get("columnType")), toString(column.get("columnComment"))));
        });
    }
    for (Map.Entry<String, List<String>> entry : solrResponse.getHighlighting().get(solrDocumentFieldValueMap.get("id")).entrySet()) {
        String key = entry.getKey();
        if (key.equals("columnName")) {
            key = "Column name";
        }
        if (entry.getValue().size() >= 1) {
            highlightsList.add(new Pair(key, entry.getValue().get(0)));
        }
    }
    schemaSearchResultData.setHighlights(highlightsList);
    schemaSearchResultData.setHiveColumns(hiveColumns);
    schemaSearchResultData.setRawData(solrDocumentFieldValueMap);
    schemaTypeResultCount += 1L;
    return schemaSearchResultData;
}
Also used : TableSearchResultData(com.thinkbiganalytics.search.rest.model.TableSearchResultData) SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) HiveColumn(com.thinkbiganalytics.search.rest.model.HiveColumn) SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult) SearchResultData(com.thinkbiganalytics.search.rest.model.SearchResultData) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) HashMap(java.util.HashMap) Pair(com.thinkbiganalytics.search.rest.model.Pair) SearchResultType(com.thinkbiganalytics.search.rest.model.SearchResultType) ArrayList(java.util.ArrayList) Objects(java.util.Objects) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) UnknownTypeSearchResultData(com.thinkbiganalytics.search.rest.model.UnknownTypeSearchResultData) SolrDocument(org.apache.solr.common.SolrDocument) List(java.util.List) SearchIndex(com.thinkbiganalytics.search.api.SearchIndex) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HiveColumn(com.thinkbiganalytics.search.rest.model.HiveColumn) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Example 2 with SchemaSearchResultData

use of com.thinkbiganalytics.search.rest.model.SchemaSearchResultData in project kylo by Teradata.

the class ElasticSearchRestSearchResultTransform method getSchemaSearchResultData.

private SchemaSearchResultData getSchemaSearchResultData(ElasticSearchRestSearchHit elasticSearchRestSearchHit) {
    final String DATABASE_NAME = "databaseName";
    final String DATABASE_OWNER = "databaseOwner";
    final String TABLE_CREATE_TIME = "tableCreateTime";
    final String TABLE_NAME = "tableName";
    final String TABLE_TYPE = "tableType";
    final String HIVE_COLUMNS = "hiveColumns";
    final String COLUMN_TYPE = "columnType";
    final String COLUMN_NAME = "columnName";
    final String COLUMN_COMMENT = "columnComment";
    final String HIVE_COLUMNS_COLUMN_TYPE = HIVE_COLUMNS + "." + COLUMN_TYPE;
    final String HIVE_COLUMNS_COLUMN_TYPE_NEW_DESCRIPTION = "Column type";
    final String HIVE_COLUMNS_COLUMN_NAME = HIVE_COLUMNS + "." + COLUMN_NAME;
    final String HIVE_COLUMNS_COLUMN_NAME_NEW_DESCRIPTION = "Column name";
    final String HIVE_COLUMNS_COLUMN_COMMENT = HIVE_COLUMNS + "." + COLUMN_COMMENT;
    final String HIVE_COLUMNS_COLUMN_COMMENT_NEW_DESCRIPTION = "Column comment";
    SchemaSearchResultData schemaSearchResultData = new SchemaSearchResultData();
    schemaSearchResultData.setDatabaseName(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(DATABASE_NAME, EMPTY_STRING).toString());
    schemaSearchResultData.setDatabaseOwner(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(DATABASE_OWNER, EMPTY_STRING).toString());
    schemaSearchResultData.setTableCreateTime(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TABLE_CREATE_TIME, EMPTY_STRING).toString());
    schemaSearchResultData.setTableName(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TABLE_NAME, EMPTY_STRING).toString());
    schemaSearchResultData.setTableType(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TABLE_TYPE, EMPTY_STRING).toString());
    List<HiveColumn> hiveColumns = new ArrayList<>();
    List<Pair> highlightsList = new ArrayList<>();
    if (!CollectionUtils.isEmpty(elasticSearchRestSearchHit.getHiveColumns())) {
        hiveColumns.addAll(elasticSearchRestSearchHit.getHiveColumns());
    }
    for (Pair highlightPair : elasticSearchRestSearchHit.getHighlights()) {
        String key = highlightPair.getKey();
        switch(key) {
            case HIVE_COLUMNS_COLUMN_TYPE:
                key = HIVE_COLUMNS_COLUMN_TYPE_NEW_DESCRIPTION;
                break;
            case HIVE_COLUMNS_COLUMN_NAME:
                key = HIVE_COLUMNS_COLUMN_NAME_NEW_DESCRIPTION;
                break;
            case HIVE_COLUMNS_COLUMN_COMMENT:
                key = HIVE_COLUMNS_COLUMN_COMMENT_NEW_DESCRIPTION;
                break;
            default:
                break;
        }
        highlightsList.add(new Pair(key, highlightPair.getValue()));
    }
    schemaSearchResultData.setHighlights(highlightsList);
    schemaSearchResultData.setHiveColumns(hiveColumns);
    Map<String, Object> rawData = new HashMap<>();
    rawData.put(RAW_DATA_KEY, elasticSearchRestSearchHit.getRawHit());
    schemaSearchResultData.setRawData(rawData);
    schemaTypeResultCount += 1L;
    return schemaSearchResultData;
}
Also used : SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HiveColumn(com.thinkbiganalytics.search.rest.model.HiveColumn) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Example 3 with SchemaSearchResultData

use of com.thinkbiganalytics.search.rest.model.SchemaSearchResultData in project kylo by Teradata.

the class ElasticSearchSearchResultTransform method getSchemaSearchResultData.

private SchemaSearchResultData getSchemaSearchResultData(SearchHit searchHit) {
    final String DATABASE_NAME = "databaseName";
    final String DATABASE_OWNER = "databaseOwner";
    final String TABLE_CREATE_TIME = "tableCreateTime";
    final String TABLE_NAME = "tableName";
    final String TABLE_TYPE = "tableType";
    final String HIVE_COLUMNS = "hiveColumns";
    final String COLUMN_TYPE = "columnType";
    final String COLUMN_NAME = "columnName";
    final String COLUMN_COMMENT = "columnComment";
    final String HIVE_COLUMNS_COLUMN_TYPE = HIVE_COLUMNS + "." + COLUMN_TYPE;
    final String HIVE_COLUMNS_COLUMN_TYPE_NEW_DESCRIPTION = "Column type";
    final String HIVE_COLUMNS_COLUMN_NAME = HIVE_COLUMNS + "." + COLUMN_NAME;
    final String HIVE_COLUMNS_COLUMN_NAME_NEW_DESCRIPTION = "Column name";
    final String HIVE_COLUMNS_COLUMN_COMMENT = HIVE_COLUMNS + "." + COLUMN_COMMENT;
    final String HIVE_COLUMNS_COLUMN_COMMENT_NEW_DESCRIPTION = "Column comment";
    Map<String, Object> searchHitSourceMap = searchHit.sourceAsMap();
    SchemaSearchResultData schemaSearchResultData = new SchemaSearchResultData();
    schemaSearchResultData.setDatabaseName(searchHitSourceMap.getOrDefault(DATABASE_NAME, "").toString());
    schemaSearchResultData.setDatabaseOwner(searchHitSourceMap.getOrDefault(DATABASE_OWNER, "").toString());
    schemaSearchResultData.setTableCreateTime(searchHitSourceMap.getOrDefault(TABLE_CREATE_TIME, "").toString());
    schemaSearchResultData.setTableName(searchHitSourceMap.getOrDefault(TABLE_NAME, "").toString());
    schemaSearchResultData.setTableType(searchHitSourceMap.getOrDefault(TABLE_TYPE, "").toString());
    List<HiveColumn> hiveColumns = new ArrayList<>();
    List<Pair> highlightsList = new ArrayList<>();
    @SuppressWarnings("unchecked") List<Map<String, String>> hiveColumnsListOfMaps = (List<Map<String, String>>) searchHitSourceMap.getOrDefault(HIVE_COLUMNS, Collections.emptyList());
    for (Map<String, String> hiveColumnsMap : hiveColumnsListOfMaps) {
        String columnName = "";
        String columnType = "";
        String columnComment = "";
        for (Map.Entry<String, String> hiveColumnEntry : hiveColumnsMap.entrySet()) {
            if (hiveColumnEntry.getKey().equals(COLUMN_TYPE)) {
                columnType = hiveColumnEntry.getValue();
            } else if (hiveColumnEntry.getKey().equals(COLUMN_NAME)) {
                columnName = hiveColumnEntry.getValue();
            } else if (hiveColumnEntry.getKey().equals(COLUMN_COMMENT)) {
                columnComment = hiveColumnEntry.getValue();
            }
        }
        hiveColumns.add(new HiveColumn(columnName, columnType, columnComment));
    }
    Map<String, HighlightField> highlights = searchHit.getHighlightFields();
    for (Map.Entry<String, HighlightField> entry : highlights.entrySet()) {
        String key = entry.getKey();
        switch(key) {
            case HIVE_COLUMNS_COLUMN_TYPE:
                key = HIVE_COLUMNS_COLUMN_TYPE_NEW_DESCRIPTION;
                break;
            case HIVE_COLUMNS_COLUMN_NAME:
                key = HIVE_COLUMNS_COLUMN_NAME_NEW_DESCRIPTION;
                break;
            case HIVE_COLUMNS_COLUMN_COMMENT:
                key = HIVE_COLUMNS_COLUMN_COMMENT_NEW_DESCRIPTION;
                break;
        }
        if (entry.getValue().getFragments().length >= 1) {
            highlightsList.add(new Pair(key, entry.getValue().getFragments()[0].toString()));
        }
    }
    schemaSearchResultData.setHighlights(highlightsList);
    schemaSearchResultData.setHiveColumns(hiveColumns);
    schemaSearchResultData.setRawData(searchHit.getSource());
    schemaTypeResultCount += 1L;
    return schemaSearchResultData;
}
Also used : ArrayList(java.util.ArrayList) HighlightField(org.elasticsearch.search.highlight.HighlightField) SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) ArrayList(java.util.ArrayList) List(java.util.List) HiveColumn(com.thinkbiganalytics.search.rest.model.HiveColumn) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Aggregations

HiveColumn (com.thinkbiganalytics.search.rest.model.HiveColumn)3 Pair (com.thinkbiganalytics.search.rest.model.Pair)3 SchemaSearchResultData (com.thinkbiganalytics.search.rest.model.SchemaSearchResultData)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)2 Map (java.util.Map)2 ObjectMapperSerializer (com.thinkbiganalytics.json.ObjectMapperSerializer)1 SearchIndex (com.thinkbiganalytics.search.api.SearchIndex)1 SearchResult (com.thinkbiganalytics.search.rest.model.SearchResult)1 SearchResultData (com.thinkbiganalytics.search.rest.model.SearchResultData)1 SearchResultType (com.thinkbiganalytics.search.rest.model.SearchResultType)1 TableSearchResultData (com.thinkbiganalytics.search.rest.model.TableSearchResultData)1 UnknownTypeSearchResultData (com.thinkbiganalytics.search.rest.model.UnknownTypeSearchResultData)1 Objects (java.util.Objects)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 HighlightField (org.elasticsearch.search.highlight.HighlightField)1