public NamespacePath(RootEntity root, List<FolderName> folderPath, LeafEntity leaf) { this.root = root; this.folderPath = folderPath; this.leaf = leaf; this.namespaceKey = new NamespaceKey(createPathList()); }
@Override public NamespaceKey resolveToDefault(NamespaceKey key) { if(options.getSchemaConfig().getDefaultSchema() == null) { return null; } return new NamespaceKey( ImmutableList.copyOf( Iterables.concat( options.getSchemaConfig().getDefaultSchema().getPathComponents(), key.getPathComponents()))); }
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); } } }
public static String makePathString(final List<String> paths) { return new NamespaceKey(paths).getSchemaPath(); }
protected static String getTableName(final NamespaceKey key) { final String tableName; if(key.size() == 2) { tableName = key.getLeaf(); } else { List<String> subString = key.getPathComponents().subList(1, key.size()); tableName = Joiner.on('/').join(subString); } return tableName; }
@Override public String toString() { return format("%s : %s", type.toString(), new NamespaceKey(fullPath).toString()); }
public static void addFolder(NamespaceService ns, String name) throws Exception { final FolderConfig folder = new FolderConfig(); final NamespaceKey folderPath = new NamespaceKey(PathUtils.parseFullPath(name)); folder.setName(folderPath.getName()); folder.setFullPathList(folderPath.getPathComponents()); ns.addOrUpdateFolder(folderPath, folder); }
@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())); } }
private static FileFormat asFormat(NamespaceKey key, Path path, boolean isFolder) { String name = path.getName(); if(name.endsWith(".zip")) { name = name.substring(0, name.length() - 4); } if(name.endsWith(".gz")) { name = name.substring(0, name.length() - 3); } final FileConfig config = new FileConfig() .setCtime(System.currentTimeMillis()) .setFullPathList(key.getPathComponents()) .setName(key.getName()) .setType(FileFormat.getFileFormatType(Collections.singletonList(FilenameUtils.getExtension(name)))) .setTag(null); return isFolder ? FileFormat.getForFolder(config) : FileFormat.getForFile(config); }
@Override public DatasetPath apply(Entry<NamespaceKey, NameSpaceContainer> input) { return new DatasetPath(input.getKey().getPathComponents()); } });
@Override protected SourceTableDefinition getDatasetWithFormat(NamespaceKey datasetPath, DatasetConfig oldConfig, FormatPluginConfig formatPluginConfig, DatasetRetrievalOptions retrievalOptions, String user) throws Exception { try{ final FileSystemWrapper fs = getFs(); 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())); } final FormatPlugin formatPlugin = formatCreator.newFormatPlugin(formatPluginConfig); return getDataset(datasetPath, oldConfig, formatPlugin, fs, datasetConfig.getPhysicalDataset().getFormatSettings()); } catch (NamespaceNotFoundException nfe){ if(formatPluginConfig == null) { // a home file can only be read from the namespace or using a format options. Without either, it is invalid, return nothing. return null; } return super.getDatasetWithFormat(new NamespaceKey(relativePath(datasetPath.getPathComponents(), getConfig().getPath())), oldConfig, formatPluginConfig, retrievalOptions, null); } }
@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)); }
private void addSourcesAndOrigins(DocumentWriter writer, List<FieldOrigin> fieldOrigins) { if (notEmpty(fieldOrigins)) { Set<String> sources = Sets.newHashSet(); final List<String> empty = ImmutableList.of(); for (FieldOrigin fieldOrigin : fieldOrigins) { for (Origin origin : listNotNull(fieldOrigin.getOriginsList())) { // DX-3999: fix this in calcite final List<String> path = Optional.fromNullable(origin.getTableList()).or(empty); if (path.isEmpty()) { continue; } NamespaceKey dataset = new NamespaceKey(origin.getTableList()); sources.add(dataset.getRoot()); } } writer.write(DATASET_SOURCES, sources.toArray(new String[0])); } }
@Override public String toString() { return "fix-fail-to-start-" + sourceKey.getRoot(); } }
public ResourceTreeEntity(SpaceConfig spaceConfig) throws UnsupportedEncodingException { this.type = ResourceType.SPACE; this.name = spaceConfig.getName(); this.fullPath = Collections.singletonList(this.name); this.url = "/resourcetree/" + new NamespaceKey(this.fullPath).toUrlEncodedString(); }
public static void addPhysicalDS(NamespaceService ns, String filePath, DatasetType type, byte[] datasetSchema) throws Exception { NamespaceKey datasetPath = new NamespaceKey(PathUtils.parseFullPath(filePath)); final DatasetConfig datasetConfig = new DatasetConfig(); datasetConfig.setName(datasetPath.getName()); datasetConfig.setType(type); final PhysicalDataset physicalDataset = new PhysicalDataset(); if (datasetSchema != null) { datasetConfig.setRecordSchema(io.protostuff.ByteString.copyFrom(datasetSchema)); } datasetConfig.setSchemaVersion(DatasetHelper.CURRENT_VERSION); datasetConfig.setPhysicalDataset(physicalDataset); ns.tryCreatePhysicalDataset(datasetPath, datasetConfig); }
@Override public Iterable<String> getSubPartitions( NamespaceKey key, List<String> partitionColumns, List<String> partitionValues) throws PartitionNotFoundException { if(pluginRetriever.getPlugin(key.getRoot(), true) == null){ throw UserException.validationError().message("Unknown source %s", key.getRoot()).build(logger); } StoragePlugin plugin = context.getCatalogService().getSource(key.getRoot()); FileSystemPlugin fsPlugin; if (plugin instanceof FileSystemPlugin) { fsPlugin = (FileSystemPlugin) plugin; return fsPlugin.getSubPartitions(key.getPathComponents(), partitionColumns, partitionValues, options.getSchemaConfig()); } throw new UnsupportedOperationException(plugin.getClass().getName() + " does not support partition retrieval."); }
NamespaceInternalKey(final NamespaceKey path, boolean normalize) { this.namespaceKey = path; this.namespaceFullPath = path.getSchemaPath(); this.keyBytes = null; final List<String> pathComponents = path.getPathComponents(); this.components = pathComponents.size(); if (components == 0) { throw UserException.validationError() .message("Invalid name space key. Given: %s, Expected format: %s", namespaceFullPath, NAMESPACE_PATH_FORMAT) .build(logger); } // Convert each path component into bytes. this.pathComponentBytes = new byte[components][]; for (int i = 0; i < components; ++i) { if (pathComponents.get(i).length() == 0) { throw UserException.validationError() .message("Invalid name space key. Given: %s, Expected format: %s", namespaceFullPath, NAMESPACE_PATH_FORMAT) .build(logger); } if (normalize) { this.pathComponentBytes[i] = pathComponents.get(i).toLowerCase().getBytes(UTF_8); } else { this.pathComponentBytes[i] = pathComponents.get(i).getBytes(UTF_8); } } }
/** * 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("."); }