All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.castled.warehouses.QueryPreviewExecutor Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package io.castled.warehouses;

import com.google.inject.Inject;
import io.castled.constants.CommonConstants;
import io.castled.jarvis.taskmanager.JarvisJobExecutor;
import io.castled.jarvis.taskmanager.models.Task;
import io.castled.models.QueryResults;
import io.castled.models.Warehouse;
import io.castled.utils.JsonUtils;

import java.util.Map;

@SuppressWarnings({"rawtypes", "unchecked"})
public class QueryPreviewExecutor implements JarvisJobExecutor {

    private final Map warehouseConnectors;
    private final WarehouseService warehouseService;

    @Inject
    public QueryPreviewExecutor(Map warehouseConnectors,
                                WarehouseService warehouseService) {
        this.warehouseConnectors = warehouseConnectors;
        this.warehouseService = warehouseService;
    }

    @Override
    public String executeJarvisJob(Task task) throws Exception {
        Long warehouseId = ((Number) task.getParams().get(CommonConstants.WAREHOUSE_ID)).longValue();
        String query = (String) task.getParams().get(CommonConstants.QUERY);
        Warehouse warehouse = this.warehouseService.getWarehouse(warehouseId);
        QueryResults queryResults = warehouseConnectors.get(warehouse.getType()).previewQuery(query, warehouse.getConfig(), 25);
        return JsonUtils.objectToString(queryResults);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy