Skip to content

Commit 0cd3f0d

Browse files
authored
feat(java,info): add prefix for adj/pg and add datatype parser test (#820)
* add prefix for adj/pg and add datatype parser test * fix prefix
1 parent f87ca77 commit 0cd3f0d

File tree

6 files changed

+97
-12
lines changed

6 files changed

+97
-12
lines changed

maven-projects/info/src/main/java/org/apache/graphar/info/yaml/AdjacentListYaml.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ public AdjacentListYaml(org.apache.graphar.info.AdjacentList adjacentList) {
4444
}
4545

4646
public AdjacentList toAdjacentList() {
47+
String adjPrefix = prefix;
48+
if (adjPrefix == null || adjPrefix.isEmpty()) {
49+
adjPrefix = AdjListType.fromOrderedAndAlignedBy(ordered, aligned_by) + "/";
50+
}
4751
return new AdjacentList(
4852
AdjListType.fromOrderedAndAlignedBy(ordered, aligned_by),
4953
FileType.fromString(file_type),
50-
prefix);
54+
adjPrefix);
5155
}
5256

5357
public boolean isOrdered() {

maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyGroupYaml.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,22 @@ public PropertyGroupYaml(PropertyGroup propertyGroup) {
4646
}
4747

4848
public PropertyGroup toPropertyGroup() {
49+
String pgPrefix = prefix;
50+
if (pgPrefix == null || pgPrefix.isEmpty()) {
51+
StringBuilder prefixBuilder = new StringBuilder();
52+
for (int i = 0; i < properties.size(); i++) {
53+
if (i > 0) {
54+
prefixBuilder.append("_");
55+
}
56+
prefixBuilder.append(properties.get(i).getName());
57+
}
58+
prefixBuilder.append("/");
59+
pgPrefix = prefixBuilder.toString();
60+
}
4961
return new PropertyGroup(
5062
properties.stream().map(PropertyYaml::toProperty).collect(Collectors.toList()),
5163
FileType.fromString(file_type),
52-
prefix);
64+
pgPrefix);
5365
}
5466

