1

我一直将我的大文件存储在 Oracle 中的 CLOB 中,但我正在考虑将我的大文件存储在共享驱动器中,然后在 Oracle 中有一列包含指向这些文件的指针。这将使用 DVC。

当我这样做时,

(a) Oracle 路径中的路径是否指向我的共享驱动器中的文件,例如实际文件本身?

(b) 还是 Oracle 中的路径以某种方式指向 DVC 元文件?

任何见解都会帮助我!

谢谢 :) 贾斯汀


编辑以提供更多清晰度:

我在这里检查(https://dvc.org/doc/api-reference/open),它有所帮助,但我还没有完全到那里......

我想使用 python(我已连接到 Oracle 数据库)从远程 dvc 存储库中提取文件。所以,如果我们能做到这一点,我想我会很好。但是,我很困惑。如果我在下面指定'remote',那么当远程文件全部编码时,我如何命名文件(例如,'activity.log')?

with dvc.api.open(
        'activity.log',
        repo='location/of/dvc/project',
        remote='my-s3-bucket'
        ) as fd:
    for line in fd:
        match = re.search(r'user=(\w+)', line)
        # ... Process users activity log

(注意:出于测试目的,我的“远程”DVC 目录只是我 MacBook 上的另一个文件夹。)

我觉得我错过了一个关于获取远程文件的关键概念......

我希望这会增加更多的清晰度。任何帮助确定远程文件访问的帮助表示赞赏!:)

贾斯汀


编辑以获取有关“rev”参数的见解:

在我提出问题之前,一些背景/我的设置:(a)我的 MacBook 上有一个名为“basics”的存储库。(b) 我将包含 501 个文件(称为“surface_files”)的目录复制到“basics”中,随后将其推送到名为“gss”的远程存储文件夹中。推送后,'gss' 包含 220 个哈希目录。

我用来到达这里的步骤如下:

> cd ~/Desktop/Work/basics
> git init
> dvc init
> dvc add ~/Desktop/Work/basics/surface_files
> git add .gitignore surface_files.dvc
> git commit -m "Add raw data"
> dvc remote add -d remote_storage ~/Desktop/Work/gss
> git commit .dvc/config -m "Configure remote storage"
> dvc push
> rm -rf ./.dvc/cache
> rm -rf ./surface_files

接下来,我运行以下 Python 代码来获取我的一个名为 的表面文件,surface_100141.dat并用于dvc.api.get_url()获取相应的远程存储文件名。然后我将这个远程存储文件复制到我的桌面,使用文件的原始名称,即surface_100141.dat.

完成这一切的代码如下,但首先,我的问题 --- 当我运行如下所示的代码时,没有问题;但是当我取消注释'rev ='行时,它失败了。我不确定为什么会这样。我使用git logcat .git/refs/heads/master确保我得到了正确的哈希值。为什么会失败?那是我的问题。

(完全公开,我的 git 知识还不是太强。我到了那里,但它仍在进行中!:))

import dvc.api
import os.path
from os import path
import shutil

filename = 'surface_100141.dat' # This file name would be stored in my Oracle database
home_dir = os.path.expanduser('~')+'/' # This simply expanding '~' into '/Users/ricej/'

resource_url = dvc.api.get_url(
    path=f'surface_files/{filename}', # Works when 'surface_files.dvc' exists, even when 'surface_files' directory and .dvc/cache do not
    repo=f'{home_dir}Desktop/Work/basics',
    # rev='5c92710e68c045d75865fa24f1b56a0a486a8a45', # Commit hash, found using 'git log' or 'cat .git/refs/heads/master'
    remote='remote_storage')
resource_url = home_dir+resource_url
print(f'Remote file: {resource_url}')

new_dir = f'{home_dir}Desktop/' # Will copy fetched file to desktop, for demonstration
new_file = new_dir+filename
print(f'Remote file copy: {new_file}')

if path.exists(new_file):
    os.remove(new_file)
    
dest = shutil.copy(resource_url, new_file) # Check your desktop after this to see remote file copy
4

1 回答 1

2

我不是 100% 确定我理解了这个问题(在你试图用这个数据库解决的实际用例上稍微扩展它会很棒),但我可以分享一些想法。

当我们谈论 DVC 时,我认为您需要指定一些东西来识别文件/目录:

  1. Git 提交 + 路径(实际路径如data/data/xml)。需要提交(或者准确地说是任何 Git 修订版)来识别数据文件的版本。
  2. 或 DVC 存储中的路径(/mnt/shared/storage/00/198493ef2343ao... ) + actual name of this file. This way you would be saving info that .dvc` 文件有。

我会说不推荐第二种方式,因为在某种程度上它是一个实现细节 - DVC 如何在内部存储文件。DVC 组织数据存储的公共接口是其存储库 URL + 提交 + 文件名。

编辑(示例):

with dvc.api.open(
        'activity.log',
        repo='location/of/dvc/project',
        remote='my-s3-bucket'
        ) as fd:
    for line in fd:
        match = re.search(r'user=(\w+)', line)
        # ... Process users activity log

location/of/dvc/project此路径必须指向实际的 Git 存储库。这个 repo 应该有一个.dvcordvc.lock文件,其中有activity.log名字 + 它在远程存储中的哈希:

outs:
  - md5: a304afb96060aad90176268345e10355
    path: activity.log

通过阅读此 Git 存储库并进行分析,假设activity.log.dvcDVC 将能够创建正确的路径s3://my-bucket/storage/a3/04afb96060aad90176268345e10355

remote='my-s3-bucket'参数是可选的。默认情况下,它将使用在 repo 本身中定义的那个。

我们再举一个真实的例子:

with dvc.api.open(
        'get-started/data.xml',
        repo='https://github.com/iterative/dataset-registry'
        ) as fd:
    for line in fd:
        match = re.search(r'user=(\w+)', line)
        # ... Process users activity log

https://github.com/iterative/dataset-registry您可以找到足以让 DVC 通过分析其配置来创建.dvc文件路径的文件

https://remote.dvc.org/dataset-registry/a3/04afb96060aad90176268345e10355

你可以wget在这个文件上运行来下载它

于 2021-04-02T23:07:02.540 回答