Search in sources :

Example 1 with DataSetTemplate

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate in project kylo by Teradata.

the class SparkShellProxyController method addDataSourceInformation.

private DataSet addDataSourceInformation(@Nonnull DataSet dataSet) {
    DataSet fetchedDataSet = fetchDataSet(dataSet.getId());
    DataSetTemplate template = DataSetUtil.mergeTemplates(fetchedDataSet);
    fetchedDataSet.getDataSource().setTemplate(template);
    return new DataSet(fetchedDataSet);
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)

Example 2 with DataSetTemplate

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate in project kylo by Teradata.

the class AbstractKyloCatalogClient method write.

@Nonnull
@Override
public KyloCatalogWriter<T> write(@Nonnull final T source, @Nonnull final String targetId) {
    final DataSetTemplate dataSet = (dataSets != null) ? dataSets.get(targetId) : null;
    if (dataSet != null) {
        final DefaultKyloCatalogWriter<T> writer = new DefaultKyloCatalogWriter<>(this, hadoopConfiguration, resourceLoader, source);
        writer.dataSet(dataSet);
        return writer;
    } else {
        throw new KyloCatalogException("Data set does not exist: " + targetId);
    }
}
Also used : KyloCatalogException(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogException) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) Nonnull(javax.annotation.Nonnull)

Example 3 with DataSetTemplate

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate in project kylo by Teradata.

the class AbstractCatalogDataSetProvider method readDataSet.

public T readDataSet(@Nonnull final DataSet dataSet) {
    final DataSetTemplate dataSetTemplate = mergeTemplates(dataSet);
    KyloCatalogReader<T> reader = getClient().read().options(dataSetTemplate.getOptions()).addJars(dataSetTemplate.getJars()).addFiles(dataSetTemplate.getFiles()).format(dataSetTemplate.getFormat());
    T dataFrame;
    if (dataSet.getPaths() != null && !dataSet.getPaths().isEmpty()) {
        if (dataSet.getPaths().size() > 1) {
            dataFrame = reader.load(dataSet.getPaths().toArray(new String[0]));
        } else {
            dataFrame = reader.load(dataSet.getPaths().get(0));
        }
    } else {
        dataFrame = reader.load();
    }
    return dataFrame;
}
Also used : DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)

Example 4 with DataSetTemplate

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate in project kylo by Teradata.

the class DefaultCatalogTableManager method getTableNames.

@Nonnull
@Override
public List<String> getTableNames(@Nonnull final DataSource dataSource, @Nullable final String schemaName, @Nullable final String tableName) throws SQLException {
    final DataSetTemplate template = DataSourceUtil.mergeTemplates(dataSource);
    return isolatedFunction(template, schemaName, (connection, schemaParser) -> {
        final javax.sql.DataSource ds = new SingleConnectionDataSource(connection, true);
        final DBSchemaParser tableSchemaParser = new DBSchemaParser(ds, new KerberosTicketConfiguration());
        return tableSchemaParser.listTables(schemaName, tableName);
    });
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) Nonnull(javax.annotation.Nonnull)

Example 5 with DataSetTemplate

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate in project kylo by Teradata.

the class DefaultCatalogTableManager method describeTable.

