Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ public AdjacentListYaml(org.apache.graphar.info.AdjacentList adjacentList) {
}

public AdjacentList toAdjacentList() {
String adjPrefix = prefix;
if (adjPrefix == null || adjPrefix.isEmpty()) {
adjPrefix = AdjListType.fromOrderedAndAlignedBy(ordered, aligned_by) + "/";
}
return new AdjacentList(
AdjListType.fromOrderedAndAlignedBy(ordered, aligned_by),
FileType.fromString(file_type),
prefix);
adjPrefix);
}

public boolean isOrdered() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,22 @@ public PropertyGroupYaml(PropertyGroup propertyGroup) {
}

public PropertyGroup toPropertyGroup() {
String pgPrefix = prefix;
if (pgPrefix == null || pgPrefix.isEmpty()) {
StringBuilder prefixBuilder = new StringBuilder();
for (int i = 0; i < properties.size(); i++) {
if (i > 0) {
prefixBuilder.append("_");
}
prefixBuilder.append(properties.get(i).getName());
}
prefixBuilder.append("/");
pgPrefix = prefixBuilder.toString();
}
return new PropertyGroup(
properties.stream().map(PropertyYaml::toProperty).collect(Collectors.toList()),
FileType.fromString(file_type),
prefix);
pgPrefix);
}

public List<PropertyYaml> getProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ public static void clean() {}

@Test
public void testStringLoader() throws IOException {
final URI GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
final URI GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
GraphInfoLoader loader = new LocalFileSystemStringGraphInfoLoader();
final GraphInfo graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
testGraphInfo(graphInfo);
}

@Test
public void testStreamLoader() throws IOException {
final URI GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
final URI GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
GraphInfoLoader loader = new LocalFileSystemStreamGraphInfoLoader();
final GraphInfo graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
testGraphInfo(graphInfo);
}

