Skip to content

Commit

Permalink
address timestamp url decoding for ts partitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstreev committed Sep 12, 2020
1 parent 8ed12ce commit 296717a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hive-sre/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.streever.hive</groupId>
<artifactId>hive-sre</artifactId>
<version>2.3.2.1-SNAPSHOT</version>
<version>2.3.2.2-SNAPSHOT</version>

<name>hive</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public String runCalculations(CommandReturn commandReturn) {
}
} catch (ScriptException e) {
e.printStackTrace();
System.err.println("Issue with script eval: " + this.getName() + ":" + calcKey);
} catch (MissingFormatArgumentException mfa) {
mfa.printStackTrace();
System.err.println("Bad Argument Match up for PATH check rule: " + this.getName() + ":" + calcKey);
Expand Down Expand Up @@ -209,6 +210,7 @@ public String runCalculations(CommandReturn commandReturn) {
}
} catch (ScriptException e) {
e.printStackTrace();
System.err.println("Issue with script eval: " + this.getName() + ":" + calcKey);
} catch (MissingFormatArgumentException mfa) {
mfa.printStackTrace();
System.err.println("Bad Argument Match up for RECORDS check rule: " + this.getName() + ":" + calcKey);
Expand Down
11 changes: 9 additions & 2 deletions hive-sre/src/main/java/com/streever/hive/sre/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

import org.apache.commons.lang.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class Utils {

public static String dirToPartitionSpec(String directoryPart) {
public static String dirToPartitionSpec(String directoryPart) throws UnsupportedEncodingException {
String[] directories = directoryPart.split("\\/");
String[] partitionSpecs = new String[directories.length];
int loc = 0;
for (String directory: directories) {
String[] specParts = directory.split("=");
partitionSpecs[loc++] = specParts[0] + "=\"" + specParts[1] + "\"";
String partDir = null;
partDir = URLDecoder.decode(specParts[1], StandardCharsets.UTF_8.toString());
partitionSpecs[loc++] = specParts[0] + "=\"" + partDir + "\"";
}
StringBuilder rtn = new StringBuilder();
rtn.append(StringUtils.join(partitionSpecs, ","));
Expand Down
25 changes: 24 additions & 1 deletion hive-sre/src/test/java/com/streever/hive/sre/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.junit.Test;

import java.io.UnsupportedEncodingException;

import static org.junit.Assert.*;

public class UtilsTest {
Expand All @@ -11,8 +13,29 @@ public void dirToPartitionSpec_001() {
String[] testSet = {"st=GA A/update_dt=2020-09-03"};

for (String test: testSet) {
String spec = Utils.dirToPartitionSpec(test);
String spec = null;
try {
spec = Utils.dirToPartitionSpec(test);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println(spec);
}
}

@Test
public void decodeTS_001() {
String[] testSet = {"st=GA A/update_dt=2019-09-01 12%3A31%3A44.333"};

for (String test: testSet) {
String spec = null;
try {
spec = Utils.dirToPartitionSpec(test);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println(spec);
}
}

}

0 comments on commit 296717a

Please sign in to comment.