-
-
Save sfc-gh-pneedleman/cd7ffccf20b85f9ff7bebaf2d49d5ccc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION FAKER("LOCALES" VARCHAR(16777216), "PROVIDER" VARCHAR(16777216), "PARAMETERS" VARCHAR(16777216)) | |
RETURNS VARIANT | |
LANGUAGE PYTHON | |
RUNTIME_VERSION = '3.8' | |
PACKAGES = ('faker') | |
HANDLER = 'compute' | |
AS ' | |
import json, datetime, decimal | |
from faker import Faker | |
locale_list = [''en_US'', ''en_GB'',''de_DE'', ''de_AT'', ''de_CH'',''pl_PL'', ''fr_FR'', ''es_ES'', ''it_IT'', ''nl_NL'', ''dk_DK'', ''ru_RU''] | |
faker = Faker(locale_list) | |
def compute(locales, provider, parameters): | |
try: | |
fake = faker[locales] | |
except: | |
raise Exception (''Country not implemented.'') | |
if len(parameters) > 2: | |
data = fake.format(provider,parameters) | |
else: | |
data = fake.format(provider) | |
data = json.loads(json.dumps(data, default=default_json_transform).replace(''\\\\n'','', '')) | |
return data | |
# format incompatible data types | |
def default_json_transform(obj): | |
if isinstance(obj, decimal.Decimal): | |
return str(obj) | |
if isinstance(obj, (datetime.date, datetime.datetime)): | |
return obj.isoformat() | |
raise TypeError | |
'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment