Commit ·
bea5157
1
Parent(s): d9bded4
:beers: cheers
Browse files- sqllitetest.py +109 -0
- test.db +3 -0
sqllitetest.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A dataset script that will hit SQLite file and return the results."""
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
import sqlite3
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import datasets
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# TODO: Add BibTeX citation
|
| 11 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
| 12 |
+
_CITATION = """\
|
| 13 |
+
@InProceedings{huggingface:dataset,
|
| 14 |
+
title = {A great new dataset},
|
| 15 |
+
author={huggingface, Inc.
|
| 16 |
+
},
|
| 17 |
+
year={2020}
|
| 18 |
+
}
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# TODO: Add description of the dataset here
|
| 22 |
+
# You can copy an official description
|
| 23 |
+
_DESCRIPTION = """\
|
| 24 |
+
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
# TODO: Add a link to an official homepage for the dataset here
|
| 28 |
+
_HOMEPAGE = ""
|
| 29 |
+
|
| 30 |
+
# TODO: Add the licence for the dataset here if you can find it
|
| 31 |
+
_LICENSE = ""
|
| 32 |
+
|
| 33 |
+
# TODO: Add link to the official dataset URLs here
|
| 34 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
| 35 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 36 |
+
_URLS = {
|
| 37 |
+
"first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
| 38 |
+
"second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
| 43 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
| 44 |
+
"""TODO: Short description of my dataset."""
|
| 45 |
+
|
| 46 |
+
# VERSION = datasets.Version("1.1.0")
|
| 47 |
+
|
| 48 |
+
# This is an example of a dataset with multiple configurations.
|
| 49 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
| 50 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
| 51 |
+
|
| 52 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
| 53 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
| 54 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
| 55 |
+
|
| 56 |
+
# You will be able to load one or the other configurations in the following list with
|
| 57 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 58 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
| 59 |
+
# BUILDER_CONFIGS = [
|
| 60 |
+
# datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
|
| 61 |
+
# datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
|
| 62 |
+
# ]
|
| 63 |
+
|
| 64 |
+
# DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
| 65 |
+
|
| 66 |
+
def _info(self):
|
| 67 |
+
return datasets.DatasetInfo(
|
| 68 |
+
description=_DESCRIPTION,
|
| 69 |
+
features=datasets.Features(
|
| 70 |
+
{
|
| 71 |
+
"ssn": datasets.Value("int32"),
|
| 72 |
+
"first_name": datasets.Value("string"),
|
| 73 |
+
"last_name": datasets.Value("string"),
|
| 74 |
+
"department": datasets.Value("int32"),
|
| 75 |
+
"salary": datasets.Value("int32"),
|
| 76 |
+
}
|
| 77 |
+
),
|
| 78 |
+
homepage=_HOMEPAGE,
|
| 79 |
+
license=_LICENSE,
|
| 80 |
+
citation=_CITATION,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
def _split_generators(self, dl_manager):
|
| 84 |
+
|
| 85 |
+
# NOTE - Here is where you would put actual connection details if you're connecting to a database
|
| 86 |
+
# For the sake of this example, we use a local path to a sqllite file.
|
| 87 |
+
conn = sqlite3.connect("test.db")
|
| 88 |
+
|
| 89 |
+
# Execute a query and get the cursor object back, which we'll use to iterate over
|
| 90 |
+
curr = conn.execute("SELECT * FROM Employees")
|
| 91 |
+
|
| 92 |
+
return [
|
| 93 |
+
datasets.SplitGenerator(
|
| 94 |
+
name=datasets.Split.TRAIN,
|
| 95 |
+
gen_kwargs={"cursor": curr},
|
| 96 |
+
)
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
def _generate_examples(self, cursor):
|
| 100 |
+
for i, ex in enumerate(cursor):
|
| 101 |
+
yield str(i), {
|
| 102 |
+
"ssn": ex[0],
|
| 103 |
+
"first_name": ex[1],
|
| 104 |
+
"last_name": ex[2],
|
| 105 |
+
"department": ex[3],
|
| 106 |
+
"salary": ex[4],
|
| 107 |
+
}
|
| 108 |
+
# Probably not necessary but just in case...we close the connection which we can find within the cursor object
|
| 109 |
+
cursor.connection.close()
|
test.db
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:66a75a4d7d23f92c66dc98752ce3bf3a886a1c50ae071d13996810552e5e6d37
|
| 3 |
+
size 12288
|