@Test
public void testReaderLoader() throws IOException {
final URI GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
final URI GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
GraphInfoLoader loader = new LocalFileSystemReaderGraphInfoLoader();
final GraphInfo graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
testGraphInfo(graphInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class GraphInfoTest {
private static VertexInfo personVertexInfo;
private static EdgeInfo knowsEdgeInfo;
private static URI GRAPH_PATH_URI;
private static URI PARUQET_GRAPH_PATH_URI;
// test not exist property group
private static final PropertyGroup notExistPg =
new PropertyGroup(
Expand All @@ -54,7 +55,8 @@ public static void setUp() {
TestUtil.checkTestData();

// Always use real test data - fail if not available
GRAPH_PATH_URI = TestUtil.getLdbcSampleGraphURI();
GRAPH_PATH_URI = TestUtil.getCSVLdbcSampleGraphURI();
PARUQET_GRAPH_PATH_URI = TestUtil.getParquetLdbcSampleGraphURI();
GraphInfoLoader loader = new LocalFileSystemStreamGraphInfoLoader();
try {
graphInfo = loader.loadGraphInfo(GRAPH_PATH_URI);
Expand Down Expand Up @@ -510,4 +512,41 @@ public void testIsValidated() {
graphInfo.getVersion().toString());
Assert.assertFalse(invalidEdgeGraphInfo.isValidated());
}

@Test
public void testParquetGraphInfo() {
GraphInfoLoader loader = new LocalFileSystemStreamGraphInfoLoader();
GraphInfo graphInfo;
try {
graphInfo = loader.loadGraphInfo(PARUQET_GRAPH_PATH_URI);
} catch (IOException e) {
throw new RuntimeException(
"Failed to load real test data from "
+ PARUQET_GRAPH_PATH_URI
+ ": "
+ e.getMessage(),
e);
}
VertexInfo personVertexInfo = graphInfo.getVertexInfos().get(0);
EdgeInfo knowsEdgeInfo = graphInfo.getEdgeInfos().get(0);
// test vertex property
PropertyGroup firstName_lastName_gender = personVertexInfo.getPropertyGroups().get(1);
Assert.assertEquals("firstName_lastName_gender/", firstName_lastName_gender.getPrefix());
Assert.assertEquals(FileType.PARQUET, firstName_lastName_gender.getFileType());
Assert.assertEquals(
URI.create("vertex/person/vertex_count"), personVertexInfo.getVerticesNumFileUri());
// test edge property
PropertyGroup creationDate = knowsEdgeInfo.getPropertyGroups().get(0);
Assert.assertEquals("creationDate/", creationDate.getPrefix());
Assert.assertEquals(FileType.PARQUET, creationDate.getFileType());
// test adjlist
AdjacentList adjOrderBySource =
knowsEdgeInfo.getAdjacentList(AdjListType.ordered_by_source);
Assert.assertEquals(FileType.PARQUET, adjOrderBySource.getFileType());
Assert.assertEquals(AdjListType.ordered_by_source, adjOrderBySource.getType());
Assert.assertEquals("ordered_by_source/", adjOrderBySource.getPrefix());
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/offset/"),
knowsEdgeInfo.getOffsetUri(AdjListType.ordered_by_source));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package org.apache.graphar.info;

import java.io.IOException;
import java.net.URI;
import org.apache.graphar.info.loader.impl.LocalFileSystemStringGraphInfoLoader;
import org.apache.graphar.info.type.DataType;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -35,6 +38,7 @@ public void setUp() {
idProperty = TestDataFactory.createIdProperty();
nameProperty = TestDataFactory.createProperty("name", DataType.STRING, false, true);
optionalProperty = TestDataFactory.createProperty("optional", DataType.STRING, false, true);
TestUtil.checkTestData();
}

@Test
Expand Down Expand Up @@ -171,4 +175,19 @@ public void testPropertyImmutability() {
TestVerificationUtils.verifyProperty(prop, "test", true, false);
Assert.assertEquals(DataType.INT32, prop.getDataType());
}

@Test
public void testLoadPropertyDateTypes() throws IOException {
String testDataRoot = TestUtil.getTestData();
String timestampEdge =
testDataRoot + "/ldbc_sample/parquet/person_knows-timestamp_person.edge.yml";
LocalFileSystemStringGraphInfoLoader localFileSystemStringGraphInfoLoader =
new LocalFileSystemStringGraphInfoLoader();
EdgeInfo edgeInfo =
localFileSystemStringGraphInfoLoader.loadEdgeInfo(URI.create(timestampEdge));
Assert.assertTrue(edgeInfo.dump().contains("data_type: timestamp"));
String dateEdge = testDataRoot + "/ldbc_sample/parquet/person_knows-date_person.edge.yml";
edgeInfo = localFileSystemStringGraphInfoLoader.loadEdgeInfo(URI.create(dateEdge));
Assert.assertTrue(edgeInfo.dump().contains("data_type: date"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public class TestUtil {
static final String SAVE_DIR =
System.getProperty("test.output.dir", "target/test-output") + "/";

private static final String LDBC_SAMPLE_GRAPH_PATH = "/ldbc_sample/csv/ldbc_sample.graph.yml";
private static final String CSV_LDBC_SAMPLE_GRAPH_PATH =
"/ldbc_sample/csv/ldbc_sample.graph.yml";
private static final String PARQUET_LDBC_SAMPLE_GRAPH_PATH =
"/ldbc_sample/parquet/ldbc_sample.graph.yml";
private static final String LDBC_GRAPH_PATH = "/ldbc/parquet/ldbc.graph.yml";

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

public static String getLdbcSampleGraphPath() {
return getTestData() + "/" + LDBC_SAMPLE_GRAPH_PATH;
public static String getCSVLdbcSampleGraphPath() {
return getTestData() + "/" + CSV_LDBC_SAMPLE_GRAPH_PATH;
}

public static URI getLdbcSampleGraphURI() {
return URI.create(getLdbcSampleGraphPath());
public static URI getCSVLdbcSampleGraphURI() {
return URI.create(getCSVLdbcSampleGraphPath());
}

public static String getParquetLdbcSampleGraphPath() {
return getTestData() + "/" + PARQUET_LDBC_SAMPLE_GRAPH_PATH;
}

public static URI getParquetLdbcSampleGraphURI() {
return URI.create(getParquetLdbcSampleGraphPath());
}

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