微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从 Oracle 访问 DVC 控制的文件?

如何解决如何从 Oracle 访问 DVC 控制的文件?

我一直在 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个hash目录。

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

> 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

解决方法

我不能 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 存储库。此存储库应该有一个 .dvcdvc.lock 文件,其中包含 activity.log 名称 + 远程存储中的哈希值:

outs:
  - md5: a304afb96060aad90176268345e10355
    path: activity.log

通过阅读此 Git 存储库并进行分析,假设 activity.log.dvc DVC 将能够创建正确的路径 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 file 创建文件路径的 config

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。