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
f053fd59
Commit
f053fd59
authored
Jun 20, 2017
by
ashutoshm
Committed by
Madhan Neethiraj
Jun 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1876: fix to handle large float/double values during ser-de, export/import
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
242b5585
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
27 deletions
+103
-27
AtlasBuiltInTypes.java
...rc/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
+12
-2
AtlasType.java
intg/src/main/java/org/apache/atlas/type/AtlasType.java
+3
-2
TestAtlasBuiltInTypesFloatDouble.java
...g/apache/atlas/type/TestAtlasBuiltInTypesFloatDouble.java
+63
-0
ZipSource.java
...in/java/org/apache/atlas/repository/impexp/ZipSource.java
+3
-23
ZipSourceTest.java
...ava/org/apache/atlas/repository/impexp/ZipSourceTest.java
+22
-0
stocks-float.zip
repository/src/test/resources/stocks-float.zip
+0
-0
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
View file @
f053fd59
...
...
@@ -283,7 +283,12 @@ public class AtlasBuiltInTypes {
return
((
Number
)
obj
).
floatValue
();
}
else
{
try
{
return
Float
.
valueOf
(
obj
.
toString
());
Float
f
=
Float
.
valueOf
(
obj
.
toString
());
if
(!
Float
.
isInfinite
(
f
))
{
return
f
;
}
else
{
return
null
;
}
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
...
...
@@ -329,7 +334,12 @@ public class AtlasBuiltInTypes {
return
((
Number
)
obj
).
doubleValue
();
}
else
{
try
{
return
Double
.
valueOf
(
obj
.
toString
());
Double
d
=
Double
.
valueOf
(
obj
.
toString
());
if
(!
Double
.
isInfinite
(
d
))
{
return
d
;
}
else
{
return
null
;
}
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
...
...
intg/src/main/java/org/apache/atlas/type/AtlasType.java
View file @
f053fd59
...
...
@@ -21,9 +21,9 @@ package org.apache.atlas.type;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.TypeCategory
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.codehaus.jackson.map.DeserializationConfig
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
java.io.IOException
;
import
java.util.List
;
...
...
@@ -36,7 +36,8 @@ import java.util.List;
public
abstract
class
AtlasType
{
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
()
.
configure
(
DeserializationConfig
.
Feature
.
USE_BIG_DECIMAL_FOR_FLOATS
,
true
);
private
final
String
typeName
;
private
final
TypeCategory
typeCategory
;
...
...
intg/src/test/java/org/apache/atlas/type/TestAtlasBuiltInTypesFloatDouble.java
0 → 100644
View file @
f053fd59
/**
* 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
.
atlas
.
type
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertNull
;
public
class
TestAtlasBuiltInTypesFloatDouble
{
@Test
public
void
floatRangeCheck
()
{
assertFloatChecks
(
String
.
valueOf
(
"-1.E-45"
),
true
);
assertFloatChecks
(
String
.
valueOf
(
Float
.
MAX_VALUE
),
true
);
assertFloatChecks
(
"3.4028235E32"
,
true
);
assertFloatChecks
(
"-3.4028235E32"
,
true
);
assertFloatChecks
(
String
.
valueOf
(
Float
.
MIN_VALUE
),
true
);
assertFloatChecks
(
"4028235e+555"
,
false
);
assertFloatChecks
(
"-4028235e+555"
,
false
);
}
@Test
public
void
doubleRangeCheck
()
{
assertDoubleChecks
(
String
.
valueOf
(
Double
.
MAX_VALUE
),
true
);
assertDoubleChecks
(
"3.4028235E32"
,
true
);
assertDoubleChecks
(
String
.
valueOf
(
Double
.
MIN_VALUE
),
true
);
assertDoubleChecks
(
"4028235e+55555"
,
false
);
assertDoubleChecks
(
"-4028235e+55555"
,
false
);
}
private
void
assertFloatChecks
(
String
v
,
boolean
notNull
)
{
assertNullNotNull
(
notNull
,
new
AtlasBuiltInTypes
.
AtlasFloatType
().
getNormalizedValue
(
v
));
}
private
void
assertDoubleChecks
(
String
v
,
boolean
notNull
)
{
assertNullNotNull
(
notNull
,
new
AtlasBuiltInTypes
.
AtlasDoubleType
().
getNormalizedValue
(
v
));
}
private
void
assertNullNotNull
(
boolean
notNull
,
Object
f
)
{
if
(
notNull
)
{
assertNotNull
(
f
);
}
else
{
assertNull
(
f
);
}
}
}
repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java
View file @
f053fd59
...
...
@@ -23,9 +23,8 @@ import org.apache.atlas.model.instance.AtlasEntity;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.repository.store.graph.v1.EntityImportStream
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.commons.lang.StringUtils
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.type.TypeReference
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -39,8 +38,6 @@ import java.util.Map;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
JSON_ERROR_OBJECT_MAPPER_NULL_RETURNED
;
public
class
ZipSource
implements
EntityImportStream
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ZipSource
.
class
);
...
...
@@ -90,7 +87,7 @@ public class ZipSource implements EntityImportStream {
try
{
String
s
=
getFromCache
(
fileName
);
this
.
creationOrder
=
convertFromJson
(
new
TypeReference
<
List
<
String
>>(){}
,
s
);
this
.
creationOrder
=
convertFromJson
(
List
.
class
,
s
);
this
.
iterator
=
this
.
creationOrder
.
iterator
();
}
catch
(
AtlasBaseException
e
)
{
LOG
.
error
(
String
.
format
(
"Error retrieving '%s' from zip."
,
fileName
),
e
);
...
...
@@ -137,26 +134,9 @@ public class ZipSource implements EntityImportStream {
return
entityWithExtInfo
;
}
private
<
T
>
T
convertFromJson
(
TypeReference
clazz
,
String
jsonData
)
throws
AtlasBaseException
{
try
{
ObjectMapper
mapper
=
new
ObjectMapper
();
T
ret
=
mapper
.
readValue
(
jsonData
,
clazz
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
JSON_ERROR_OBJECT_MAPPER_NULL_RETURNED
,
clazz
.
toString
());
}
return
ret
;
}
catch
(
Exception
e
)
{
throw
new
AtlasBaseException
(
"Error converting file to JSON."
,
e
);
}
}
private
<
T
>
T
convertFromJson
(
Class
<
T
>
clazz
,
String
jsonData
)
throws
AtlasBaseException
{
try
{
ObjectMapper
mapper
=
new
ObjectMapper
();
return
mapper
.
readValue
(
jsonData
,
clazz
);
return
AtlasType
.
fromJson
(
jsonData
,
clazz
);
}
catch
(
Exception
e
)
{
throw
new
AtlasBaseException
(
"Error converting file to JSON."
,
e
);
...
...
repository/src/test/java/org/apache/atlas/repository/impexp/ZipSourceTest.java
View file @
f053fd59
...
...
@@ -44,6 +44,13 @@ public class ZipSourceTest {
return
new
Object
[][]
{{
new
ZipSource
(
fs
)
}};
}
@DataProvider
(
name
=
"zipFileStocksFloat"
)
public
static
Object
[][]
getDataFromZipFileWithLongFloats
()
throws
IOException
{
FileInputStream
fs
=
ZipFileResourceTestUtils
.
getFileInputStream
(
"stocks-float.zip"
);
return
new
Object
[][]
{{
new
ZipSource
(
fs
)
}};
}
@DataProvider
(
name
=
"sales"
)
public
static
Object
[][]
getDataFromQuickStart_v1_Sales
(
ITestContext
context
)
throws
IOException
{
return
getZipSource
(
"sales-v1-full.zip"
);
...
...
@@ -139,6 +146,21 @@ public class ZipSourceTest {
assertTrue
(
zipSource
.
hasNext
());
}
@Test
(
dataProvider
=
"zipFileStocksFloat"
)
public
void
attemptToSerializeLongFloats
(
ZipSource
zipSource
)
throws
IOException
,
AtlasBaseException
{
Assert
.
assertTrue
(
zipSource
.
hasNext
());
assertTrue
(
zipSource
.
hasNext
());
assertTrue
(
zipSource
.
hasNext
());
AtlasEntity
.
AtlasEntityWithExtInfo
e
=
zipSource
.
getNextEntityWithExtInfo
();
assertNotNull
(
e
);
assertTrue
(
e
.
getEntity
().
getClassifications
().
size
()
>
0
);
assertNotNull
(
e
.
getEntity
().
getClassifications
().
get
(
0
).
getAttribute
(
"fv"
));
assertEquals
(
e
.
getEntity
().
getClassifications
().
get
(
0
).
getAttribute
(
"fv"
).
toString
(),
"3.4028235E+38"
);
assertTrue
(
zipSource
.
hasNext
());
}
@Test
(
dataProvider
=
"zipFileStocks"
)
public
void
applyTransformation
(
ZipSource
zipSource
)
throws
IOException
,
AtlasBaseException
{
ImportTransforms
transforms
=
getTransformForHiveDB
();
...
...
repository/src/test/resources/stocks-float.zip
0 → 100644
View file @
f053fd59
File added
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