Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accumulated changed from release 0.1.21 to 0.1.26 #49

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
58f4fd4
minor refactor
jianwu Sep 15, 2021
a070db4
Add ClassUtil.findMethod
jianwu Oct 10, 2021
82d0a8a
rename CacheProvider to ScopeProvider; add TimeProvider.now(); Move a…
jianwu Dec 28, 2021
82c55aa
.
jianwu Jan 17, 2022
abb5388
add ArrayUtil.subArray()
jianwu Jan 17, 2022
0fa335c
Add hive udf to_json
jianwu Feb 8, 2022
d4ba291
release 0.1.22
jianwu Feb 9, 2022
c1f96c7
Add ToCSVUDF; refactor csv parser
jianwu Feb 13, 2022
ec28c57
add unit test for ToCSVUDF
jianwu Feb 13, 2022
509154b
update ToCSVUDF to support noHeader and headers option
jianwu Feb 13, 2022
62581e2
Remove dependency of java.beans.Transient as it's not available in An…
jianwu Mar 7, 2022
c09ffa2
Add JSONCodeOption.sortObjectKeys; update SnapShotTest to use it so t…
jianwu Apr 22, 2022
605912c
Fix JSONCoder non-deterministic issue in testing
jianwu Apr 24, 2022
4b545e9
release 0.1.25; fix typo in execption message; update ListUtil.Map() …
jianwu Aug 18, 2022
fb87ead
support has checker for Bean methods in ClassUtil
jianwu Aug 20, 2022
a620bab
release 0.1.26
jianwu Aug 20, 2022
4bb95ea
restore test for TDPathTest
jianwu Aug 21, 2022
71b59d0
Add LangUtil.seq
jianwu Aug 25, 2022
0a6fa12
Release 0.1.27: add LangUtil.seq, with
jianwu Sep 2, 2022
bb7db42
Add TwoWayMap; Add ArrayUtil.contains()
jianwu Sep 7, 2022
29d8064
Support TreeDoc.dedupeNodes(); update TDNode.hashCode() to not includ…
jianwu Dec 5, 2022
ad8cc42
add missing files
jianwu Dec 14, 2022
4d1ee72
Update ClassUtil to support java17 Record style getter methods
jianwu Dec 15, 2022
5e36659
Add TDJSONOption.setDeliminatorObject()
jianwu Jan 8, 2023
d437f3d
support treedoc with type as a wrapper element
jianwu Jan 9, 2023
90464ee
Add TimeProvider.nanoTime
jianwu Jan 24, 2023
8b35f7a
Add header support for CSV writer and parser
jianwu Feb 19, 2023
bd882bb
Add test for csv parse object
jianwu Feb 19, 2023
9d7854b
Avoid calling CSVOption.buildTerm() from caller
jianwu Feb 19, 2023
9072a31
.
jianwu Feb 20, 2023
2b5cf59
refactor unit test to avoid duplications
jianwu Feb 20, 2023
62a51f3
[csv] fix parse quoted fields
jianwu Feb 20, 2023
2ef6714
Update JSONCoderOption to support fieldSelectOption for particular cl…
jianwu Apr 18, 2023
c884088
Create maven.yml
jianwu Apr 18, 2023
b0d6759
add missing files
jianwu Apr 18, 2023
6cb510b
fix github action build
jianwu Apr 18, 2023
dcd6836
Fix TimeProvider.nanoTime()
jianwu May 9, 2023
a10cb87
Add ListUtil.reduce
jianwu Jun 1, 2023
1b9febe
update ListUtil to accept Iterable instead of Collection
jianwu Jun 2, 2023
19bb640
Support path compression
jianwu Jul 6, 2023
49fd4b6
fix test
jianwu Jul 8, 2023
e4421c6
Add name index for TDNode for large number of chilrens; Improve CliArg
jianwu Aug 8, 2023
76b3e81
Fix TDNode.namedIndex not updated for new child
jianwu Sep 11, 2023
62d1b27
fix csv writer for TDNode fields missing quote issue
jianwu Sep 16, 2023
46a64ad
csvwriter write empty string for null values
jianwu Sep 16, 2023
2953aa5
.
jianwu Sep 16, 2023
8011a66
csvwriter treat null as empty string
jianwu Sep 17, 2023
cb3e1da
.
jianwu Sep 17, 2023
f7dbfa3
TDJSONWriter to support alwaysQuoteValue and useTypeWrapper options
jianwu Sep 19, 2023
a94d40e
fix test; add , for for _quoteNeededChars
jianwu Sep 20, 2023
73e8f4d
fix csv parser for double quoted string contains comma
jianwu Sep 24, 2023
c478ec3
.
jianwu Sep 25, 2023
5a5a8ea
Add SetUtil
jianwu Dec 23, 2023
417afd0
fix build badge
jianwu Dec 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ build.xml
nb-configuration.xml
*.versionsBackup
.gradle
.factorypath
.nondex
2 changes: 1 addition & 1 deletion CliArg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.21</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>CliArg</artifactId>
Expand Down
33 changes: 20 additions & 13 deletions CliArg/src/main/java/org/jsonex/cliarg/CLIParser.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.jsonex.cliarg;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.jsonex.core.util.BeanConvertContext;
import org.jsonex.core.util.ClassUtil;
import static org.jsonex.core.util.LangUtil.doIf;
import static org.jsonex.core.util.LangUtil.doIfNotNull;
import static org.jsonex.core.util.ListUtil.isIn;
import org.jsonex.jsoncoder.JSONCoder;
import org.jsonex.jsoncoder.JSONCoderOption;
import org.jsonex.treedoc.TDNode.Type;
import org.jsonex.treedoc.json.TDJSONOption;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

