-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to Transpose data in Shiftr.
Fixes #91 #108 Added to the '@' wildcard functionality to allow for data lookup in the input tree. - Example : input : { "data" : { "key" : "penguins", "value" : "fish" } spec : { "data" : { "@value" : "@key" } } output : { "penguins" : "fish" } This will pull values from the "data" Map, from the "key" and "value" keys. - Complex paths after the '@' can be embedded in a parenthesis - Example : "@(path.to.data.down.the[2].tree.&(1,1))" - Note : The "path" after an '@' can not contain any '*' wildcards. - Cleaned up the Parsing of PathElements for Shiftr. - Refactored the WalkedPath so that it can contain a pointer to the input from each level - For Transpose, the ability to coerce a Boolean into a String of "true" or "false". - Ability to specify a String value on the LHS by using the # operator. -- Compelling usecase is transposing a boolean into more useful String values. Also, added to the '#' operator so that values from the spec can be written directly to the output. This was possible before, but required two passes thru Shiftr.
- Loading branch information
milo.simpson
committed
Oct 13, 2014
1 parent
7bf1651
commit 7d9735c
Showing
56 changed files
with
2,025 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
jolt-core/src/main/java/com/bazaarvoice/jolt/common/PathStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2014 Bazaarvoice, Inc. | ||
* | ||
* Licensed 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 com.bazaarvoice.jolt.common; | ||
|
||
import com.bazaarvoice.jolt.common.pathelement.LiteralPathElement; | ||
|
||
/** | ||
* A tuple class that contains the data for one level of a | ||
* tree walk, aka a reference to the input for that level, and | ||
* the LiteralPathElement that was matched at that level. | ||
*/ | ||
public final class PathStep { | ||
private final Object treeRef; | ||
private final LiteralPathElement literalPathElement; | ||
|
||
public PathStep(Object treeRef, LiteralPathElement literalPathElement) { | ||
this.treeRef = treeRef; | ||
this.literalPathElement = literalPathElement; | ||
} | ||
|
||
public Object getTreeRef() { | ||
return treeRef; | ||
} | ||
|
||
public LiteralPathElement getLiteralPathElement() { | ||
return literalPathElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
jolt-core/src/main/java/com/bazaarvoice/jolt/common/pathelement/HashPathElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2013 Bazaarvoice, Inc. | ||
* | ||
* Licensed 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 com.bazaarvoice.jolt.common.pathelement; | ||
|
||
import com.bazaarvoice.jolt.common.WalkedPath; | ||
import com.bazaarvoice.jolt.exception.SpecException; | ||
import com.bazaarvoice.jolt.utils.StringTools; | ||
|
||
/** | ||
* For use on the LHS, allows the user to specify an explicit string to write out. | ||
* Aka given a input that is boolean, would want to write something out other than "true" / "false". | ||
*/ | ||
public class HashPathElement extends BasePathElement implements MatchablePathElement { | ||
|
||
private final String keyValue; | ||
|
||
public HashPathElement( String key ) { | ||
super(key); | ||
|
||
if ( StringTools.isBlank( key ) ) { | ||
throw new SpecException( "HashPathElement cannot have empty String as input." ); | ||
} | ||
|
||
if ( ! key.startsWith( "#" ) ) { | ||
throw new SpecException( "LHS # should start with a # : " + key ); | ||
} | ||
|
||
if ( key.length() <= 1 ) { | ||
throw new SpecException( "HashPathElement input is too short : " + key ); | ||
} | ||
|
||
|
||
if ( key.charAt( 1 ) == '(' ) { | ||
if ( key.charAt( key.length() -1 ) == ')' ) { | ||
keyValue = key.substring( 2, key.length() -1 ); | ||
} | ||
else { | ||
throw new SpecException( "HashPathElement, mismatched parens : " + key ); | ||
} | ||
} | ||
else { | ||
keyValue = key.substring( 1 ); | ||
} | ||
} | ||
|
||
@Override | ||
public String getCanonicalForm() { | ||
return "#(" + keyValue + ")"; | ||
} | ||
|
||
@Override | ||
public LiteralPathElement match( String dataKey, WalkedPath walkedPath ) { | ||
return new LiteralPathElement( keyValue ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.