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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
57 additions
and
76 deletions
+57
-76
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
+0
-0
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
* Used when creating a ClassType, to support recursive Structs.
*/
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
)
throws
MetadataException
{
super
(
typeSystem
,
name
,
superTraits
,
fields
);
super
(
typeSystem
,
ClassType
.
class
,
name
,
superTraits
,
fields
);
}
@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
implements
Comparable
<
ST
>
{
public
final
TypeSystem
typeSystem
;
public
final
Class
<
ST
>
superTypeClass
;
public
final
String
name
;
public
final
FieldMapping
fieldMapping
;
public
final
int
numFields
;
...
...
@@ -47,8 +48,10 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
/**
* 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
.
superTypeClass
=
superTypeClass
;
this
.
name
=
name
;
this
.
fieldMapping
=
null
;
this
.
numFields
=
numFields
;
...
...
@@ -56,9 +59,11 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
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
{
this
.
typeSystem
=
typeSystem
;
this
.
superTypeClass
=
superTypeClass
;
this
.
name
=
name
;
this
.
fieldMapping
=
constructFieldMapping
(
superTypes
,
fields
);
...
...
@@ -115,8 +120,9 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
queue
.
add
(
new
Node
(
getName
()));
while
(!
queue
.
isEmpty
())
{
Path
currentPath
=
queue
.
poll
();
ST
superType
=
currentPath
.
typeName
==
getName
()
?
(
ST
)
this
:
(
ST
)
typeSystem
.
dataType
(
currentPath
.
typeName
);
(
ST
)
typeSystem
.
getDataType
(
superTypeClass
,
currentPath
.
typeName
);
pathNameToPathMap
.
put
(
currentPath
.
pathName
,
currentPath
);
if
(
superType
!=
this
)
{
...
...
@@ -248,7 +254,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
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
));
return
new
DownCastStructInstance
(
superTypeName
,
new
DownCastFieldMapping
(
ImmutableMap
.
copyOf
(
downCastMap
)),
...
...
@@ -318,7 +324,12 @@ public abstract class HierarchicalType<ST extends HierarchicalType,T> extends Ab
@Override
public
Path
next
()
{
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
)
{
ImmutableList
<
String
>
sTs
=
t
.
superTypes
;
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;
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
>
superTraits
;
public
final
AttributeDefinition
[]
attributeDefinitions
;
public
final
ImmutableList
<
String
>
superTypes
;
public
ClassTypeDefinition
(
String
typeName
,
ImmutableList
<
String
>
superTraits
,
AttributeDefinition
[]
attributeDefinitions
)
{
this
.
typeName
=
typeName
;
this
.
superTraits
=
superTraits
==
null
?
ImmutableList
.<
String
>
of
()
:
superTraits
;
this
.
attributeDefinitions
=
attributeDefinition
s
;
public
HierarchicalTypeDefinition
(
Class
<
T
>
hierarchicalMetaType
,
String
typeName
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
[]
attributeDefinitions
)
{
super
(
typeName
,
attributeDefinitions
)
;
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>
* Used when creating a TraitType, to support recursive Structs.
*/
TraitType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
int
numFields
)
{
super
(
typeSystem
,
name
,
superTraits
,
numFields
);
super
(
typeSystem
,
TraitType
.
class
,
name
,
superTraits
,
numFields
);
handler
=
null
;
}
TraitType
(
TypeSystem
typeSystem
,
String
name
,
ImmutableList
<
String
>
superTraits
,
AttributeInfo
...
fields
)
throws
MetadataException
{
super
(
typeSystem
,
name
,
superTraits
,
fields
);
super
(
typeSystem
,
TraitType
.
class
,
name
,
superTraits
,
fields
);
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
This diff is collapsed.
Click to expand it.
src/test/java/org/apache/metadata/BaseTest.java
View file @
b8feeebf
...
...
@@ -21,13 +21,9 @@ package org.apache.metadata;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.Lists
;
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.types.*
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
...
...
@@ -126,18 +122,18 @@ public abstract class BaseTest {
return
new
AttributeDefinition
(
name
,
dataType
,
Multiplicity
.
REQUIRED
,
false
,
null
);
}
protected
Map
<
String
,
TraitType
>
defineTraits
(
Trait
TypeDefinition
...
tDefs
)
throws
MetadataException
{
return
ms
.
getTypeSystem
().
defineTraitTypes
(
t
rue
,
t
Defs
);
protected
Map
<
String
,
IDataType
>
defineTraits
(
Hierarchical
TypeDefinition
...
tDefs
)
throws
MetadataException
{
return
ms
.
getTypeSystem
().
defineTraitTypes
(
tDefs
);
}
protected
TraitTypeDefinition
createTraitTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
protected
HierarchicalTypeDefinition
<
TraitType
>
createTraitTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
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
)
{
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;
import
com.google.common.collect.ImmutableList
;
import
org.junit.Assert
;
import
org.apache.metadata.storage.StructInstance
;
import
org.apache.metadata.types.*
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.util.Map
;
public
class
TraitTest
extends
BaseTest
{
...
...
@@ -34,16 +31,16 @@ public class TraitTest extends BaseTest {
*/
@Test
public
void
test1
()
throws
MetadataException
{
Trait
TypeDefinition
A
=
createTraitTypeDef
(
"A"
,
null
,
Hierarchical
TypeDefinition
A
=
createTraitTypeDef
(
"A"
,
null
,
createRequiredAttrDef
(
"a"
,
DataTypes
.
INT_TYPE
),
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_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
));
Trait
TypeDefinition
C
=
createTraitTypeDef
(
"C"
,
ImmutableList
.<
String
>
of
(
"A"
),
Hierarchical
TypeDefinition
C
=
createTraitTypeDef
(
"C"
,
ImmutableList
.<
String
>
of
(
"A"
),
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
));
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 {
}
@Test
def
testTrait
{
val
A
:
TraitTypeDefinition
=
createTraitTypeDef
(
"A"
,
null
,
val
A
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"A"
,
null
,
BaseTest
.
createRequiredAttrDef
(
"a"
,
DataTypes
.
INT_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"b"
,
DataTypes
.
BOOLEAN_TYPE
),
BaseTest
.
createOptionalAttrDef
(
"c"
,
DataTypes
.
BYTE_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
))
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
))
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
))
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