import static org.jsonex.core.util.LangUtil.doIf;
import static org.jsonex.core.util.ListUtil.isIn;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Parse the input command line arguments against the {@link CLISpec}. The parsed result will be stored in the target
Expand Down Expand Up @@ -106,7 +112,7 @@ private void parseArg(String arg) {
}
Param param = spec.indexedParams.get(paramIndex++);
missingParams.remove(param.name);
param.property.set(target, parseValue(param, arg));
doIfNotNull(parseValue(param, arg), v -> param.property.set(target, v));
}

private Object parseValue(Param param, String value) {
Expand All @@ -124,7 +130,8 @@ private Object parseValue(Param param, String value) {
? JSONCoder.decode(value, cls, opt)
: JSONCoder.decodeTo(value, param.getProperty().get(target), opt.setMergeArray(true));
} catch (Exception e) {
log.error("Error parsing parameter:" + param.name, e);
errorMessages.put(param.name, value + ";" + e.toString());
// log.error("Error parsing parameter:" + param.name, e);
}
return null;
}
Expand All @@ -133,9 +140,9 @@ private Object parseValue(Param param, String value) {

public String getErrorsAsString() {
StringBuilder sb = new StringBuilder();
doIf(!missingParams.isEmpty(), () -> sb.append("\nMissing required arguments:" + missingParams));
doIf(!extraArgs.isEmpty(), () -> sb.append("\nUnexpected arguments:" + extraArgs));
doIf(!errorMessages.isEmpty(), () -> sb.append("\nError parsing following arguments:" + errorMessages));
doIf(!missingParams.isEmpty(), () -> sb.append("\nMissing required arguments:").append(missingParams));
doIf(!extraArgs.isEmpty(), () -> sb.append("\nUnexpected arguments:").append(extraArgs));
doIf(!errorMessages.isEmpty(), () -> sb.append("\nError parsing following arguments:").append(errorMessages));
return sb.toString();
}
}
4 changes: 3 additions & 1 deletion CliArg/src/main/java/org/jsonex/cliarg/CLISpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
import static org.jsonex.core.util.ListUtil.setAt;

/**
* <pre>
* CLI specification based on annotated java bean of `cls`. Following annotations will be processed:
*
* Class level:
* {@link Name}: Name of the command. (Optional) Default to the class simple name
* {@link Summary}: Summary of the command (Optional)
* {@link Description}: Description of the command (Optional)
* {@link Examples}: Array of string representation of samples usages (Optional)
*
* For field level annotations, please refer to class {@link Param}
*
* </pre>
*
* @param <T>
*/
@Data
Expand Down
23 changes: 12 additions & 11 deletions CliArg/src/main/java/org/jsonex/cliarg/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@
import static org.jsonex.core.util.StringUtil.noNull;

