Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
2f231bef
Commit
2f231bef
authored
Mar 09, 2015
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BUG-32607: expose json serialization for individual type artifacts
parent
7a63f7ea
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
0 deletions
+181
-0
TypesDef.scala
...cala/org/apache/hadoop/metadata/typesystem/TypesDef.scala
+11
-0
TypesSerialization.scala
.../hadoop/metadata/typesystem/json/TypesSerialization.scala
+18
-0
TypesSerializationTest.scala
...oop/metadata/typesystem/json/TypesSerializationTest.scala
+152
-0
No files found.
typesystem/src/main/scala/org/apache/hadoop/metadata/typesystem/TypesDef.scala
View file @
2f231bef
...
...
@@ -25,6 +25,17 @@ case class TypesDef(enumTypes: Seq[EnumTypeDefinition],
traitTypes
:
Seq
[
HierarchicalTypeDefinition
[
TraitType
]],
classTypes
:
Seq
[
HierarchicalTypeDefinition
[
ClassType
]])
{
def
this
(
enumType
:
EnumTypeDefinition
)
=
this
(
Seq
(
enumType
),
Seq
(),
Seq
(),
Seq
())
def
this
(
structType
:
StructTypeDefinition
)
=
this
(
Seq
(),
Seq
(
structType
),
Seq
(),
Seq
())
def
this
(
typ
:
HierarchicalTypeDefinition
[
_
],
isTrait
:
Boolean
)
=
this
(
Seq
(),
Seq
(),
if
(
isTrait
)
Seq
(
typ
.
asInstanceOf
[
HierarchicalTypeDefinition
[
TraitType
]])
else
Seq
(),
if
(!
isTrait
)
Seq
(
typ
.
asInstanceOf
[
HierarchicalTypeDefinition
[
ClassType
]])
else
Seq
()
)
def
enumTypesAsJavaList
()
=
{
import
scala.collection.JavaConverters._
enumTypes
.
asJava
...
...
typesystem/src/main/scala/org/apache/hadoop/metadata/typesystem/json/TypesSerialization.scala
View file @
2f231bef
...
...
@@ -99,6 +99,24 @@ object TypesSerialization {
read
[
TypesDef
](
jsonStr
)
}
def
toJson
(
typesDef
:
TypesDef
)
:
String
=
{
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
MultiplicitySerializer
writePretty
(
typesDef
)
}
def
toJson
(
enumTypeDefinition
:
EnumTypeDefinition
)
:
String
=
{
toJson
(
new
TypesDef
(
enumTypeDefinition
))
}
def
toJson
(
structTypeDefinition
:
StructTypeDefinition
)
:
String
=
{
toJson
(
new
TypesDef
(
structTypeDefinition
))
}
def
toJson
(
typDef
:
HierarchicalTypeDefinition
[
_
],
isTrait
:
Boolean
)
:
String
=
{
toJson
(
new
TypesDef
(
typDef
,
isTrait
))
}
private
def
convertAttributeInfoToAttributeDef
(
aInfo
:
AttributeInfo
)
=
{
new
AttributeDefinition
(
aInfo
.
name
,
aInfo
.
dataType
().
getName
,
aInfo
.
multiplicity
,
aInfo
.
isComposite
,
aInfo
.
reverseAttributeName
)
...
...
typesystem/src/test/scala/org/apache/hadoop/metadata/typesystem/json/TypesSerializationTest.scala
View file @
2f231bef
...
...
@@ -146,4 +146,156 @@ class TypesSerializationTest extends BaseTest with TypeHelpers {
Assert
.
assertEquals
(
typesDef1
,
typesDef2
)
}
@Test
def
test2
:
Unit
=
{
val
sDef
=
structDef
(
"ts1"
,
requiredAttr
(
"a"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
optionalAttr
(
"c"
,
DataTypes
.
BYTE_TYPE
),
optionalAttr
(
"d"
,
DataTypes
.
SHORT_TYPE
),
optionalAttr
(
"e"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"f"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"g"
,
DataTypes
.
LONG_TYPE
),
optionalAttr
(
"h"
,
DataTypes
.
FLOAT_TYPE
),
optionalAttr
(
"i"
,
DataTypes
.
DOUBLE_TYPE
),
optionalAttr
(
"j"
,
DataTypes
.
BIGINTEGER_TYPE
),
optionalAttr
(
"k"
,
DataTypes
.
BIGDECIMAL_TYPE
),
optionalAttr
(
"l"
,
DataTypes
.
DATE_TYPE
),
optionalAttr
(
"m"
,
DataTypes
.
arrayTypeName
(
DataTypes
.
INT_TYPE
)),
optionalAttr
(
"n"
,
DataTypes
.
arrayTypeName
(
DataTypes
.
BIGDECIMAL_TYPE
)),
optionalAttr
(
"o"
,
DataTypes
.
mapTypeName
(
DataTypes
.
STRING_TYPE
,
DataTypes
.
DOUBLE_TYPE
)))
val
ser2
=
TypesSerialization
.
toJson
(
sDef
)
val
typesDef2
=
TypesSerialization
.
fromJson
(
ser2
)
Assert
.
assertEquals
(
sDef
,
typesDef2
.
structTypes
(
0
))
}
@Test
def
test3
:
Unit
=
{
val
sDef
=
structDef
(
"ts1"
,
requiredAttr
(
"a"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
optionalAttr
(
"c"
,
DataTypes
.
BYTE_TYPE
),
optionalAttr
(
"d"
,
DataTypes
.
SHORT_TYPE
),
optionalAttr
(
"e"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"f"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"g"
,
DataTypes
.
LONG_TYPE
),
optionalAttr
(
"h"
,
DataTypes
.
FLOAT_TYPE
),
optionalAttr
(
"i"
,
DataTypes
.
DOUBLE_TYPE
),
optionalAttr
(
"j"
,
DataTypes
.
BIGINTEGER_TYPE
),
optionalAttr
(
"k"
,
DataTypes
.
BIGDECIMAL_TYPE
),
optionalAttr
(
"l"
,
DataTypes
.
DATE_TYPE
),
optionalAttr
(
"m"
,
DataTypes
.
arrayTypeName
(
DataTypes
.
INT_TYPE
)),
optionalAttr
(
"n"
,
DataTypes
.
arrayTypeName
(
DataTypes
.
BIGDECIMAL_TYPE
)),
optionalAttr
(
"o"
,
DataTypes
.
mapTypeName
(
DataTypes
.
STRING_TYPE
,
DataTypes
.
DOUBLE_TYPE
)))
val
ser2
=
TypesSerialization
.
toJson
(
sDef
)
val
typesDef2
=
TypesSerialization
.
fromJson
(
ser2
)
Assert
.
assertEquals
(
sDef
,
typesDef2
.
structTypes
(
0
))
}
@Test
def
test4
:
Unit
=
{
val
A
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"A"
,
List
(),
requiredAttr
(
"a"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
optionalAttr
(
"c"
,
DataTypes
.
BYTE_TYPE
),
optionalAttr
(
"d"
,
DataTypes
.
SHORT_TYPE
))
val
B
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"B"
,
Seq
(
"A"
),
optionalAttr
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
))
val
C
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"C"
,
Seq
(
"A"
),
optionalAttr
(
"c"
,
DataTypes
.
BYTE_TYPE
))
val
D
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"D"
,
Seq
(
"B"
,
"C"
),
optionalAttr
(
"d"
,
DataTypes
.
SHORT_TYPE
))
val
typDefs
=
Seq
(
A
,
B
,
C
,
D
)
typDefs
.
foreach
{
tDef
=>
val
ser2
=
TypesSerialization
.
toJson
(
tDef
,
true
)
val
typesDef2
=
TypesSerialization
.
fromJson
(
ser2
)
Assert
.
assertEquals
(
tDef
,
typesDef2
.
traitTypes
(
0
))
}
}
@Test
def
test5
:
Unit
=
{
val
e1
=
new
EnumTypeDefinition
(
"HiveObjectType"
,
new
EnumValue
(
"GLOBAL"
,
1
),
new
EnumValue
(
"DATABASE"
,
2
),
new
EnumValue
(
"TABLE"
,
3
),
new
EnumValue
(
"PARTITION"
,
4
),
new
EnumValue
(
"COLUMN"
,
5
))
val
e2
=
new
EnumTypeDefinition
(
"PrincipalType"
,
new
EnumValue
(
"USER"
,
1
),
new
EnumValue
(
"ROLE"
,
2
),
new
EnumValue
(
"GROUP"
,
3
))
val
e3
=
new
EnumTypeDefinition
(
"TxnState"
,
new
EnumValue
(
"COMMITTED"
,
1
),
new
EnumValue
(
"ABORTED"
,
2
),
new
EnumValue
(
"OPEN"
,
3
))
val
e4
=
new
EnumTypeDefinition
(
"LockLevel"
,
new
EnumValue
(
"DB"
,
1
),
new
EnumValue
(
"TABLE"
,
2
),
new
EnumValue
(
"PARTITION"
,
3
))
val
typDefs
=
Seq
(
e1
,
e2
,
e3
,
e4
)
typDefs
.
foreach
{
tDef
=>
val
ser2
=
TypesSerialization
.
toJson
(
tDef
)
val
typesDef2
=
TypesSerialization
.
fromJson
(
ser2
)
Assert
.
assertEquals
(
tDef
,
typesDef2
.
enumTypes
(
0
))
}
}
@Test
def
test6
:
Unit
=
{
val
typDef
=
createClassTypeDef
(
"t4"
,
List
(),
requiredAttr
(
"a"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
optionalAttr
(
"c"
,
DataTypes
.
BYTE_TYPE
),
optionalAttr
(
"d"
,
DataTypes
.
SHORT_TYPE
),
optionalAttr
(
"enum1"
,
"HiveObjectType"
),
optionalAttr
(
"e"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"f"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"g"
,
DataTypes
.
LONG_TYPE
),
optionalAttr
(
"enum2"
,
"PrincipalType"
),
optionalAttr
(
"h"
,
DataTypes
.
FLOAT_TYPE
),
optionalAttr
(
"i"
,
DataTypes
.
DOUBLE_TYPE
),
optionalAttr
(
"j"
,
DataTypes
.
BIGINTEGER_TYPE
),
optionalAttr
(
"k"
,
DataTypes
.
BIGDECIMAL_TYPE
),
optionalAttr
(
"enum3"
,
"TxnState"
),
optionalAttr
(
"l"
,
DataTypes
.
DATE_TYPE
),
optionalAttr
(
"m"
,
DataTypes
.
INT_TYPE
),
optionalAttr
(
"n"
,
DataTypes
.
BIGDECIMAL_TYPE
),
optionalAttr
(
"o"
,
DataTypes
.
mapTypeName
(
DataTypes
.
STRING_TYPE
,
DataTypes
.
DOUBLE_TYPE
)),
optionalAttr
(
"enum4"
,
"LockLevel"
))
val
deptTypeDef
:
HierarchicalTypeDefinition
[
ClassType
]
=
createClassTypeDef
(
"Department"
,
List
(),
requiredAttr
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"employees"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
true
,
"department"
))
val
personTypeDef
:
HierarchicalTypeDefinition
[
ClassType
]
=
createClassTypeDef
(
"Person"
,
List
(),
requiredAttr
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"department"
,
"Department"
,
Multiplicity
.
REQUIRED
,
false
,
"employees"
),
new
AttributeDefinition
(
"manager"
,
"Manager"
,
Multiplicity
.
OPTIONAL
,
false
,
"subordinates"
)
)
val
managerTypeDef
:
HierarchicalTypeDefinition
[
ClassType
]
=
createClassTypeDef
(
"Manager"
,
List
(
"Person"
),
new
AttributeDefinition
(
"subordinates"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
false
,
"manager"
)
)
val
typDefs
=
Seq
(
typDef
,
deptTypeDef
,
personTypeDef
,
managerTypeDef
)
typDefs
.
foreach
{
tDef
=>
val
ser2
=
TypesSerialization
.
toJson
(
tDef
,
false
)
val
typesDef2
=
TypesSerialization
.
fromJson
(
ser2
)
Assert
.
assertEquals
(
tDef
,
typesDef2
.
classTypes
(
0
))
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment