Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hshetl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tools
hshetl
Commits
bb7be0ca
Commit
bb7be0ca
authored
11 years ago
by
schulmax
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Introduces UUID-Transformer
parent
2102ccae
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hshetl/entities.py
+2
-1
2 additions, 1 deletion
hshetl/entities.py
hshetl/transformers.py
+65
-0
65 additions, 0 deletions
hshetl/transformers.py
with
67 additions
and
1 deletion
hshetl/entities.py
+
2
−
1
View file @
bb7be0ca
...
@@ -521,6 +521,7 @@ class Result(object):
...
@@ -521,6 +521,7 @@ class Result(object):
'''
Initializes the necessary properties.
'''
'''
Initializes the necessary properties.
'''
self
.
entity
=
entity
self
.
entity
=
entity
self
.
source
=
NameResolver
(
self
.
entity
,
'
source
'
,
source
)()
self
.
source
=
NameResolver
(
self
.
entity
,
'
source
'
,
source
)()
'''
source is a Result, NOT a container
'''
self
.
update
=
EntityList
(
self
.
source
)
self
.
update
=
EntityList
(
self
.
source
)
self
.
insert
=
EntityList
(
self
.
source
)
self
.
insert
=
EntityList
(
self
.
source
)
...
@@ -571,7 +572,7 @@ class EntityList(list):
...
@@ -571,7 +572,7 @@ class EntityList(list):
'''
'''
def
__init__
(
self
,
result
):
def
__init__
(
self
,
result
):
'''
Defa
ult
co
nst
ructor
'''
'''
Expects a Res
ult
i
nst
ance
'''
self
.
result
=
result
self
.
result
=
result
self
.
source
=
result
.
source_container
self
.
source
=
result
.
source_container
self
.
target
=
result
.
target_container
self
.
target
=
result
.
target_container
...
...
This diff is collapsed.
Click to expand it.
hshetl/transformers.py
+
65
−
0
View file @
bb7be0ca
...
@@ -291,3 +291,68 @@ class PropertiesTransformer(AbstractTransformer):
...
@@ -291,3 +291,68 @@ class PropertiesTransformer(AbstractTransformer):
transformed_properties
[
prop
]
=
eval
(
'
pt.{}.value
'
.
format
(
operation
),
globals
(),
dict
(
properties
.
items
()
+
locals
().
items
()))
transformed_properties
[
prop
]
=
eval
(
'
pt.{}.value
'
.
format
(
operation
),
globals
(),
dict
(
properties
.
items
()
+
locals
().
items
()))
return
transformed_properties
return
transformed_properties
@yamlify
class
UuidTransformer
(
AbstractTransformer
):
'''
Creates an uuid for entity.
Applies all operations to the fields in the new data container.
.. function:: __init__(source[, *args[, **kwargs]])
Constructor
:param source: The source container.
:param **kwargs: Accepts parameters from :class:`.AbstractTransformer`.
:type source: string
A loader inside of a YAML job definition with more parameters:
.. code-block:: yaml
transformer: !uuid
entity: !entity
id: string
source: foobar
'''
yaml_tag
=
u
'
!uuid
'
def
__init__
(
self
,
source
,
uuid_attribute
,
mapping
=
{},
*
args
,
**
kwargs
):
super
(
UuidTransformer
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
source
=
source
self
.
uuid_attr
=
uuid_attribute
self
.
mapping
=
mapping
'''
The source container to work on.
'''
if
self
.
entity
is
not
None
:
self
.
source
=
NameResolver
(
self
.
entity
,
'
source
'
,
source
)()
def
create_container
(
self
):
if
isinstance
(
self
.
source
,
str
)
and
self
.
entity
is
not
None
:
self
.
source
=
NameResolver
(
self
.
entity
,
'
source
'
,
self
.
source
)()
else
:
raise
Exception
(
"
Source is of type string and entity is None, so the NameResolver cannot find a correspinding container.
"
)
if
self
.
mapping
is
not
{}:
mapped_identifiers
=
[
x
if
x
not
in
self
.
mapping
.
keys
()
else
self
.
mapping
[
x
]
for
x
in
self
.
source
.
identifiers
]
self
.
result
=
Container
(
name
=
self
.
name
,
identifiers
=
mapped_identifiers
,
properties
=
self
.
entity
.
properties
)
self
.
entity
.
add
(
self
.
result
)
def
can_execute
(
self
):
'''
Whether the Transformer has everything set needed for its transform operation.
'''
return
self
.
entity
is
not
None
and
self
.
source
is
not
None
def
_execute
(
self
):
for
record
in
self
.
entity
.
record_repository
.
itervalues
():
identifier
=
record
.
get_container_identifier
(
self
.
source
)
if
identifier
is
None
:
continue
# ignore records not known by source.
transformed
=
self
.
_execute_operations
(
record
)
record
.
load
(
identifier
,
transformed
,
self
.
result
)
def
_execute_operations
(
self
,
record
):
properties
=
record
.
get_properties
(
self
.
source
)
transformed_properties
=
properties
.
copy
()
transformed_properties
[
self
.
uuid_attr
]
=
uuid
().
hex
return
transformed_properties
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment