use of com.thinkbiganalytics.schema.DefaultJdbcTable in project kylo by Teradata.
the class HiveMetastoreService method listTables.
@Nonnull
public List<JdbcTable> listTables(@Nullable final String catalog, @Nullable final String schema, @Nullable final String pattern, @Nullable final Pageable pageable) {
String query = "SELECT d.NAME as \"DATABASE_NAME\", t.TBL_NAME, t.TBL_TYPE, p.PARAM_VALUE" + " FROM TBLS t" + " JOIN DBS d on d.DB_ID = t.DB_ID" + " LEFT JOIN TABLE_PARAMS p on p.TBL_ID = t.TBL_ID AND p.PARAM_KEY = \"comment\"" + " WHERE d.NAME LIKE ? " + " AND t.TBL_NAME LIKE ? " + " ORDER BY \"DATABASE_NAME\", t.TBL_NAME";
if (DatabaseType.POSTGRES.equals(getMetastoreDatabaseType())) {
query = "SELECT d.\"NAME\" as \"DATABASE_NAME\", t.\"TBL_NAME\", t.\"TBL_TYPE\", p.\"PARAM_VALUE\"" + " FROM \"TBLS\" t" + " JOIN \"DBS\" d on d.\"DB_ID\" = t.\"DB_ID\" " + " LEFT JOIN \"TABLE_PARAMS\" p ON p.\"TBL_ID\" = t.\"TBL_ID\" and p.\"PARAM_KEY\" = 'comment'" + " WHERE d.\"NAME\" LIKE ? " + " AND t.\"TBL_NAME\" LIKE ? " + " ORDER BY d.\"NAME\", t.\"TBL_NAME\"";
}
final List<JdbcTable> tables = hiveMetatoreJdbcTemplate.query(query, ps -> {
ps.setString(1, schema == null ? "%" : schema);
ps.setString(2, pattern == null ? "%" : "%" + pattern + "%");
}, (rs, i) -> {
final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(rs.getString("TBL_NAME"), rs.getString("TBL_TYPE"));
jdbcTable.setIdentifierQuoteString("`");
jdbcTable.setRemarks(rs.getString("PARAM_VALUE"));
jdbcTable.setSchema(rs.getString("DATABASE_NAME"));
return jdbcTable;
});
if (userImpersonationEnabled) {
return tables.stream().filter(jdbcTable -> hiveService.isTableAccessibleByImpersonatedUser(jdbcTable.getSchema() + "." + jdbcTable.getName())).collect(Collectors.toList());
} else {
return tables;
}
}
use of com.thinkbiganalytics.schema.DefaultJdbcTable 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());
}
}
Aggregations