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

com.qubole.quark.catalog.json.SchemaFactory Maven / Gradle / Ivy

There is a newer version: 6.0.3
Show newest version
/*
 * Copyright (c) 2015. Qubole Inc
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.qubole.quark.catalog.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.google.common.collect.ImmutableList;

import com.qubole.quark.QuarkException;
import com.qubole.quark.planner.DataSourceSchema;
import com.qubole.quark.planner.QuarkFactory;
import com.qubole.quark.planner.QuarkFactoryResult;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * Sets up and organizes the planner with tables from all federated data sources.
 * The info argument encodes all the required information (described below) as
 * JSON.
 * Consider an example where there are 3 data sources:
 * 
    *
  • CANONICAL
  • *
  • CUBES
  • *
  • VIEWS
  • *
* CANONICAL is the default. Each of the data sources have many schemas and * tables. This class and its dependents set up such that the tables can be * referred as follows: *
    *
  • canonical.default.lineitem refers to a table in DEFAULT in CANONICAL.
  • *
  • canonical.tpch.customers refers to a table in TPCH in CANONICAL.
  • *
  • lineitem refers to a table in DEFAULT in CANONICAL.
  • *
  • CUBES.PUBLIC.WEB_RETURNS refers to a table in PUBLIC in CUBES.
  • *
* */ public class SchemaFactory implements QuarkFactory { private static final Logger LOG = LoggerFactory.getLogger(SchemaFactory.class); /** * Creates list of QuarkSchema * * @param info A JSON string which represents a RootSchema and its dependent objects. * @return * @throws QuarkException */ public QuarkFactoryResult create(Properties info) throws QuarkException { try { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new GuavaModule()); RootSchema rootSchema = objectMapper.readValue((String) info.get("model"), RootSchema.class); ImmutableList.Builder schemaList = new ImmutableList.Builder<>(); for (com.qubole.quark.catalog.json.DataSourceSchema secondary : rootSchema.dataSources) { schemaList.add(secondary); } return new QuarkFactoryResult(schemaList.build(), rootSchema.relSchema); } catch (java.io.IOException e) { LOG.error("Unexpected Exception during create", e); throw new QuarkException(e.getCause()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy