Copilot commented on code in PR #780: URL: https://github.com/apache/incubator-graphar/pull/780#discussion_r2597921513
########## maven-projects/info/src/test/java/org/apache/graphar/info/MultiPropertyTest.java: ########## @@ -0,0 +1,353 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.graphar.info; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import org.apache.graphar.info.loader.GraphInfoLoader; +import org.apache.graphar.info.loader.impl.LocalFileSystemStringGraphInfoLoader; +import org.apache.graphar.info.saver.GraphInfoSaver; +import org.apache.graphar.info.saver.impl.LocalFileSystemYamlGraphSaver; +import org.apache.graphar.info.type.AdjListType; +import org.apache.graphar.info.type.Cardinality; +import org.apache.graphar.info.type.DataType; +import org.apache.graphar.info.type.FileType; +import org.apache.graphar.info.yaml.PropertyYaml; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class MultiPropertyTest extends BaseFileSystemTest { + + private String testSaveDirectory; + private GraphInfoLoader graphInfoLoader; + private GraphInfoSaver graphInfoSaver; + private Property singleProperty; + private Property listProperty; + private Property setProperty; + + @Before + public void setUp() { + testSaveDirectory = createCleanTestDirectory("ldbc_multi_property_sample/"); + graphInfoLoader = new LocalFileSystemStringGraphInfoLoader(); + graphInfoSaver = new LocalFileSystemYamlGraphSaver(); + singleProperty = + TestDataFactory.createProperty("single_email", DataType.STRING, false, true); + listProperty = + TestDataFactory.createProperty( + "list_email", DataType.STRING, Cardinality.LIST, false, true); + setProperty = + TestDataFactory.createProperty( + "set_email", DataType.STRING, Cardinality.SET, false, true); + } + + @After + public void tearDown() { + // Test data will be preserved for debugging - cleanup happens before next test run + System.out.println("Test data saved in: " + testSaveDirectory); + } + + @Test + public void testPropertyWithCardinality() { + // Test single cardinality property + Assert.assertEquals("single_email", singleProperty.getName()); + Assert.assertEquals(DataType.STRING, singleProperty.getDataType()); + Assert.assertFalse(singleProperty.isPrimary()); + Assert.assertTrue(singleProperty.isNullable()); + Assert.assertEquals(Cardinality.SINGLE, singleProperty.getCardinality()); + + // Test list cardinality property + Assert.assertEquals("list_email", listProperty.getName()); + Assert.assertEquals(DataType.STRING, listProperty.getDataType()); + Assert.assertFalse(listProperty.isPrimary()); + Assert.assertTrue(listProperty.isNullable()); + Assert.assertEquals(Cardinality.LIST, listProperty.getCardinality()); + + // Test set cardinality property + Assert.assertEquals("set_email", setProperty.getName()); + Assert.assertEquals(DataType.STRING, setProperty.getDataType()); + Assert.assertFalse(setProperty.isPrimary()); + Assert.assertTrue(setProperty.isNullable()); + Assert.assertEquals(Cardinality.SET, setProperty.getCardinality()); + } + + @Test + public void testPropertyGroupWithMultiProperties() { + // Create property group with different cardinality properties + PropertyGroup propertyGroup = + TestDataFactory.createPropertyGroup( + Arrays.asList(singleProperty, listProperty, setProperty), + FileType.PARQUET, + "emails/"); + + Assert.assertEquals(3, propertyGroup.size()); + Assert.assertEquals(FileType.PARQUET, propertyGroup.getFileType()); + Assert.assertEquals("emails/", propertyGroup.getPrefix()); + + // Test iteration over properties + int count = 0; + for (Property property : propertyGroup) { + count++; + if ("single_email".equals(property.getName())) { + Assert.assertEquals(Cardinality.SINGLE, property.getCardinality()); + } else if ("list_email".equals(property.getName())) { + Assert.assertEquals(Cardinality.LIST, property.getCardinality()); + } else if ("set_email".equals(property.getName())) { + Assert.assertEquals(Cardinality.SET, property.getCardinality()); + } + } + Assert.assertEquals(3, count); + } + + @Test + public void testPropertyYamlWithCardinality() { + // Test converting Property to PropertyYaml and back + PropertyYaml singleYaml = new PropertyYaml(singleProperty); + PropertyYaml listYaml = new PropertyYaml(listProperty); + PropertyYaml setYaml = new PropertyYaml(setProperty); + + // Check YAML representations + Assert.assertEquals("single_email", singleYaml.getName()); + Assert.assertNull(singleYaml.getCardinality()); + + Assert.assertEquals("list_email", listYaml.getName()); + Assert.assertEquals("list", listYaml.getCardinality()); + + Assert.assertEquals("set_email", setYaml.getName()); + Assert.assertEquals("set", setYaml.getCardinality()); + + // Convert back to Property objects + Property singlePropFromYaml = new Property(singleYaml); + Property listPropFromYaml = new Property(listYaml); + Property setPropFromYaml = new Property(setYaml); + + // Verify properties are correctly restored + Assert.assertEquals(singleProperty.getName(), singlePropFromYaml.getName()); + Assert.assertEquals(singleProperty.getDataType(), singlePropFromYaml.getDataType()); + Assert.assertEquals(singleProperty.getCardinality(), singlePropFromYaml.getCardinality()); + + Assert.assertEquals(listProperty.getName(), listPropFromYaml.getName()); + Assert.assertEquals(listProperty.getDataType(), listPropFromYaml.getDataType()); + Assert.assertEquals(listProperty.getCardinality(), listPropFromYaml.getCardinality()); + + Assert.assertEquals(setProperty.getName(), setPropFromYaml.getName()); + Assert.assertEquals(setProperty.getDataType(), setPropFromYaml.getDataType()); + Assert.assertEquals(setProperty.getCardinality(), setPropFromYaml.getCardinality()); + } + + @Test + public void testDefaultCardinality() { + // Test that properties created without specifying cardinality default to SINGLE + Property defaultProperty = + TestDataFactory.createProperty("default_prop", DataType.STRING, false, true); + Assert.assertEquals(Cardinality.SINGLE, defaultProperty.getCardinality()); + + // Test YAML conversion with default cardinality + PropertyYaml defaultYaml = new PropertyYaml(defaultProperty); + Assert.assertNull(defaultYaml.getCardinality()); + + Property defaultPropFromYaml = new Property(defaultYaml); + Assert.assertEquals(Cardinality.SINGLE, defaultPropFromYaml.getCardinality()); + } + + @Test + public void testInvalidCardinalityHandling() { + // Test handling of invalid cardinality in YAML + PropertyYaml invalidYaml = new PropertyYaml(); + invalidYaml.setName("invalid_prop"); + invalidYaml.setData_type("string"); + invalidYaml.setCardinality("INVALID"); // This should throw an IllegalArgumentException + IllegalArgumentException illegalArgumentException = + Assert.assertThrows( + IllegalArgumentException.class, () -> new Property(invalidYaml)); + Assert.assertEquals("Unknown cardinality: INVALID", illegalArgumentException.getMessage()); + } + + @Test + public void testEdgeInfoWithMultiProperty() throws IOException { + Property weights = + TestDataFactory.createProperty( + "weights", DataType.DOUBLE, Cardinality.LIST, false, true); + PropertyGroup weights_pg = + TestDataFactory.createPropertyGroup( + Arrays.asList(weights), FileType.CSV, "weights/"); Review Comment: Variable name `weights_pg` uses snake_case, which is inconsistent with Java naming conventions. Consider renaming to `weightsPg` or `weightsPropertyGroup` to match the camelCase pattern used elsewhere in the codebase (e.g., `csvGroup`, `parquetGroup` in PropertyGroupTest.java). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