5567
public List<PropertyYaml> getProperties() {

maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoLoaderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ public static void clean() {}
4242

4343
@Test
4444
public void testStringLoader() throws IOException {
45-
final URI GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
45+
final URI GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
4646
GraphInfoLoader loader = new LocalFileSystemStringGraphInfoLoader();
4747
final GraphInfo graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
4848
testGraphInfo(graphInfo);
4949
}
5050

5151
@Test
5252
public void testStreamLoader() throws IOException {
53-
final URI GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
53+
final URI GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
5454
GraphInfoLoader loader = new LocalFileSystemStreamGraphInfoLoader();
5555
final GraphInfo graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
5656
testGraphInfo(graphInfo);
5757
}
5858

5959
@Test
6060
public void testReaderLoader() throws IOException {
61-
final URI GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
61+
final URI GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
6262
GraphInfoLoader loader = new LocalFileSystemReaderGraphInfoLoader();
6363
final GraphInfo graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
6464
testGraphInfo(graphInfo);

maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class GraphInfoTest {
4242
private static VertexInfo personVertexInfo;
4343
private static EdgeInfo knowsEdgeInfo;
4444
private static URI GRAPH_PATH_URI;
45+
private static URI PARUQET_GRAPH_PATH_URI;
4546
// test not exist property group
4647
private static final PropertyGroup notExistPg =
4748
new PropertyGroup(
@@ -54,7 +55,8 @@ public static void setUp() {
5455
TestUtil.checkTestData();
5556

5657
// Always use real test data - fail if not available
57-
GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
58+
GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
59+
PARUQET_GRAPH_PATH_URI = TestUtil.getParquetLdbcSampleGraphURI();
5860
GraphInfoLoader loader = new LocalFileSystemStreamGraphInfoLoader();
5961
try {
6062
graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
@@ -510,4 +512,41 @@ public void testIsValidated() {
510512
graphInfo.getVersion().toString());
511513
Assert.assertFalse(invalidEdgeGraphInfo.isValidated());
512514
}
515+
516+
@Test
517+
public void testParquetGraphInfo() {
518+
GraphInfoLoader loader = new LocalFileSystemStreamGraphInfoLoader();
519+
GraphInfo graphInfo;
520+
try {
521+
graphInfo = loader.loadGraphInfo(PARUQET_GRAPH_PATH_URI);
522+
} catch (IOException e) {
523+
throw new RuntimeException(
524+
"Failed to load real test data from "
525+
+ PARUQET_GRAPH_PATH_URI
526+
+ ": "
527+
+ e.getMessage(),
528+
e);
529+
}
530+
VertexInfo personVertexInfo = graphInfo.getVertexInfos().get(0);
531+
EdgeInfo knowsEdgeInfo = graphInfo.getEdgeInfos().get(0);
532+
// test vertex property
533+
PropertyGroup firstName_lastName_gender = personVertexInfo.getPropertyGroups().get(1);
534+
Assert.assertEquals("firstName_lastName_gender/", firstName_lastName_gender.getPrefix());
535+
Assert.assertEquals(FileType.PARQUET, firstName_lastName_gender.getFileType());
536+
Assert.assertEquals(
537+
URI.create("vertex/person/vertex_count"), personVertexInfo.getVerticesNumFileUri());
538+
// test edge property
539+
PropertyGroup creationDate = knowsEdgeInfo.getPropertyGroups().get(0);
540+
Assert.assertEquals("creationDate/", creationDate.getPrefix());
541+
Assert.assertEquals(FileType.PARQUET, creationDate.getFileType());
542+
// test adjlist
543+
AdjacentList adjOrderBySource =
544+
knowsEdgeInfo.getAdjacentList(AdjListType.ordered_by_source);
545+
Assert.assertEquals(FileType.PARQUET, adjOrderBySource.getFileType());
546+
Assert.assertEquals(AdjListType.ordered_by_source, adjOrderBySource.getType());
547+
Assert.assertEquals("ordered_by_source/", adjOrderBySource.getPrefix());
548+
Assert.assertEquals(
549+
URI.create("edge/person_knows_person/ordered_by_source/adj_list/offset/"),
550+
knowsEdgeInfo.getOffsetUri(AdjListType.ordered_by_source));
551+
}
513552
}

maven-projects/info/src/test/java/org/apache/graphar/info/PropertyTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package org.apache.graphar.info;
2121

22+
import java.io.IOException;
23+
import java.net.URI;
24+
import org.apache.graphar.info.loader.impl.LocalFileSystemStringGraphInfoLoader;
2225
import org.apache.graphar.info.type.DataType;
2326
import org.junit.Assert;
2427
import org.junit.Before;
@@ -35,6 +38,7 @@ public void setUp() {
3538
idProperty = TestDataFactory.createIdProperty();
3639
nameProperty = TestDataFactory.createProperty("name", DataType.STRING, false, true);
3740
optionalProperty = TestDataFactory.createProperty("optional", DataType.STRING, false, true);
41+
TestUtil.checkTestData();
3842
}
3943

4044
@Test
@@ -171,4 +175,19 @@ public void testPropertyImmutability() {
171175
TestVerificationUtils.verifyProperty(prop, "test", true, false);
172176
Assert.assertEquals(DataType.INT32, prop.getDataType());
173177
}
178+
179+
@Test
180+
public void testLoadPropertyDateTypes() throws IOException {
181+
String testDataRoot = TestUtil.getTestData();
182+
String timestampEdge =
183+
testDataRoot + "/ldbc_sample/parquet/person_knows-timestamp_person.edge.yml";
184+
LocalFileSystemStringGraphInfoLoader localFileSystemStringGraphInfoLoader =
185+
new LocalFileSystemStringGraphInfoLoader();
186+
EdgeInfo edgeInfo =
187+
localFileSystemStringGraphInfoLoader.loadEdgeInfo(URI.create(timestampEdge));
188+
Assert.assertTrue(edgeInfo.dump().contains("data_type: timestamp"));
189+
String dateEdge = testDataRoot + "/ldbc_sample/parquet/person_knows-date_person.edge.yml";
190+
edgeInfo = localFileSystemStringGraphInfoLoader.loadEdgeInfo(URI.create(dateEdge));
191+
Assert.assertTrue(edgeInfo.dump().contains("data_type: date"));
192+
}
174193
}

maven-projects/info/src/test/java/org/apache/graphar/info/TestUtil.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public class TestUtil {
3737
static final String SAVE_DIR =
3838
System.getProperty("test.output.dir", "target/test-output") + "/";
3939

40-
private static final String LDBC_SAMPLE_GRAPH_PATH = "/ldbc_sample/csv/ldbc_sample.graph.yml";
40+
private static final String CSV_LDBC_SAMPLE_GRAPH_PATH =
41+
"/ldbc_sample/csv/ldbc_sample.graph.yml";
42+
private static final String PARQUET_LDBC_SAMPLE_GRAPH_PATH =
43+
"/ldbc_sample/parquet/ldbc_sample.graph.yml";
4144
private static final String LDBC_GRAPH_PATH = "/ldbc/parquet/ldbc.graph.yml";
4245

4346
public static String getTestData() {
@@ -49,12 +52,20 @@ public static boolean hasTestData() {
4952
return GAR_TEST_DATA != null && new java.io.File(GAR_TEST_DATA).exists();
5053
}
5154

52-
public static String getLdbcSampleGraphPath() {
53-
return getTestData() + "/" + LDBC_SAMPLE_GRAPH_PATH;
55+
public static String getCSVLdbcSampleGraphPath() {
56+
return getTestData() + "/" + CSV_LDBC_SAMPLE_GRAPH_PATH;
5457
}
5558

56-
public static URI getLdbcSampleGraphURI() {
57-
return URI.create(getLdbcSampleGraphPath());
59+
public static URI getCSVLdbcSampleGraphURI() {
60+
return URI.create(getCSVLdbcSampleGraphPath());
61+
}
62+
63+
public static String getParquetLdbcSampleGraphPath() {
64+
return getTestData() + "/" + PARQUET_LDBC_SAMPLE_GRAPH_PATH;
65+
}
66+
67+
public static URI getParquetLdbcSampleGraphURI() {
68+
return URI.create(getParquetLdbcSampleGraphPath());
5869
}
5970

6071
public static String getLdbcGraphPath() {
@@ -127,7 +138,7 @@ public static GraphInfo getLdbcSampleDataSet() {
127138
try {
128139
GraphInfoLoader loader =
129140
new org.apache.graphar.info.loader.impl.LocalFileSystemStreamGraphInfoLoader();
130-
return loader.loadGraphInfo(getLdbcSampleGraphURI());
141+
return loader.loadGraphInfo(getCSVLdbcSampleGraphURI());
131142
} catch (Exception e) {
132143
throw new RuntimeException(
133144
"Failed to load real LDBC sample data: " + e.getMessage(), e);

0 commit comments

Comments
 (0)