/**
* Represent an command line parameter, it can be either argument or option
* If index is not null indicate it's argument
* Argument default to required unless explicitly specified.
* required argument can't follow non-required argument which index less than it
* If index is null indicates it's an option, option default to not required, unless specified
*
* For option of Boolean type, it will be mapped as flag, that means the value of the option can be omitted.
*
* <pre>
* Represent a command line parameter, it can be either argument or option
* If index is not null indicate it is an argument.
* Argument default to required unless explicitly specified.
* Required argument can't follow non-required argument which index less than it
* If index is null indicates it's an option, option default to not required, unless specified
* For option of Boolean type, it will be mapped as flag, that means the value of the option can be omitted.

* For Param of complex type or array/list, the value can be specified as JSON(ex) string, the top level "{" or "[",
* can be, omitted. The quote for key and value can be omitted.
*
* For array parameters, it also possible to specify the values as separate options. The values will be merged
*

* For array parameters, it is also possible to specify the values as separate options. The values will be merged

* Following Annotation will be processed for each parameter:
*
* {@link Name} Name of the parameter, optional, default to field name
* {@link ShortName} The optional short name
* {@link Description} The optional description
* {@link Index} Indicate this an indexed parameter
* {@link Required} Indicate if this field is required. all the index fields are required unless explicitly indicated.
* All the non-index fields are not required unless explicitly indicated.
* </pre>
*/
@Data
public class Param {
Expand Down
4 changes: 2 additions & 2 deletions CliArg/src/test/java/org/jsonex/cliarg/CliParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public static class Arg1 {

@Test
public void testParse() {
CLISpec spec = new CLISpec(Arg1.class);
CLISpec<Arg1> spec = new CLISpec<>(Arg1.class);
assertMatchesSnapshot("spec", spec);

log.info("spec:\n" + spec.printUsage());
assertMatchesSnapshot("usage", spec.printUsage());

String[] args = { "abc", "10", "name:n1,x:1,y:2", "-o", "VAL2", "--optInt", "100",
"--arrayArg", "str1,str2,'It\\'s escapted'", "--arrayArg", "array as separate option"};
CLIParser parser = spec.parse(args, 0);
CLIParser<Arg1> parser = spec.parse(args, 0);
log.info("parsedValue:\n" + parser.target);
assertMatchesSnapshot("parserTarget", parser.target);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"strParam":"abc",
"arrayArg":[
"str1",
"str2",
"It's escapted",
"array as separate option"
],
"noShortName":0,
"numParam":10,
"opt":"VAL2",
"optInt":100,
"point":{
"name":"n1",
"x":1,
"y":2
},
"opt":"VAL2",
"optInt":100,
"noShortName":0,
"arrayArg":[
"str1",
"str2",
"It's escapted",
"array as separate option"
]
"strParam":"abc"
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"cls":"org.jsonex.cliarg.CliParserTest.Arg1",
"defVal":{
"noShortName":0,
"numParam":0,
"opt":"VAL1",
"optInt":10,
"noShortName":0
"optInt":10
},
"name":"TestArg1",
"summary":"This is a test arg1",
"description":"Description of test Args",
"examples":[
"arg1 2",
"arg1 4"
],
"firstOptionalIndex":2,
"optionParams":[
{
"name":"opt",
"shortName":"o",
"description":"Opt",
"defVal":"VAL1",
"required":true
},
"indexedParams":[
{
"name":"optInt",
"shortName":"i",
"defVal":10
"description":"Str parameter",
"index":0,
"name":"strParam"
},
{
"name":"noShortName",
"defVal":0
"defVal":0,
"description":"number parameter",
"index":1,
"name":"numParam"
},
{
"name":"arrayArg",
"description":"array of string, you can specify either use ',' separated string (jsonex array, with escape supported), or pass as multiple options"
"description":"Object Point",
"index":2,
"name":"point",
"required":false
}
],
"indexedParams":[
"name":"TestArg1",
"optionParams":[
{
"name":"strParam",
"index":0,
"description":"Str parameter"
"defVal":"VAL1",
"description":"Opt",
"name":"opt",
"required":true,
"shortName":"o"
},
{
"name":"numParam",
"index":1,
"description":"number parameter",
"defVal":0
"defVal":10,
"name":"optInt",
"shortName":"i"
},
{
"name":"point",
"index":2,
"description":"Object Point",
"required":false
"defVal":0,
"name":"noShortName"
},
{
"description":"array of string, you can specify either use ',' separated string (jsonex array, with escape supported), or pass as multiple options",
"name":"arrayArg"
}
],
"requiredParams":[
"strParam",
"numParam",
"opt"
],
"summary":"This is a test arg1",
"usage":"TestArg1 -o {opt} [-i {optInt}] [--noShortName {noShortName}] [--arrayArg {arrayArg}] <strParam> <numParam> [point]"
}
53 changes: 53 additions & 0 deletions HiveUDF/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>HiveUDF</artifactId>
<name>HiveUDF</name>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>JSONCoder</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>csv</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SnapshotTest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SnapshotTest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>4.0.0-alpha-2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading