@Override public boolean datasetExists(NamespaceKey key) { if (key.size() != 3) { return false; } try{ return getDataset(key, null, DatasetRetrievalOptions.IGNORE_AUTHZ_ERRORS) != null; } catch (Exception e) { logger.warn("Failure while evaluating if dataset '{}' exists.", key, e); return false; } }
@Override public boolean datasetExists(NamespaceKey key) { return key.size() == 2 && TABLES.contains(key.getName().toLowerCase()); }
@Override public boolean datasetExists(NamespaceKey key) { return key.size() == 2 && TABLES.contains(key.getName().toLowerCase()); }
public static TableName getTableName(NamespaceKey key) { switch(key.size()) { case 2: return TableName.valueOf(key.getName()); case 3: final List<String> paths = key.getPathComponents(); return TableName.valueOf(paths.get(1), paths.get(2)); default: throw new IllegalStateException("Unexpected key length: " + key); } } }
/** * A path is ambiguous if it has two parts and the root contains a period. In this case, we don't * know whether the root should be considered a single part of many parts and need to do a search * for an unescaped path rather than a lookup. * * This is because JDBC & ODBC tools use a two part naming scheme and thus we also present Dremio * datasets using this two part scheme where all parts of the path except the leaf are presented * as part of the schema of the table. This relates to DX- * * @param key * Key to test * @return Whether path is ambiguous. */ private boolean isAmbiguousKey(NamespaceKey key) { if(key.size() != 2) { return false; } return key.getRoot().contains("."); }
@Override public SourceTableDefinition getDataset(NamespaceKey datasetPath, DatasetConfig oldDataset, DatasetRetrievalOptions ignored) throws Exception { if(datasetPath.size() != 2) { return null; } InfoSchemaTable table = TABLE_MAP.get(datasetPath.getName().toLowerCase()); if(table != null) { return table.asTableDefinition(oldDataset); } return null; }
@Override public SourceTableDefinition getDataset(NamespaceKey datasetPath, DatasetConfig oldDataset, DatasetRetrievalOptions ignored) throws Exception { if(datasetPath.size() != 2) { return null; } SystemTable table = TABLE_MAP.get(datasetPath.getName().toLowerCase()); if(table != null) { return table.asTableDefinition(oldDataset); } return null; }
@Override public boolean containerExists(NamespaceKey key) { if(key.size() != 2){ return false; } return getClient(SystemUser.SYSTEM_USERNAME).databaseExists(key.getPathComponents().get(1)); }
@Override public Iterable<String> listSchemas(NamespaceKey path) { final SearchQuery filter = path.size() == 0 ? null : SearchQueryUtils.newTermQuery(DatasetIndexKeys.UNQUOTED_LC_SCHEMA, path.toUnescapedString().toLowerCase()); return FluentIterable.from(InfoSchemaTable.SCHEMATA.<Schema>asIterable("N/A", username, context.getDatasetListing(), filter)) .transform(new com.google.common.base.Function<Schema, String>() { @Override public String apply(Schema input) { return input.SCHEMA_NAME; } }); }
@Override public boolean datasetExists(NamespaceKey key) { if(key.size() != 3){ return false; } return getClient(SystemUser.SYSTEM_USERNAME).tableExists(key.getPathComponents().get(1), key.getPathComponents().get(2)); }
@Override public boolean datasetExists(NamespaceKey key) { if (!(key.size() == 3 || key.size() == 2)) { return false; } if (key.getLeaf().indexOf((TableName.NAMESPACE_DELIM)) != -1) { // ensure the table name does not have ":" return false; } try(Admin admin = connection.getConnection().getAdmin()) { HTableDescriptor descriptor = admin.getTableDescriptor(TableNameGetter.getTableName(key)); return descriptor != null; } catch (IOException e) { logger.warn("Failure while checking for HBase table {}.", key, e); } return false; }
@Override public boolean containerExists(NamespaceKey key) { if(key.size() != 2) { return false; } if (key.getName().equals(HBASE_SYSTEM_NAMESPACE)) { // DX-10110: do not allow access to the system namespace of HBase itself. Causes confusion when multiple 'use hbase' statements are processed return false; } try(Admin admin = connection.getConnection().getAdmin()) { NamespaceDescriptor descriptor = admin.getNamespaceDescriptor(key.getName()); return descriptor != null; } catch (IOException e) { logger.warn("Failure while checking for HBase Namespace {}.", key, e); } return false; }
@Override public boolean containerExists(NamespaceKey key) { if (key.size() != 2) { return false; } String schema = key.getPathComponents().get(1); try{ IndexExists exists = new IndexExists(); exists.addIndex(schema); return getRandomConnection().executeAndHandleResponseCode(exists, false, "").success(); } catch (Exception e) { logger.warn("Failure while evaluating if index or alias '{}' exists.", key, e); return false; } }
@Override public NamespaceKey resolveSingle(NamespaceKey key) { if(getDefaultSchema() == null || key.size() > 1) { return key; } return getDefaultSchema().getChild(key.getLeaf()); }
public ElasticMapping getMapping(NamespaceKey datasetPath){ if(datasetPath.size() != 3){ return null;
private SourceTableDefinition getDatasetInternal(NamespaceKey datasetPath, DatasetConfig oldConfig) throws Exception { if(datasetPath.size() != 3){ return null;
Map<String, Object> storageOptions ) { Preconditions.checkArgument(key.size() >= 2, "key must be at least two parts"); final String containerName = key.getPathComponents().get(1); if (key.size() == 2) { throw UserException.validationError() .message("Creating buckets is not supported", containerName)
@Override public SourceTableDefinition getDataset(NamespaceKey datasetPath, DatasetConfig oldConfig, DatasetRetrievalOptions retrievalOptions) throws Exception { if (datasetPath.size() <= 1) { return null; } PhysicalDataset physicalDataset = oldConfig == null ? null : oldConfig.getPhysicalDataset(); FormatPluginConfig pluginConfig = null; try { final FileSystemWrapper fs = getFs(); final FileConfig fileConfig; if(physicalDataset != null && physicalDataset.getFormatSettings() != null){ fileConfig = physicalDataset.getFormatSettings(); }else{ final DatasetConfig datasetConfig =getContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).getDataset(datasetPath); if (!(datasetConfig.getType() == DatasetType.PHYSICAL_DATASET_HOME_FILE || datasetConfig.getType() == DatasetType.PHYSICAL_DATASET_HOME_FOLDER)) { throw new IllegalArgumentException(format("Table %s does not belong to home space", datasetPath.toString())); } fileConfig = datasetConfig.getPhysicalDataset().getFormatSettings(); } pluginConfig = PhysicalDatasetUtils.toFormatPlugin(fileConfig, Collections.<String>emptyList()); final FormatPlugin formatPlugin = formatCreator.newFormatPlugin(pluginConfig); return getDataset(datasetPath, oldConfig, formatPlugin, fs, fileConfig); } catch (NamespaceNotFoundException nfe){ FormatPluginConfig formatPluginConfig = null; if(physicalDataset != null && physicalDataset.getFormatSettings() != null){ formatPluginConfig = PhysicalDatasetUtils.toFormatPlugin(physicalDataset.getFormatSettings(), Collections.<String>emptyList()); } return getDatasetWithFormat(datasetPath, oldConfig, formatPluginConfig, retrievalOptions, null); } }
@Override public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws Exception { final SqlUseSchema useSchema = SqlNodeUtil.unwrap(sqlNode, SqlUseSchema.class); // first we try locally. NamespaceKey orig = new NamespaceKey(useSchema.getSchema()); NamespaceKey defaultPath = catalog.resolveToDefault(orig); NamespaceKey compoundPath = orig.size() == 1 && orig.getRoot().contains(".") ? new NamespaceKey(SqlUtils.parseSchemaPath(orig.getRoot())) : null; if(defaultPath != null && catalog.containerExists(defaultPath)) { session.setDefaultSchemaPath(defaultPath.getPathComponents()); } else if (catalog.containerExists(orig)) { session.setDefaultSchemaPath(orig.getPathComponents()); } else if(compoundPath != null && catalog.containerExists(compoundPath)) { // kept to support old compound use statements. session.setDefaultSchemaPath(compoundPath.getPathComponents()); } else { throw UserException.validationError().message("Schema [%s] is not valid with respect to either root schema or current default schema.", orig).build(logger); } return Collections.singletonList(SimpleCommandResult.successful("Default schema changed to [%s]", session.getDefaultSchemaPath())); } }