Motivation:
This PR extracted the process of understanding ion schema out of data generating and data writing processes. Before refactoring, the method of extracting information out of ion schema file is to load the ion schema file to IonReader and then iterate the element until we find the target constraints. And this process also followed by data generating which makes adding new features of processing constraints complicated. After refactoring, supporting new features process will only contain two steps:
Adding the class which is used for implementing the functionalities of the new constraint.
Adding more steps in data generating process to extract the constraint value then generating data based on this constraint value.
There are multiple files changed in this PR and this PR has been separated into different commits based on the different functionalities.
Commits:
Adds package to process ion schema file:
ReparsedType.java: ReparsedType aims to simplify the process of understanding ion schema and the implemented methods including getName(), getISL(), getIonType(), getConstraintMap(). After passing parameter type which represents ion schema type definition to constructor, the created object allows to extract constraints information directly by using provided methods.
ReparsedConstraint.java: All constraints included in ion schema type definition after converting ion schema type definition from Type to ReparsedType will be converted to ReparsedConstraint. The ReparsedConstraint class is inherited by QuantifiableConstraints, Regex and ValidValues three different types of constraints.
QuantifiableConstraint.java: This class is inherited by Scale, Precision, TimestampPrecision, ByteLength, CodepointLength, and ContainerLength. All these constraint objects’ values have the same pattern from set ([, <RANGE>]) or could be processed into the format provided in the set. The value of these objects will be extracted as Range type by using method getRange().
ValidValues.java: After creating object from class ValidValues, the constraint value can be extracted by method getValidValues(). If the provided ‘valid_values’ contains annotation range, the range value will be extracted by using method getRange().
Range.java: This class implements methods of processing constraints values which contain annotation ‘range’. It provides methods uppBound() and lowerBound() which allow to access the bound values. In the data generating process, when a range of quantifiable constraint value provided, the ion data generator will randomly choose the constraint value randomly within the provided range. This class allows to get the random value within the range directly by using method getRandomQuantifiableValueFromRange().
Regex.java: Regex inherits class ReparsedConstraint. This class implements method getPattern() which allows to get the regular expression pattern in String format.
Commits which updated the process of generating different types of ion data:
In these commits, the process of extracting constraints from schema has been replaced by using the new ion schema understanding classes. For now, only generating scalar types of ion data processes have been updated, and some container data generating processes have been temporarily comment to avoid build failure. However, this PR will keep updating until all refactoring finished.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Description of changes:
Motivation: This PR extracted the process of understanding ion schema out of data generating and data writing processes. Before refactoring, the method of extracting information out of ion schema file is to load the ion schema file to IonReader and then iterate the element until we find the target constraints. And this process also followed by data generating which makes adding new features of processing constraints complicated. After refactoring, supporting new features process will only contain two steps:
Commits:
getName()
,getISL()
,getIonType()
,getConstraintMap()
. After passing parametertype
which represents ion schema type definition to constructor, the created object allows to extract constraints information directly by using provided methods.QuantifiableConstraints
,Regex
andValidValues
three different types of constraints.Scale
,Precision
,TimestampPrecision
,ByteLength
,CodepointLength
, andContainerLength
. All these constraint objects’ values have the same pattern from set ([getRange()
.getValidValues()
. If the provided ‘valid_values’ contains annotation range, the range value will be extracted by using methodgetRange()
.uppBound()
andlowerBound()
which allow to access the bound values. In the data generating process, when a range of quantifiable constraint value provided, the ion data generator will randomly choose the constraint value randomly within the provided range. This class allows to get the random value within the range directly by using methodgetRandomQuantifiableValueFromRange()
.Regex
inherits classReparsedConstraint
. This class implements methodgetPattern()
which allows to get the regular expression pattern in String format.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.