@Nonnull
@Override
public CatalogTableSchema describeTable(@Nonnull final DataSource dataSource, @Nullable final String schemaName, @Nullable final String tableName) throws SQLException {
    final DataSetTemplate template = DataSourceUtil.mergeTemplates(dataSource);
    if (Objects.equals("hive", template.getFormat())) {
        final TableSchema tableSchema = hiveMetastoreService.getTable(schemaName, tableName);
        final CatalogTableSchema catalogTableSchema = new CatalogTableSchema(tableSchema);
        // Get table metadata
        if (StringUtils.isNotEmpty(tableSchema.getName())) {
            final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(tableSchema.getName(), "TABLE");
            jdbcTable.setCatalog(tableSchema.getDatabaseName());
            jdbcTable.setCatalog(tableSchema.getDatabaseName());
            jdbcTable.setRemarks(tableSchema.getDescription());
            jdbcTable.setSchema(tableSchema.getSchemaName());
            jdbcTable.setCatalogSeparator(".");
            jdbcTable.setIdentifierQuoteString("`");
            catalogTableSchema.setTable(createTable(jdbcTable));
        }
        return catalogTableSchema;
    } else if (Objects.equals("jdbc", template.getFormat())) {
        return isolatedFunction(template, schemaName, (connection, schemaParser) -> {
            final javax.sql.DataSource ds = new SingleConnectionDataSource(connection, true);
            final DBSchemaParser tableSchemaParser = new DBSchemaParser(ds, new KerberosTicketConfiguration());
            final TableSchema tableSchema = tableSchemaParser.describeTable(schemaName, tableName);
            if (tableSchema != null) {
                // Get table metadata
                final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(tableSchema.getName(), "TABLE");
                jdbcTable.setCatalog(tableSchema.getDatabaseName());
                jdbcTable.setCatalog(tableSchema.getDatabaseName());
                jdbcTable.setRemarks(tableSchema.getDescription());
                jdbcTable.setSchema(tableSchema.getSchemaName());
                jdbcTable.setMetaData(connection.getMetaData());
                // Return table schema
                final CatalogTableSchema catalogTableSchema = new CatalogTableSchema(tableSchema);
                catalogTableSchema.setTable(createTable(jdbcTable));
                return catalogTableSchema;
            } else {
                return null;
            }
        });
    } else {
        throw new IllegalArgumentException("Unsupported format: " + template.getFormat());
    }
}
Also used : PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) LoadingCache(com.google.common.cache.LoadingCache) Connection(java.sql.Connection) DataSourceUtil(com.thinkbiganalytics.kylo.catalog.datasource.DataSourceUtil) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) DataSetUtil(com.thinkbiganalytics.kylo.catalog.dataset.DataSetUtil) StringUtils(org.apache.commons.lang3.StringUtils) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) Value(org.springframework.beans.factory.annotation.Value) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Configuration(org.apache.hadoop.conf.Configuration) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) HiveMetastoreService(com.thinkbiganalytics.hive.service.HiveMetastoreService) DefaultJdbcTable(com.thinkbiganalytics.schema.DefaultJdbcTable) Nonnull(javax.annotation.Nonnull) JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Properties(java.util.Properties) Set(java.util.Set) JdbcCatalog(com.thinkbiganalytics.discovery.schema.JdbcCatalog) HadoopClassLoader(com.thinkbiganalytics.kylo.util.HadoopClassLoader) Collectors(java.util.stream.Collectors) JdbcSchemaParserProvider(com.thinkbiganalytics.schema.JdbcSchemaParserProvider) KerberosUtil(com.thinkbiganalytics.kerberos.KerberosUtil) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) List(java.util.List) JdbcSchema(com.thinkbiganalytics.discovery.schema.JdbcSchema) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CacheBuilder(com.google.common.cache.CacheBuilder) JdbcTable(com.thinkbiganalytics.discovery.schema.JdbcTable) DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) DefaultJdbcTable(com.thinkbiganalytics.schema.DefaultJdbcTable) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Nonnull(javax.annotation.Nonnull)

Aggregations

DataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate)10 Nonnull (javax.annotation.Nonnull)7 DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)4 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)4 DefaultDataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)4 DataSourceUtil (com.thinkbiganalytics.kylo.catalog.datasource.DataSourceUtil)3 List (java.util.List)3 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)2 KyloCatalogException (com.thinkbiganalytics.kylo.catalog.api.KyloCatalogException)2 Connector (com.thinkbiganalytics.kylo.catalog.rest.model.Connector)2 DBSchemaParser (com.thinkbiganalytics.schema.DBSchemaParser)2 Nullable (javax.annotation.Nullable)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Configuration (org.apache.hadoop.conf.Configuration)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 SingleConnectionDataSource (org.springframework.jdbc.datasource.SingleConnectionDataSource)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1