Skip to content

Commit

Permalink
Add support for byte string columns. Fixes #141. (#142)
Browse files Browse the repository at this point in the history
* Add support for byte string columns. Fixes #141.

* Fixes #145 by upgrading to java 18.
  • Loading branch information
erikmafo authored Aug 9, 2022
1 parent 77e3799 commit 3d53223
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup Java JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 18
- name: Install with maven
env:
JAVA_TOOL_OPTIONS: ${{ matrix.java-opts }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codacy-coverage-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Java JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 18
- name: Verify with maven
env:
JAVA_TOOL_OPTIONS: "-Djava.awt.headless=true -Dtestfx.robot=glass -Dtestfx.headless=true -Dprism.order=sw -Dprism.text=t2k"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup Java JDK
uses: actions/[email protected]
with:
java-version: 17
java-version: 18

- name: Checkout repository
uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.erikmafo</groupId>
<artifactId>littletableviewer</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>
<name>Little Table Viewer</name>

Expand Down Expand Up @@ -39,7 +39,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>17</release>
<release>18</release>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -196,13 +196,13 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.2</version>
<version>18.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.2</version>
<version>18.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/erikmafo/ltviewer/model/BigtableCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Base64;

/**
* A simple representation of a bigtable row cell.
*/
Expand Down Expand Up @@ -70,6 +72,8 @@ public String getQualifier() {
*/
public String getValueAsString() { return bytes.toStringUtf8(); }

public String getValueAsStringBase64() { return Base64.getEncoder().encodeToString(bytes.toByteArray()); }

/**
* Gets the value of the cell as a byte array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ private BigtableValue convertUsingValueType(BigtableCell cell, @NotNull CellDefi
return toBigtableValue(cell.getValueAsString(), valueTypeUpper);
case ValueTypeConstants.PROTO:
return toBigtableValue(ProtoUtil.toJson(cell.getByteString(), cellDefinition.getProtoObjectDefinition()), valueTypeUpper);
case ValueTypeConstants.BYTE_STRING:
return toBigtableValue(cell.getValueAsStringBase64(), valueTypeUpper);
default:
return toBigtableValue(cell.getValueAsString(), ValueTypeConstants.STRING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public ByteString toByteString(Field field, Value value) {
case ValueTypeConstants.LONG:
byteString = ByteStringConverterUtil.toByteString(value.asLong());
break;
case ValueTypeConstants.BYTE_STRING:
byteString = ByteStringConverterUtil.toByteStringFromBase64(value.asString());
break;
default: throw new IllegalArgumentException(String.format("Value type %s is not supported", valueType.toUpperCase()));
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/erikmafo/ltviewer/model/CellDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public void setQualifier(String qualifier) {
this.qualifier = qualifier;
}

public ProtoObjectDefinition getProtoObjectDefinition() {
return protoObjectDefinition;
}

public void setProtoObjectDefinition(ProtoObjectDefinition protoObjectDefinition) {
this.protoObjectDefinition = protoObjectDefinition;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -85,8 +93,4 @@ public String toString() {
", qualifier='" + qualifier + '\'' +
'}';
}

public ProtoObjectDefinition getProtoObjectDefinition() {
return protoObjectDefinition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.jetbrains.annotations.NotNull;

public class ProtoObjectDefinition {
private final String descriptorSetFile;
private final String protoFile;
private final String messageType;
private String descriptorSetFile;
private String protoFile;
private String messageType;

public ProtoObjectDefinition(String descriptorSetFile, String protoFile, String messageType) {
Check.notNullOrEmpty(descriptorSetFile, "descriptorSetFile");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class ValueTypeConstants {
public static final String JSON = "JSON";

public static final String PROTO = "PROTO";

public static final String BYTE_STRING = "BYTESTRING";
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.erikmafo.ltviewer.services.internal.testdata;

import com.erikmafo.ltviewer.model.BigtableInstance;
import com.erikmafo.ltviewer.model.ProtoObjectDefinition;
import com.erikmafo.ltviewer.services.internal.BigtableEmulatorSettingsProvider;
import com.erikmafo.ltviewer.util.ProtoUtil;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import com.google.protobuf.ByteString;
import org.jetbrains.annotations.NotNull;

import java.io.Console;
import java.io.IOException;

import static com.erikmafo.ltviewer.util.ByteStringConverterUtil.toByteString;
Expand All @@ -35,6 +32,7 @@ public class TestDataUtil {
private static final String PROJECT_0 = "project-0";
private static final String INSTANCE_0 = "instance-0";
private static final String TABLE_0 = "table-0";
public static final ByteString BYTE_STRING_TEST_VALUE = toByteString(842098349384L);

public static void injectWithTestData(BigtableEmulatorSettingsProvider settingsProvider) {
try {
Expand Down Expand Up @@ -74,7 +72,7 @@ private static void addData(String tableName, com.google.cloud.bigtable.data.v2.
.setCell("f1", toByteString("q3"), toByteString(i + 0.5))
.setCell("f1", toByteString("q4"), toByteString(JSON_TEST_DATA))
.setCell("f2", toByteString("q1"), toByteString("string-" + i))
.setCell("f3", toByteString("q1"), toByteString("string-" + i))
.setCell("f3", toByteString("q1"), BYTE_STRING_TEST_VALUE)
.setCell("f4", toByteString("q1"), getPerson(i).toByteString());
dataClient.mutateRow(mutation);
}
Expand All @@ -87,6 +85,7 @@ private static PersonOuterClass.Person getPerson(int i) {
.setName("Person-" + i)
.setId("" + i)
.setAge(i % 100)
.setBytes(BYTE_STRING_TEST_VALUE)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

V
person.proto">
l
person.proto"T
Person
name ( Rname
id ( Rid
age (Ragebproto3
age (Rage
bytes ( Rbytesbproto3
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ message Person {
string name = 1;
string id = 2;
int32 age = 3;
bytes bytes = 4;
}
Loading

0 comments on commit 3d53223

Please sign in to comment.