Search in sources :

Example 1 with ScanBasedQueryProcessor

use of com.linkedin.pinot.tools.scan.query.ScanBasedQueryProcessor in project pinot by linkedin.

the class HybridClusterScanComparisonIntegrationTest method configureScanBasedComparator.

private void configureScanBasedComparator(List<Pair<File, File>> enabledRealtimeSegments) throws Exception {
    // Deduplicate overlapping realtime and offline segments
    Set<String> enabledAvroFiles = new HashSet<String>();
    List<File> segmentsToUnpack = new ArrayList<File>();
    LOGGER.info("Offline avro to segment map {}", _offlineAvroToSegmentMap);
    LOGGER.info("Enabled realtime segments {}", enabledRealtimeSegments);
    for (Map.Entry<File, File> avroAndSegment : _offlineAvroToSegmentMap.entrySet()) {
        if (!enabledAvroFiles.contains(avroAndSegment.getKey().getName())) {
            enabledAvroFiles.add(avroAndSegment.getKey().getName());
            segmentsToUnpack.add(avroAndSegment.getValue());
        }
    }
    for (Pair<File, File> avroAndSegment : enabledRealtimeSegments) {
        if (!enabledAvroFiles.contains(avroAndSegment.getLeft().getName())) {
            enabledAvroFiles.add(avroAndSegment.getLeft().getName());
            segmentsToUnpack.add(avroAndSegment.getRight());
        }
    }
    LOGGER.info("Enabled Avro files {}", enabledAvroFiles);
    // Unpack enabled segments
    ensureDirectoryExistsAndIsEmpty(_unpackedSegments);
    for (File file : segmentsToUnpack) {
        LOGGER.info("Unpacking file {}", file);
        TarGzCompressionUtils.unTar(file, _unpackedSegments);
    }
    _scanBasedQueryProcessor = new ScanBasedQueryProcessor(_unpackedSegments.getAbsolutePath());
}
Also used : ScanBasedQueryProcessor(com.linkedin.pinot.tools.scan.query.ScanBasedQueryProcessor) ArrayList(java.util.ArrayList) File(java.io.File) Map(java.util.Map) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 2 with ScanBasedQueryProcessor

use of com.linkedin.pinot.tools.scan.query.ScanBasedQueryProcessor in project pinot by linkedin.

the class QueryComparison method runFunctionMode.

private void runFunctionMode() throws Exception {
    BufferedReader resultReader = null;
    ScanBasedQueryProcessor scanBasedQueryProcessor = null;
    try (BufferedReader queryReader = new BufferedReader(new InputStreamReader(new FileInputStream(_queryFile), "UTF8"))) {
        if (_resultFile == null) {
            scanBasedQueryProcessor = new ScanBasedQueryProcessor(_segmentsDir.getAbsolutePath());
        } else {
            resultReader = new BufferedReader(new InputStreamReader(new FileInputStream(_resultFile), "UTF8"));
        }
        int passed = 0;
        int total = 0;
        String query;
        while ((query = queryReader.readLine()) != null) {
            if (query.isEmpty() || query.startsWith("#")) {
                continue;
            }
            JSONObject expectedJson = null;
            try {
                if (resultReader != null) {
                    expectedJson = new JSONObject(resultReader.readLine());
                } else {
                    QueryResponse expectedResponse = scanBasedQueryProcessor.processQuery(query);
                    expectedJson = new JSONObject(new ObjectMapper().writeValueAsString(expectedResponse));
                }
            } catch (Exception e) {
                LOGGER.error("Comparison FAILED: Id: {} Exception caught while getting expected response for query: '{}'", total, query, e);
            }
            JSONObject actualJson = null;
            if (expectedJson != null) {
                try {
                    actualJson = new JSONObject(_clusterStarter.query(query));
                } catch (Exception e) {
                    LOGGER.error("Comparison FAILED: Id: {} Exception caught while running query: '{}'", total, query, e);
                }
            }
            if (expectedJson != null && actualJson != null) {
                try {
                    if (compare(actualJson, expectedJson)) {
                        passed++;
                        LOGGER.info("Comparison PASSED: Id: {} actual Time: {} ms expected Time: {} ms Docs Scanned: {}", total, actualJson.get(TIME_USED_MS), expectedJson.get(TIME_USED_MS), actualJson.get(NUM_DOCS_SCANNED));
                        LOGGER.debug("actual Response: {}", actualJson);
                        LOGGER.debug("expected Response: {}", expectedJson);
                    } else {
                        LOGGER.error("Comparison FAILED: Id: {} query: {}", query);
                        LOGGER.info("actual Response: {}", actualJson);
                        LOGGER.info("expected Response: {}", expectedJson);
                    }
                } catch (Exception e) {
                    LOGGER.error("Comparison FAILED: Id: {} Exception caught while comparing query: '{}' actual response: {}, expected response: {}", total, query, actualJson, expectedJson, e);
                }
            }
            total++;
        }
        LOGGER.info("Total {} out of {} queries passed.", passed, total);
    } finally {
        if (resultReader != null) {
            resultReader.close();
        }
    }
}
Also used : ScanBasedQueryProcessor(com.linkedin.pinot.tools.scan.query.ScanBasedQueryProcessor) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.JSONObject) QueryResponse(com.linkedin.pinot.tools.scan.query.QueryResponse) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JSONException(org.json.JSONException)

Aggregations

ScanBasedQueryProcessor (com.linkedin.pinot.tools.scan.query.ScanBasedQueryProcessor)2 QueryResponse (com.linkedin.pinot.tools.scan.query.QueryResponse)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1