我一直将我的大文件存储在 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 log
并cat .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