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
b8feeebf
Commit
b8feeebf
authored
Dec 12, 2014
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unify defining structs, traits and class types
parent
040ee99c
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
354 additions
and
228 deletions
+354
-228
ClassType.java
src/main/java/org/apache/metadata/types/ClassType.java
+2
-2
HierarchicalType.java
...main/java/org/apache/metadata/types/HierarchicalType.java
+16
-5
HierarchicalTypeDefinition.java
...org/apache/metadata/types/HierarchicalTypeDefinition.java
+8
-11
StructTypeDefinition.java
.../java/org/apache/metadata/types/StructTypeDefinition.java
+15
-0
TraitType.java
src/main/java/org/apache/metadata/types/TraitType.java
+2
-2
TraitTypeDefinition.java
...n/java/org/apache/metadata/types/TraitTypeDefinition.java
+0
-35
TypeSystem.java
src/main/java/org/apache/metadata/types/TypeSystem.java
+297
-152
BaseTest.java
src/test/java/org/apache/metadata/BaseTest.java
+6
-10
TraitTest.java
src/test/java/org/apache/metadata/TraitTest.java
+4
-7
SerializationTest.scala
...st/scala/org/apache/metadata/json/SerializationTest.scala
+4
-4
No files found.
src/main/java/org/apache/metadata/types/ClassType.java
View file @
b8feeebf
...
@@ -40,12 +40,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
...
@@ -40,12 +40,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
* Used when creating a ClassType, to support recursive Structs.
* Used when creating a ClassType, to support recursive Structs.
*/
*/
ClassType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTypes
,
int
numFields
)
{
ClassType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTypes
,
int
numFields
)
{
super
(
typeSystem
,
name
,
superTypes
,
numFields
);
super
(
typeSystem
,
ClassType
.
class
,
name
,
superTypes
,
numFields
);
}
}
ClassType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
AttributeInfo
...
fields
)
ClassType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
AttributeInfo
...
fields
)
throws
MetadataException
{
throws
MetadataException
{
super
(
typeSystem
,
name
,
superTraits
,
fields
);
super
(
typeSystem
,
ClassType
.
class
,
name
,
superTraits
,
fields
);
}
}
@Override
@Override
...
...
src/main/java/org/apache/metadata/types/HierarchicalType.java
View file @
b8feeebf
...
@@ -36,6 +36,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
...
@@ -36,6 +36,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
implements
Comparable
<
ST
>
{
implements
Comparable
<
ST
>
{
public
final
TypeSystem
typeSystem
;
public
final
TypeSystem
typeSystem
;
public
final
Class
<
ST
>
superTypeClass
;
public
final
String
name
;
public
final
String
name
;
public
final
FieldMapping
fieldMapping
;
public
final
FieldMapping
fieldMapping
;
public
final
int
numFields
;
public
final
int
numFields
;
...
@@ -47,8 +48,10 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
...
@@ -47,8 +48,10 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
/**
/**
* Used when creating a Type, to support recursive Structs.
* Used when creating a Type, to support recursive Structs.
*/
*/
HierarchicalType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTypes
,
int
numFields
)
{
HierarchicalType
(
TypeSystem
typeSystem
,
Class
<
ST
>
superTypeClass
,
String
name
,
ImmutableList
<
String
>
superTypes
,
int
numFields
)
{
this
.
typeSystem
=
typeSystem
;
this
.
typeSystem
=
typeSystem
;
this
.
superTypeClass
=
superTypeClass
;
this
.
name
=
name
;
this
.
name
=
name
;
this
.
fieldMapping
=
null
;
this
.
fieldMapping
=
null
;
this
.
numFields
=
numFields
;
this
.
numFields
=
numFields
;
...
@@ -56,9 +59,11 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
...
@@ -56,9 +59,11 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
this
.
immediateAttrs
=
null
;
this
.
immediateAttrs
=
null
;
}
}
HierarchicalType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeInfo
...
fields
)
HierarchicalType
(
TypeSystem
typeSystem
,
Class
<
ST
>
superTypeClass
,
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeInfo
...
fields
)
throws
MetadataException
{
throws
MetadataException
{
this
.
typeSystem
=
typeSystem
;
this
.
typeSystem
=
typeSystem
;
this
.
superTypeClass
=
superTypeClass
;
this
.
name
=
name
;
this
.
name
=
name
;
this
.
fieldMapping
=
constructFieldMapping
(
superTypes
,
this
.
fieldMapping
=
constructFieldMapping
(
superTypes
,
fields
);
fields
);
...
@@ -115,8 +120,9 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
...
@@ -115,8 +120,9 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
queue
.
add
(
new
Node
(
getName
()));
queue
.
add
(
new
Node
(
getName
()));
while
(!
queue
.
isEmpty
())
{
while
(!
queue
.
isEmpty
())
{
Path
currentPath
=
queue
.
poll
();
Path
currentPath
=
queue
.
poll
();
ST
superType
=
currentPath
.
typeName
==
getName
()
?
(
ST
)
this
:
ST
superType
=
currentPath
.
typeName
==
getName
()
?
(
ST
)
this
:
(
ST
)
typeSystem
.
dataType
(
currentPath
.
typeName
);
(
ST
)
typeSystem
.
getDataType
(
superTypeClass
,
currentPath
.
typeName
);
pathNameToPathMap
.
put
(
currentPath
.
pathName
,
currentPath
);
pathNameToPathMap
.
put
(
currentPath
.
pathName
,
currentPath
);
if
(
superType
!=
this
)
{
if
(
superType
!=
this
)
{
...
@@ -248,7 +254,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
...
@@ -248,7 +254,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
superTypeName
,
getName
()));
superTypeName
,
getName
()));
}
}
ST
superType
=
(
ST
)
typeSystem
.
dataType
(
superTypeName
);
ST
superType
=
(
ST
)
typeSystem
.
getDataType
(
superTypeClass
,
superTypeName
);
Map
<
String
,
String
>
downCastMap
=
superType
.
constructDowncastFieldMap
(
this
,
pathToSuper
.
get
(
0
));
Map
<
String
,
String
>
downCastMap
=
superType
.
constructDowncastFieldMap
(
this
,
pathToSuper
.
get
(
0
));
return
new
DownCastStructInstance
(
superTypeName
,
return
new
DownCastStructInstance
(
superTypeName
,
new
DownCastFieldMapping
(
ImmutableMap
.
copyOf
(
downCastMap
)),
new
DownCastFieldMapping
(
ImmutableMap
.
copyOf
(
downCastMap
)),
...
@@ -318,7 +324,12 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
...
@@ -318,7 +324,12 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
@Override
@Override
public
Path
next
()
{
public
Path
next
()
{
Path
p
=
pathQueue
.
poll
();
Path
p
=
pathQueue
.
poll
();
ST
t
=
(
ST
)
typeSystem
.
dataType
(
p
.
typeName
);
ST
t
=
null
;
try
{
t
=
(
ST
)
typeSystem
.
getDataType
(
superTypeClass
,
p
.
typeName
);
}
catch
(
MetadataException
me
)
{
throw
new
RuntimeException
(
me
);
}
if
(
t
.
superTypes
!=
null
)
{
if
(
t
.
superTypes
!=
null
)
{
ImmutableList
<
String
>
sTs
=
t
.
superTypes
;
ImmutableList
<
String
>
sTs
=
t
.
superTypes
;
for
(
String
sT
:
sTs
)
{
for
(
String
sT
:
sTs
)
{
...
...
src/main/java/org/apache/metadata/types/
Class
TypeDefinition.java
→
src/main/java/org/apache/metadata/types/
Hierarchical
TypeDefinition.java
View file @
b8feeebf
...
@@ -20,16 +20,14 @@ package org.apache.metadata.types;
...
@@ -20,16 +20,14 @@ package org.apache.metadata.types;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
public
class
Class
TypeDefinition
{
public
class
HierarchicalTypeDefinition
<
T
extends
HierarchicalType
>
extends
Struct
TypeDefinition
{
public
final
String
typeName
;
public
final
ImmutableList
<
String
>
superTypes
;
public
final
ImmutableList
<
String
>
superTraits
;
public
final
AttributeDefinition
[]
attributeDefinitions
;
public
ClassTypeDefinition
(
String
typeName
,
ImmutableList
<
String
>
superTraits
,
public
HierarchicalTypeDefinition
(
Class
<
T
>
hierarchicalMetaType
,
AttributeDefinition
[]
attributeDefinitions
)
{
String
typeName
,
ImmutableList
<
String
>
superTypes
,
this
.
typeName
=
typeName
;
AttributeDefinition
[]
attributeDefinitions
)
{
this
.
superTraits
=
superTraits
==
null
?
ImmutableList
.<
String
>
of
()
:
superTraits
;
super
(
typeName
,
attributeDefinitions
)
;
this
.
attributeDefinitions
=
attributeDefinition
s
;
this
.
superTypes
=
superTypes
==
null
?
ImmutableList
.<
String
>
of
()
:
superType
s
;
}
}
}
}
\ No newline at end of file
src/main/java/org/apache/metadata/types/StructTypeDefinition.java
0 → 100644
View file @
b8feeebf
package
org
.
apache
.
metadata
.
types
;
import
com.google.common.collect.ImmutableList
;
public
class
StructTypeDefinition
{
public
final
String
typeName
;
public
final
AttributeDefinition
[]
attributeDefinitions
;
public
StructTypeDefinition
(
String
typeName
,
AttributeDefinition
[]
attributeDefinitions
)
{
this
.
typeName
=
typeName
;
this
.
attributeDefinitions
=
attributeDefinitions
;
}
}
src/main/java/org/apache/metadata/types/TraitType.java
View file @
b8feeebf
...
@@ -32,13 +32,13 @@ public class TraitType extends HierarchicalType<TraitType, IStruct>
...
@@ -32,13 +32,13 @@ public class TraitType extends HierarchicalType<TraitType, IStruct>
* Used when creating a TraitType, to support recursive Structs.
* Used when creating a TraitType, to support recursive Structs.
*/
*/
TraitType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
int
numFields
)
{
TraitType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
int
numFields
)
{
super
(
typeSystem
,
name
,
superTraits
,
numFields
);
super
(
typeSystem
,
TraitType
.
class
,
name
,
superTraits
,
numFields
);
handler
=
null
;
handler
=
null
;
}
}
TraitType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
AttributeInfo
...
fields
)
TraitType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
AttributeInfo
...
fields
)
throws
MetadataException
{
throws
MetadataException
{
super
(
typeSystem
,
name
,
superTraits
,
fields
);
super
(
typeSystem
,
TraitType
.
class
,
name
,
superTraits
,
fields
);
handler
=
new
TypedStructHandler
(
this
);
handler
=
new
TypedStructHandler
(
this
);
}
}
...
...
src/main/java/org/apache/metadata/types/TraitTypeDefinition.java
deleted
100644 → 0
View file @
040ee99c
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
metadata
.
types
;
import
com.google.common.collect.ImmutableList
;
public
class
TraitTypeDefinition
{
public
final
String
typeName
;
public
final
ImmutableList
<
String
>
superTraits
;
public
final
AttributeDefinition
[]
attributeDefinitions
;
public
TraitTypeDefinition
(
String
typeName
,
ImmutableList
<
String
>
superTraits
,
AttributeDefinition
[]
attributeDefinitions
)
{
this
.
typeName
=
typeName
;
this
.
superTraits
=
superTraits
==
null
?
ImmutableList
.<
String
>
of
()
:
superTraits
;
this
.
attributeDefinitions
=
attributeDefinitions
;
}
}
src/main/java/org/apache/metadata/types/TypeSystem.java
View file @
b8feeebf
...
@@ -18,9 +18,15 @@
...
@@ -18,9 +18,15 @@
package
org
.
apache
.
metadata
.
types
;
package
org
.
apache
.
metadata
.
types
;
import
com.google.common.base.Function
;
import
com.google.common.base.Predicate
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.Iterables
;
import
com.google.common.collect.Lists
;
import
org.apache.metadata.MetadataException
;
import
org.apache.metadata.MetadataException
;
import
javax.annotation.Nullable
;
import
java.lang.reflect.Constructor
;
import
java.util.*
;
import
java.util.*
;
public
class
TypeSystem
{
public
class
TypeSystem
{
...
@@ -32,7 +38,8 @@ public class TypeSystem {
...
@@ -32,7 +38,8 @@ public class TypeSystem {
registerPrimitiveTypes
();
registerPrimitiveTypes
();
}
}
private
TypeSystem
(
TypeSystem
ts
)
{}
private
TypeSystem
(
TypeSystem
ts
)
{
}
public
ImmutableList
<
String
>
getTypeNames
()
{
public
ImmutableList
<
String
>
getTypeNames
()
{
return
ImmutableList
.
copyOf
(
types
.
keySet
());
return
ImmutableList
.
copyOf
(
types
.
keySet
());
...
@@ -52,12 +59,8 @@ public class TypeSystem {
...
@@ -52,12 +59,8 @@ public class TypeSystem {
types
.
put
(
DataTypes
.
STRING_TYPE
.
getName
(),
DataTypes
.
STRING_TYPE
);
types
.
put
(
DataTypes
.
STRING_TYPE
.
getName
(),
DataTypes
.
STRING_TYPE
);
}
}
public
IDataType
dataType
(
String
name
)
{
return
types
.
get
(
name
);
}
public
<
T
>
T
getDataType
(
Class
<
T
>
cls
,
String
name
)
throws
MetadataException
{
public
<
T
>
T
getDataType
(
Class
<
T
>
cls
,
String
name
)
throws
MetadataException
{
if
(
types
.
containsKey
(
name
)
)
{
if
(
types
.
containsKey
(
name
)
)
{
return
cls
.
cast
(
types
.
get
(
name
));
return
cls
.
cast
(
types
.
get
(
name
));
}
}
...
@@ -65,7 +68,7 @@ public class TypeSystem {
...
@@ -65,7 +68,7 @@ public class TypeSystem {
* is this an Array Type?
* is this an Array Type?
*/
*/
String
arrElemType
=
TypeUtils
.
parseAsArrayType
(
name
);
String
arrElemType
=
TypeUtils
.
parseAsArrayType
(
name
);
if
(
arrElemType
!=
null
)
{
if
(
arrElemType
!=
null
)
{
IDataType
dT
=
defineArrayType
(
getDataType
(
IDataType
.
class
,
arrElemType
));
IDataType
dT
=
defineArrayType
(
getDataType
(
IDataType
.
class
,
arrElemType
));
return
cls
.
cast
(
dT
);
return
cls
.
cast
(
dT
);
}
}
...
@@ -74,7 +77,7 @@ public class TypeSystem {
...
@@ -74,7 +77,7 @@ public class TypeSystem {
* is this a Map Type?
* is this a Map Type?
*/
*/
String
[]
mapType
=
TypeUtils
.
parseAsMapType
(
name
);
String
[]
mapType
=
TypeUtils
.
parseAsMapType
(
name
);
if
(
mapType
!=
null
)
{
if
(
mapType
!=
null
)
{
IDataType
dT
=
defineMapType
(
getDataType
(
IDataType
.
class
,
mapType
[
0
]),
IDataType
dT
=
defineMapType
(
getDataType
(
IDataType
.
class
,
mapType
[
0
]),
getDataType
(
IDataType
.
class
,
mapType
[
1
]));
getDataType
(
IDataType
.
class
,
mapType
[
1
]));
return
cls
.
cast
(
dT
);
return
cls
.
cast
(
dT
);
...
@@ -86,187 +89,320 @@ public class TypeSystem {
...
@@ -86,187 +89,320 @@ public class TypeSystem {
public
StructType
defineStructType
(
String
name
,
public
StructType
defineStructType
(
String
name
,
boolean
errorIfExists
,
boolean
errorIfExists
,
AttributeDefinition
...
attrDefs
)
throws
MetadataException
{
AttributeDefinition
...
attrDefs
)
throws
MetadataException
{
if
(
types
.
containsKey
(
name
)
)
{
StructTypeDefinition
structDef
=
new
StructTypeDefinition
(
name
,
attrDefs
);
throw
new
MetadataException
(
String
.
format
(
"Cannot redefine type %s"
,
name
));
Map
<
String
,
IDataType
>
newTypes
=
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(
structDef
),
}
ImmutableList
.<
HierarchicalTypeDefinition
<
TraitType
>>
of
(),
assert
name
!=
null
;
ImmutableList
.<
HierarchicalTypeDefinition
<
ClassType
>>
of
());
AttributeInfo
[]
infos
=
new
AttributeInfo
[
attrDefs
.
length
];
Map
<
Integer
,
AttributeDefinition
>
recursiveRefs
=
new
HashMap
<
Integer
,
AttributeDefinition
>();
return
getDataType
(
StructType
.
class
,
structDef
.
typeName
);
try
{
}
types
.
put
(
name
,
new
StructType
(
this
,
name
,
attrDefs
.
length
));
for
(
int
i
=
0
;
i
<
attrDefs
.
length
;
i
++)
{
public
TraitType
defineTraitType
(
HierarchicalTypeDefinition
<
TraitType
>
traitDef
infos
[
i
]
=
new
AttributeInfo
(
this
,
attrDefs
[
i
]);
)
throws
MetadataException
{
if
(
attrDefs
[
i
].
dataTypeName
==
name
)
{
Map
<
String
,
IDataType
>
newTypes
=
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
recursiveRefs
.
put
(
i
,
attrDefs
[
i
]);
ImmutableList
.<
HierarchicalTypeDefinition
<
TraitType
>>
of
(
traitDef
),
}
ImmutableList
.<
HierarchicalTypeDefinition
<
ClassType
>>
of
());
}
}
catch
(
MetadataException
me
)
{
return
getDataType
(
TraitType
.
class
,
traitDef
.
typeName
);
types
.
remove
(
name
);
}
throw
me
;
}
catch
(
RuntimeException
re
)
{
public
ClassType
defineClassType
(
HierarchicalTypeDefinition
<
ClassType
>
classDef
types
.
remove
(
name
);
)
throws
MetadataException
{
throw
re
;
Map
<
String
,
IDataType
>
newTypes
=
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
}
ImmutableList
.<
HierarchicalTypeDefinition
<
TraitType
>>
of
(),
StructType
sT
=
new
StructType
(
this
,
name
,
null
,
infos
);
ImmutableList
.<
HierarchicalTypeDefinition
<
ClassType
>>
of
());
types
.
put
(
name
,
sT
);
for
(
Map
.
Entry
<
Integer
,
AttributeDefinition
>
e
:
recursiveRefs
.
entrySet
())
{
return
getDataType
(
ClassType
.
class
,
classDef
.
typeName
);
infos
[
e
.
getKey
()].
setDataType
(
sT
);
}
return
sT
;
}
}
public
TraitType
defineTraitType
(
boolean
errorIfExists
,
public
Map
<
String
,
IDataType
>
defineTraitTypes
(
HierarchicalTypeDefinition
<
TraitType
>...
traitDefs
)
TraitTypeDefinition
traitDef
throws
MetadataException
{
)
throws
MetadataException
{
TransientTypeSystem
transientTypes
=
new
TransientTypeSystem
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
Map
<
String
,
TraitType
>
m
=
defineTraitTypes
(
errorIfExists
,
traitDef
);
ImmutableList
.<
HierarchicalTypeDefinition
<
TraitType
>>
copyOf
(
traitDefs
),
return
m
.
values
().
iterator
().
next
();
ImmutableList
.<
HierarchicalTypeDefinition
<
ClassType
>>
of
());
return
transientTypes
.
defineTypes
();
}
public
Map
<
String
,
IDataType
>
defineTypes
(
ImmutableList
<
StructTypeDefinition
>
structDefs
,
ImmutableList
<
HierarchicalTypeDefinition
<
TraitType
>>
traitDefs
,
ImmutableList
<
HierarchicalTypeDefinition
<
ClassType
>>
classDefs
)
throws
MetadataException
{
TransientTypeSystem
transientTypes
=
new
TransientTypeSystem
(
structDefs
,
traitDefs
,
classDefs
);
return
transientTypes
.
defineTypes
();
}
public
DataTypes
.
ArrayType
defineArrayType
(
IDataType
elemType
)
throws
MetadataException
{
assert
elemType
!=
null
;
DataTypes
.
ArrayType
dT
=
new
DataTypes
.
ArrayType
(
elemType
);
types
.
put
(
dT
.
getName
(),
dT
);
return
dT
;
}
public
DataTypes
.
MapType
defineMapType
(
IDataType
keyType
,
IDataType
valueType
)
throws
MetadataException
{
assert
keyType
!=
null
;
assert
valueType
!=
null
;
DataTypes
.
MapType
dT
=
new
DataTypes
.
MapType
(
keyType
,
valueType
);
types
.
put
(
dT
.
getName
(),
dT
);
return
dT
;
}
}
public
Map
<
String
,
TraitType
>
defineTraitTypes
(
boolean
errorIfExists
,
class
TransientTypeSystem
extends
TypeSystem
{
TraitTypeDefinition
...
traitDefs
)
throws
MetadataException
{
final
ImmutableList
<
StructTypeDefinition
>
structDefs
;
TransientTypeSystem
transientTypes
=
new
TransientTypeSystem
();
final
ImmutableList
<
HierarchicalTypeDefinition
<
TraitType
>>
traitDefs
;
Map
<
String
,
TraitTypeDefinition
>
traitDefMap
=
new
HashMap
<
String
,
TraitTypeDefinition
>();
final
ImmutableList
<
HierarchicalTypeDefinition
<
ClassType
>>
classDefs
;
Map
<
String
,
StructTypeDefinition
>
structNameToDefMap
=
new
HashMap
<
String
,
StructTypeDefinition
>();
Map
<
String
,
HierarchicalTypeDefinition
<
TraitType
>>
traitNameToDefMap
=
new
HashMap
<
String
,
HierarchicalTypeDefinition
<
TraitType
>>();
Map
<
String
,
HierarchicalTypeDefinition
<
ClassType
>>
classNameToDefMap
=
new
HashMap
<
String
,
HierarchicalTypeDefinition
<
ClassType
>>();
Set
<
String
>
transientTypes
;
List
<
AttributeInfo
>
recursiveRefs
;
List
<
DataTypes
.
ArrayType
>
recursiveArrayTypes
;
List
<
DataTypes
.
MapType
>
recursiveMapTypes
;
TransientTypeSystem
(
ImmutableList
<
StructTypeDefinition
>
structDefs
,
ImmutableList
<
HierarchicalTypeDefinition
<
TraitType
>>
traitDefs
,
ImmutableList
<
HierarchicalTypeDefinition
<
ClassType
>>
classDefs
)
{
super
(
TypeSystem
.
this
);
this
.
structDefs
=
structDefs
;
this
.
traitDefs
=
traitDefs
;
this
.
classDefs
=
classDefs
;
structNameToDefMap
=
new
HashMap
<
String
,
StructTypeDefinition
>();
traitNameToDefMap
=
new
HashMap
<
String
,
HierarchicalTypeDefinition
<
TraitType
>>();
classNameToDefMap
=
new
HashMap
<
String
,
HierarchicalTypeDefinition
<
ClassType
>>();
recursiveRefs
=
new
ArrayList
<
AttributeInfo
>();
recursiveArrayTypes
=
new
ArrayList
<
DataTypes
.
ArrayType
>();
recursiveMapTypes
=
new
ArrayList
<
DataTypes
.
MapType
>();
transientTypes
=
new
LinkedHashSet
<
String
>();
}
private
IDataType
dataType
(
String
name
)
{
return
TypeSystem
.
this
.
types
.
get
(
name
);
}
/*
/*
* Step 1:
* Step 1:
* - validate cannot redefine types
* - validate cannot redefine types
* - setup an empty TraitType to allow for recursive type graphs.
* -
for Hierarchical Types
setup an empty TraitType to allow for recursive type graphs.
*/
*/
for
(
TraitTypeDefinition
traitDef
:
traitDefs
)
{
private
void
step1
()
throws
MetadataException
{
assert
traitDef
.
typeName
!=
null
;
for
(
StructTypeDefinition
sDef
:
structDefs
)
{
if
(
types
.
containsKey
(
traitDef
.
typeName
)
)
{
assert
sDef
.
typeName
!=
null
;
throw
new
MetadataException
(
String
.
format
(
"Cannot redefine type %s"
,
traitDef
.
typeName
));
TypeUtils
.
validateName
(
sDef
.
typeName
);
if
(
dataType
(
sDef
.
typeName
)
!=
null
)
{
throw
new
MetadataException
(
String
.
format
(
"Cannot redefine type %s"
,
sDef
.
typeName
));
}
TypeSystem
.
this
.
types
.
put
(
sDef
.
typeName
,
new
StructType
(
this
,
sDef
.
typeName
,
sDef
.
attributeDefinitions
.
length
));
structNameToDefMap
.
put
(
sDef
.
typeName
,
sDef
);
transientTypes
.
add
(
sDef
.
typeName
);
}
for
(
HierarchicalTypeDefinition
<
TraitType
>
traitDef
:
traitDefs
)
{
assert
traitDef
.
typeName
!=
null
;
TypeUtils
.
validateName
(
traitDef
.
typeName
);
if
(
types
.
containsKey
(
traitDef
.
typeName
))
{
throw
new
MetadataException
(
String
.
format
(
"Cannot redefine type %s"
,
traitDef
.
typeName
));
}
TypeSystem
.
this
.
types
.
put
(
traitDef
.
typeName
,
new
TraitType
(
this
,
traitDef
.
typeName
,
traitDef
.
superTypes
,
traitDef
.
attributeDefinitions
.
length
));
traitNameToDefMap
.
put
(
traitDef
.
typeName
,
traitDef
);
transientTypes
.
add
(
traitDef
.
typeName
);
}
}
transientTypes
.
traitTypes
.
put
(
traitDef
.
typeName
,
for
(
HierarchicalTypeDefinition
<
ClassType
>
classDef
:
classDefs
)
{
new
TraitType
(
transientTypes
,
traitDef
.
typeName
,
traitDef
.
superTraits
,
assert
classDef
.
typeName
!=
null
;
traitDef
.
attributeDefinitions
.
length
));
TypeUtils
.
validateName
(
classDef
.
typeName
);
traitDefMap
.
put
(
traitDef
.
typeName
,
traitDef
);
if
(
types
.
containsKey
(
classDef
.
typeName
))
{
throw
new
MetadataException
(
String
.
format
(
"Cannot redefine type %s"
,
classDef
.
typeName
));
}
TypeSystem
.
this
.
types
.
put
(
classDef
.
typeName
,
new
ClassType
(
this
,
classDef
.
typeName
,
classDef
.
superTypes
,
classDef
.
attributeDefinitions
.
length
));
classNameToDefMap
.
put
(
classDef
.
typeName
,
classDef
);
transientTypes
.
add
(
classDef
.
typeName
);
}
}
}
/*
private
<
U
extends
HierarchicalType
>
void
validateSuperTypes
(
Class
<
U
>
cls
,
HierarchicalTypeDefinition
<
U
>
def
)
* Step 2:
throws
MetadataException
{
* - validate SuperTypes.
*/
for
(
TraitTypeDefinition
traitDef
:
traitDefs
)
{
Set
<
String
>
s
=
new
HashSet
<
String
>();
Set
<
String
>
s
=
new
HashSet
<
String
>();
for
(
String
superTraitName
:
traitDef
.
superTraits
)
{
ImmutableList
<
String
>
superTypes
=
def
.
superTypes
;
for
(
String
superTypeName
:
superTypes
)
{
if
(
s
.
contains
(
superT
raitName
)
)
{
if
(
s
.
contains
(
superT
ypeName
)
)
{
throw
new
MetadataException
(
String
.
format
(
"T
rait %s extends superTrait
%s multiple times"
,
throw
new
MetadataException
(
String
.
format
(
"T
ype %s extends superType
%s multiple times"
,
traitDef
.
typeName
,
superTrait
Name
));
def
.
typeName
,
superType
Name
));
}
}
IDataType
dT
=
types
.
get
(
superTraitName
);
IDataType
dT
=
dataType
(
superTypeName
);
dT
=
dT
==
null
?
transientTypes
.
traitTypes
.
get
(
superTraitName
)
:
dT
;
if
(
dT
==
null
)
{
if
(
dT
==
null
)
{
throw
new
MetadataException
(
String
.
format
(
"Unknown superType %s in definition of type %s"
,
throw
new
MetadataException
(
String
.
format
(
"Unknown superType %s in definition of type %s"
,
superT
raitName
,
traitD
ef
.
typeName
));
superT
ypeName
,
d
ef
.
typeName
));
}
}
if
(
dT
.
getTypeCategory
()
!=
DataTypes
.
TypeCategory
.
TRAIT
)
{
if
(
!
cls
.
isAssignableFrom
(
dT
.
getClass
())
)
{
throw
new
MetadataException
(
String
.
format
(
"SuperType %s must be a
Trait
, in definition of type %s"
,
throw
new
MetadataException
(
String
.
format
(
"SuperType %s must be a
%s
, in definition of type %s"
,
superT
raitName
,
traitD
ef
.
typeName
));
superT
ypeName
,
cls
.
getName
(),
d
ef
.
typeName
));
}
}
s
.
add
(
superT
rait
Name
);
s
.
add
(
superT
ype
Name
);
}
}
}
}
/*
/*
* Step
3
:
* Step
2
:
* -
Construct TraitTypes in order of SuperType before SubType
.
* -
for Hierarchical Types, validate SuperTypes
.
*/
*/
List
<
TraitType
>
l
=
new
ArrayList
<
TraitType
>(
transientTypes
.
traitTypes
.
values
());
private
void
step2
()
throws
MetadataException
{
Collections
.
sort
(
l
);
for
(
HierarchicalTypeDefinition
<
TraitType
>
traitDef
:
traitDefs
)
{
List
<
AttributeInfo
>
recursiveRefs
=
new
ArrayList
<
AttributeInfo
>();
validateSuperTypes
(
TraitType
.
class
,
traitDef
);
List
<
DataTypes
.
ArrayType
>
recursiveArrayTypes
=
new
ArrayList
<
DataTypes
.
ArrayType
>();
}
List
<
DataTypes
.
MapType
>
recursiveMapTypes
=
new
ArrayList
<
DataTypes
.
MapType
>();
try
{
for
(
TraitType
ttO
:
l
)
{
TraitTypeDefinition
traitDef
=
traitDefMap
.
get
(
ttO
.
getName
());
AttributeInfo
[]
infos
=
new
AttributeInfo
[
traitDef
.
attributeDefinitions
.
length
];
for
(
int
i
=
0
;
i
<
traitDef
.
attributeDefinitions
.
length
;
i
++)
{
infos
[
i
]
=
new
AttributeInfo
(
this
,
traitDef
.
attributeDefinitions
[
i
]);
if
(
transientTypes
.
traitTypes
.
containsKey
(
traitDef
.
attributeDefinitions
[
i
].
dataTypeName
))
{
recursiveRefs
.
add
(
infos
[
i
]);
}
if
(
infos
[
i
].
dataType
().
getTypeCategory
()
==
DataTypes
.
TypeCategory
.
ARRAY
)
{
DataTypes
.
ArrayType
arrType
=
(
DataTypes
.
ArrayType
)
infos
[
i
].
dataType
();
if
(
transientTypes
.
traitTypes
.
containsKey
(
arrType
.
getElemType
().
getName
()))
{
recursiveArrayTypes
.
add
(
arrType
);
}
}
if
(
infos
[
i
].
dataType
().
getTypeCategory
()
==
DataTypes
.
TypeCategory
.
MAP
)
{
DataTypes
.
MapType
mapType
=
(
DataTypes
.
MapType
)
infos
[
i
].
dataType
();
if
(
transientTypes
.
traitTypes
.
containsKey
(
mapType
.
getKeyType
().
getName
()))
{
recursiveMapTypes
.
add
(
mapType
);
}
else
if
(
transientTypes
.
traitTypes
.
containsKey
(
mapType
.
getValueType
().
getName
()))
{
recursiveMapTypes
.
add
(
mapType
);
}
}
}
TraitType
tt
=
new
TraitType
(
this
,
traitDef
.
typeName
,
traitDef
.
superTraits
,
infos
);
for
(
HierarchicalTypeDefinition
<
ClassType
>
classDef
:
classDefs
)
{
types
.
put
(
tt
.
getName
(),
tt
);
validateSuperTypes
(
ClassType
.
class
,
classDef
);
}
}
}
/*
private
AttributeInfo
constructAttributeInfo
(
AttributeDefinition
attrDef
)
throws
MetadataException
{
* Step 4:
AttributeInfo
info
=
new
AttributeInfo
(
this
,
attrDef
);
* - fix up references in recursive AttrInfo and recursive Collection Types.
if
(
transientTypes
.
contains
(
attrDef
.
dataTypeName
))
{
*/
recursiveRefs
.
add
(
info
);
for
(
AttributeInfo
info
:
recursiveRefs
)
{
info
.
setDataType
(
dataType
(
info
.
dataType
().
getName
()));
}
}
for
(
DataTypes
.
ArrayType
arrType
:
recursiveArrayTypes
)
{
if
(
info
.
dataType
().
getTypeCategory
()
==
DataTypes
.
TypeCategory
.
ARRAY
)
{
arrType
.
setElemType
(
dataType
(
arrType
.
getElemType
().
getName
()));
DataTypes
.
ArrayType
arrType
=
(
DataTypes
.
ArrayType
)
info
.
dataType
();
if
(
transientTypes
.
contains
(
arrType
.
getElemType
().
getName
()))
{
recursiveArrayTypes
.
add
(
arrType
);
}
}
}
for
(
DataTypes
.
MapType
mapType
:
recursiveMapTypes
)
{
if
(
info
.
dataType
().
getTypeCategory
()
==
DataTypes
.
TypeCategory
.
MAP
)
{
mapType
.
setKeyType
(
dataType
(
mapType
.
getKeyType
().
getName
()));
DataTypes
.
MapType
mapType
=
(
DataTypes
.
MapType
)
info
.
dataType
();
mapType
.
setValueType
(
dataType
(
mapType
.
getValueType
().
getName
()));
if
(
transientTypes
.
contains
(
mapType
.
getKeyType
().
getName
()))
{
recursiveMapTypes
.
add
(
mapType
);
}
else
if
(
transientTypes
.
contains
(
mapType
.
getValueType
().
getName
()))
{
recursiveMapTypes
.
add
(
mapType
);
}
}
}
}
catch
(
MetadataException
me
)
{
for
(
String
sT
:
transientTypes
.
traitTypes
.
keySet
())
{
return
info
;
types
.
remove
(
sT
);
}
private
StructType
constructStructureType
(
StructTypeDefinition
def
)
throws
MetadataException
{
AttributeInfo
[]
infos
=
new
AttributeInfo
[
def
.
attributeDefinitions
.
length
];
for
(
int
i
=
0
;
i
<
def
.
attributeDefinitions
.
length
;
i
++)
{
infos
[
i
]
=
constructAttributeInfo
(
def
.
attributeDefinitions
[
i
]);
}
}
throw
me
;
StructType
type
=
new
StructType
(
TypeSystem
.
this
,
def
.
typeName
,
null
,
infos
);
TypeSystem
.
this
.
types
.
put
(
def
.
typeName
,
type
);
return
type
;
}
}
return
transientTypes
.
traitTypes
;
private
<
U
extends
HierarchicalType
>
U
constructHierarchicalType
(
Class
<
U
>
cls
,
}
HierarchicalTypeDefinition
<
U
>
def
)
throws
MetadataException
{
AttributeInfo
[]
infos
=
new
AttributeInfo
[
def
.
attributeDefinitions
.
length
];
for
(
int
i
=
0
;
i
<
def
.
attributeDefinitions
.
length
;
i
++)
{
infos
[
i
]
=
constructAttributeInfo
(
def
.
attributeDefinitions
[
i
]);
}
try
{
Constructor
<
U
>
cons
=
cls
.
getDeclaredConstructor
(
new
Class
[]{
TypeSystem
.
class
,
String
.
class
,
ImmutableList
.
class
,
AttributeInfo
[].
class
});
U
type
=
cons
.
newInstance
(
TypeSystem
.
this
,
def
.
typeName
,
def
.
superTypes
,
infos
);
TypeSystem
.
this
.
types
.
put
(
def
.
typeName
,
type
);
return
type
;
}
catch
(
Exception
e
)
{
throw
new
MetadataException
(
String
.
format
(
"Cannot construct Type of MetaType %s"
,
cls
.
getName
()),
e
);
}
}
/*
* Step 3:
* - Order Hierarchical Types in order of SuperType before SubType.
* - Construct all the Types
*/
private
void
step3
()
throws
MetadataException
{
public
DataTypes
.
ArrayType
defineArrayType
(
IDataType
elemType
)
throws
MetadataException
{
List
<
TraitType
>
traitTypes
=
new
ArrayList
<
TraitType
>();
assert
elemType
!=
null
;
for
(
String
traitTypeName
:
traitNameToDefMap
.
keySet
())
{
DataTypes
.
ArrayType
dT
=
new
DataTypes
.
ArrayType
(
elemType
);
traitTypes
.
add
(
getDataType
(
TraitType
.
class
,
traitTypeName
));
types
.
put
(
dT
.
getName
(),
dT
);
}
return
dT
;
Collections
.
sort
(
traitTypes
);
}
public
DataTypes
.
MapType
defineMapType
(
IDataType
keyType
,
IDataType
valueType
)
throws
MetadataException
{
List
<
ClassType
>
classTypes
=
new
ArrayList
<
ClassType
>();
assert
keyType
!=
null
;
for
(
String
classTypeName
:
classNameToDefMap
.
keySet
())
{
assert
valueType
!=
null
;
classTypes
.
add
(
getDataType
(
ClassType
.
class
,
classTypeName
));
DataTypes
.
MapType
dT
=
new
DataTypes
.
MapType
(
keyType
,
valueType
);
}
types
.
put
(
dT
.
getName
(),
dT
);
Collections
.
sort
(
classTypes
);
return
dT
;
}
class
TransientTypeSystem
extends
TypeSystem
{
for
(
StructTypeDefinition
structDef
:
structDefs
)
{
Map
<
String
,
TraitType
>
traitTypes
=
new
HashMap
<
String
,
TraitType
>();
constructStructureType
(
structDef
);
}
TransientTypeSystem
()
{
for
(
TraitType
traitType
:
traitTypes
)
{
super
(
TypeSystem
.
this
);
constructHierarchicalType
(
TraitType
.
class
,
traitNameToDefMap
.
get
(
traitType
.
getName
()));
}
for
(
ClassType
classType
:
classTypes
)
{
constructHierarchicalType
(
ClassType
.
class
,
classNameToDefMap
.
get
(
classType
.
getName
()));
}
}
/*
* Step 4:
* - fix up references in recursive AttrInfo and recursive Collection Types.
*/
private
void
step4
()
throws
MetadataException
{
for
(
AttributeInfo
info
:
recursiveRefs
)
{
info
.
setDataType
(
dataType
(
info
.
dataType
().
getName
()));
}
for
(
DataTypes
.
ArrayType
arrType
:
recursiveArrayTypes
)
{
arrType
.
setElemType
(
dataType
(
arrType
.
getElemType
().
getName
()));
}
for
(
DataTypes
.
MapType
mapType
:
recursiveMapTypes
)
{
mapType
.
setKeyType
(
dataType
(
mapType
.
getKeyType
().
getName
()));
mapType
.
setValueType
(
dataType
(
mapType
.
getValueType
().
getName
()));
}
}
}
public
IDataType
dataType
(
String
name
)
{
Map
<
String
,
IDataType
>
defineTypes
()
throws
MetadataException
{
IDataType
dT
=
TypeSystem
.
this
.
dataType
(
name
);
step1
();
dT
=
dT
==
null
?
traitTypes
.
get
(
name
)
:
dT
;
step2
();
return
dT
;
try
{
step3
();
step4
();
}
catch
(
MetadataException
me
)
{
for
(
String
sT
:
transientTypes
)
{
types
.
remove
(
sT
);
}
throw
me
;
}
Map
<
String
,
IDataType
>
newTypes
=
new
HashMap
<
String
,
IDataType
>();
for
(
String
tName
:
transientTypes
)
{
newTypes
.
put
(
tName
,
dataType
(
tName
));
}
return
newTypes
;
}
}
@Override
@Override
...
@@ -275,35 +411,44 @@ public class TypeSystem {
...
@@ -275,35 +411,44 @@ public class TypeSystem {
}
}
@Override
@Override
public
<
T
>
T
getDataType
(
Class
<
T
>
cls
,
String
name
)
throws
MetadataException
{
public
<
T
>
T
getDataType
(
Class
<
T
>
cls
,
String
name
)
throws
MetadataException
{
return
TypeSystem
.
this
.
getDataType
(
cls
,
name
);
return
TypeSystem
.
this
.
getDataType
(
cls
,
name
);
}
}
@Override
@Override
public
StructType
defineStructType
(
String
name
,
boolean
errorIfExists
,
AttributeDefinition
...
attrDefs
)
public
StructType
defineStructType
(
String
name
,
boolean
errorIfExists
,
AttributeDefinition
...
attrDefs
)
throws
MetadataException
{
throws
MetadataException
{
return
TypeSystem
.
this
.
defineStructType
(
name
,
errorIfExists
,
attrDefs
);
throw
new
MetadataException
(
"Internal Error: define type called on TrasientTypeSystem"
);
}
}
@Override
@Override
public
TraitType
defineTraitType
(
boolean
errorIfExists
,
Trait
TypeDefinition
traitDef
)
throws
MetadataException
{
public
TraitType
defineTraitType
(
Hierarchical
TypeDefinition
traitDef
)
throws
MetadataException
{
return
TypeSystem
.
this
.
defineTraitType
(
errorIfExists
,
traitDef
);
throw
new
MetadataException
(
"Internal Error: define type called on TrasientTypeSystem"
);
}
}
@Override
@Override
public
Map
<
String
,
TraitType
>
defineTraitTypes
(
boolean
errorIfExists
,
TraitTypeDefinition
...
traitDefs
)
public
ClassType
defineClassType
(
HierarchicalTypeDefinition
<
ClassType
>
classDef
)
throws
MetadataException
{
throw
new
MetadataException
(
"Internal Error: define type called on TrasientTypeSystem"
);
}
@Override
public
Map
<
String
,
IDataType
>
defineTypes
(
ImmutableList
<
StructTypeDefinition
>
structDefs
,
ImmutableList
<
HierarchicalTypeDefinition
<
TraitType
>>
traitDefs
,
ImmutableList
<
HierarchicalTypeDefinition
<
ClassType
>>
classDefs
)
throws
MetadataException
{
throws
MetadataException
{
return
TypeSystem
.
this
.
defineTraitTypes
(
errorIfExists
,
traitDefs
);
throw
new
MetadataException
(
"Internal Error: define type called on TrasientTypeSystem"
);
}
}
@Override
@Override
public
DataTypes
.
ArrayType
defineArrayType
(
IDataType
elemType
)
throws
MetadataException
{
public
DataTypes
.
ArrayType
defineArrayType
(
IDataType
elemType
)
throws
MetadataException
{
return
TypeSystem
.
this
.
defineArrayType
(
elemType
);
throw
new
MetadataException
(
"Internal Error: define type called on TrasientTypeSystem"
);
}
}
@Override
@Override
public
DataTypes
.
MapType
defineMapType
(
IDataType
keyType
,
IDataType
valueType
)
throws
MetadataException
{
public
DataTypes
.
MapType
defineMapType
(
IDataType
keyType
,
IDataType
valueType
)
throws
MetadataException
{
return
TypeSystem
.
this
.
defineMapType
(
keyType
,
valueType
);
throw
new
MetadataException
(
"Internal Error: define type called on TrasientTypeSystem"
);
}
}
}
}
}
}
src/test/java/org/apache/metadata/BaseTest.java
View file @
b8feeebf
...
@@ -21,13 +21,9 @@ package org.apache.metadata;
...
@@ -21,13 +21,9 @@ package org.apache.metadata;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
junit.framework.TestCase
;
import
org.apache.metadata.storage.IRepository
;
import
org.apache.metadata.storage.memory.MemRepository
;
import
org.apache.metadata.storage.memory.MemRepository
;
import
org.apache.metadata.types.*
;
import
org.apache.metadata.types.*
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
...
@@ -126,18 +122,18 @@ public abstract class BaseTest {
...
@@ -126,18 +122,18 @@ public abstract class BaseTest {
return
new
AttributeDefinition
(
name
,
dataType
,
Multiplicity
.
REQUIRED
,
false
,
null
);
return
new
AttributeDefinition
(
name
,
dataType
,
Multiplicity
.
REQUIRED
,
false
,
null
);
}
}
protected
Map
<
String
,
TraitType
>
defineTraits
(
Trait
TypeDefinition
...
tDefs
)
throws
MetadataException
{
protected
Map
<
String
,
IDataType
>
defineTraits
(
Hierarchical
TypeDefinition
...
tDefs
)
throws
MetadataException
{
return
ms
.
getTypeSystem
().
defineTraitTypes
(
t
rue
,
t
Defs
);
return
ms
.
getTypeSystem
().
defineTraitTypes
(
tDefs
);
}
}
protected
TraitTypeDefinition
createTraitTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
protected
HierarchicalTypeDefinition
<
TraitType
>
createTraitTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
...
attrDefs
)
{
AttributeDefinition
...
attrDefs
)
{
return
new
TraitTypeDefinition
(
name
,
superTypes
,
attrDefs
);
return
new
HierarchicalTypeDefinition
(
TraitType
.
class
,
name
,
superTypes
,
attrDefs
);
}
}
protected
ClassTypeDefinition
createClassTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
protected
HierarchicalTypeDefinition
<
ClassType
>
createClassTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
...
attrDefs
)
{
AttributeDefinition
...
attrDefs
)
{
return
new
ClassTypeDefinition
(
name
,
superTypes
,
attrDefs
);
return
new
HierarchicalTypeDefinition
(
ClassType
.
class
,
name
,
superTypes
,
attrDefs
);
}
}
}
}
src/test/java/org/apache/metadata/TraitTest.java
View file @
b8feeebf
...
@@ -2,13 +2,10 @@ package org.apache.metadata;
...
@@ -2,13 +2,10 @@ package org.apache.metadata;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.apache.metadata.storage.StructInstance
;
import
org.apache.metadata.types.*
;
import
org.apache.metadata.types.*
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.util.Map
;
public
class
TraitTest
extends
BaseTest
{
public
class
TraitTest
extends
BaseTest
{
...
@@ -34,16 +31,16 @@ public class TraitTest extends BaseTest {
...
@@ -34,16 +31,16 @@ public class TraitTest extends BaseTest {
*/
*/
@Test
@Test
public
void
test1
()
throws
MetadataException
{
public
void
test1
()
throws
MetadataException
{
Trait
TypeDefinition
A
=
createTraitTypeDef
(
"A"
,
null
,
Hierarchical
TypeDefinition
A
=
createTraitTypeDef
(
"A"
,
null
,
createRequiredAttrDef
(
"a"
,
DataTypes
.
INT_TYPE
),
createRequiredAttrDef
(
"a"
,
DataTypes
.
INT_TYPE
),
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
),
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
),
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
));
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
));
Trait
TypeDefinition
B
=
createTraitTypeDef
(
"B"
,
ImmutableList
.<
String
>
of
(
"A"
),
Hierarchical
TypeDefinition
B
=
createTraitTypeDef
(
"B"
,
ImmutableList
.<
String
>
of
(
"A"
),
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
));
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
));
Trait
TypeDefinition
C
=
createTraitTypeDef
(
"C"
,
ImmutableList
.<
String
>
of
(
"A"
),
Hierarchical
TypeDefinition
C
=
createTraitTypeDef
(
"C"
,
ImmutableList
.<
String
>
of
(
"A"
),
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
));
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
));
Trait
TypeDefinition
D
=
createTraitTypeDef
(
"D"
,
ImmutableList
.<
String
>
of
(
"B"
,
"C"
),
Hierarchical
TypeDefinition
D
=
createTraitTypeDef
(
"D"
,
ImmutableList
.<
String
>
of
(
"B"
,
"C"
),
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
));
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
));
defineTraits
(
A
,
B
,
C
,
D
);
defineTraits
(
A
,
B
,
C
,
D
);
...
...
src/test/scala/org/apache/metadata/json/SerializationTest.scala
View file @
b8feeebf
...
@@ -78,16 +78,16 @@ class SerializationTest extends BaseTest {
...
@@ -78,16 +78,16 @@ class SerializationTest extends BaseTest {
}
}
@Test
def
testTrait
{
@Test
def
testTrait
{
val
A
:
TraitTypeDefinition
=
createTraitTypeDef
(
"A"
,
null
,
val
A
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"A"
,
null
,
BaseTest
.
createRequiredAttrDef
(
"a"
,
DataTypes
.
INT_TYPE
),
BaseTest
.
createRequiredAttrDef
(
"a"
,
DataTypes
.
INT_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
))
BaseTest
.
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
))
val
B
:
TraitTypeDefinition
=
createTraitTypeDef
(
"B"
,
ImmutableList
.
of
[
String
](
"A"
),
val
B
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"B"
,
ImmutableList
.
of
[
String
](
"A"
),
BaseTest
.
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
))
BaseTest
.
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
))
val
C
:
TraitTypeDefinition
=
createTraitTypeDef
(
"C"
,
ImmutableList
.
of
[
String
](
"A"
),
val
C
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"C"
,
ImmutableList
.
of
[
String
](
"A"
),
BaseTest
.
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
))
BaseTest
.
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_TYPE
))
val
D
:
TraitTypeDefinition
=
createTraitTypeDef
(
"D"
,
ImmutableList
.
of
[
String
](
"B"
,
"C"
),
val
D
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"D"
,
ImmutableList
.
of
[
String
](
"B"
,
"C"
),
BaseTest
.
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
))
BaseTest
.
createOptionalAttrDef
(
"d"
,
DataTypes
.
SHORT_TYPE
))
defineTraits
(
A
,
B
,
C
,
D
)
defineTraits
(
A
,
B
,
C
,
D
)
...
...
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