Skip to content

Commit

Permalink
Clean methods names
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Jun 5, 2024
1 parent b27252e commit c56a18f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ default void eachRow(Closure<Object> closure) throws Exception{
*
* @return A {@link Collection} containing the name of the column.
*/
Collection<String> getColumns() throws Exception;
Collection<String> getColumnNames() throws Exception;

/**
* Get all column information from the underlying table.
* Get all column name and types from the underlying table.
*
* @return A {@link Map} containing the information of the column.
*/
Map<String, String> getColumnsTypes() throws Exception;
Map<String, String> getColumnNamesTypes() throws Exception;

/**
* Get the type of the column from the underlying table.
Expand All @@ -98,7 +98,7 @@ default void eachRow(Closure<Object> closure) throws Exception{
* @return The count of columns.
*/
default int getColumnCount() throws Exception{
return getColumns().size();
return getColumnNames().size();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,13 @@ public boolean isWrapperFor(Class<?> aClass) {


@Override
public Collection<String> getColumns() {
public Collection<String> getColumnNames() {
return null;
}


@Override
public Map<String, String> getColumnsTypes() {
public Map<String, String> getColumnNamesTypes() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void addColumn(String columnName, List<Object> values) {


@Override
public Collection<String> getColumns() {
public Collection<String> getColumnNames() {
return columns.stream().map(column -> column.get(0).toString()).collect(Collectors.toList());
}

Expand Down Expand Up @@ -506,7 +506,7 @@ public Iterator<ResultSet> iterator() {


@Override
public Map<String, String> getColumnsTypes() {
public Map<String, String> getColumnNamesTypes() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public Object getObject(int column) {

@Override
public BigDecimal getBigDecimal(int column) {
return getInternalDataFrame().getDecimal(getRow(), getColumns().get(column));
return getInternalDataFrame().getDecimal(getRow(), getColumnNames().get(column));
}

@Override
Expand Down Expand Up @@ -527,12 +527,12 @@ public Stream<Tuple> stream() {
}

@Override
public List<String> getColumns() {
public List<String> getColumnNames() {
return Arrays.asList(names());
}

@Override
public Map<String, String> getColumnsTypes() throws Exception {
public Map<String, String> getColumnNamesTypes() throws Exception {
DataType[] dataTypes = types();
String[] names = names();
Map<String, String> map = new HashMap<>();
Expand Down Expand Up @@ -794,7 +794,7 @@ public List<Object> getFirstRow() {

@Override
public DataFrame columns(String... columns) {
List<String> col = new ArrayList<>(getColumns());
List<String> col = new ArrayList<>(getColumnNames());
col.removeAll(Arrays.asList(columns));
return of(drop(col.toArray(new String[0])));
}
Expand All @@ -818,7 +818,7 @@ public IBuilderResult filter(String filter, List<Object> params) {
public Map<String, Object> firstRow() {
Map<String, Object> map = new HashMap<>();
if (first()) {
for (String column : getColumns()) {
for (String column : getColumnNames()) {
map.put(column, getObject(column));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import smile.validation.Validation;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
Expand Down Expand Up @@ -314,7 +313,7 @@ void testSelect() {
}

/**
* Tests the {@link DataFrame#getColumns()}, {@link DataFrame#getColumnsTypes()},
* Tests the {@link DataFrame#getColumnNames()}, {@link DataFrame#getColumnNamesTypes()},
* {@link DataFrame#getColumnType(String)}, {@link DataFrame#getColumnCount()}
*/
@Test
Expand All @@ -327,22 +326,22 @@ void columnsTest() throws Exception {

assertNull(dataFrame.getColumnType("COL"));

assertEquals(13, dataFrame.getColumns().size());
assertTrue(dataFrame.getColumns().contains("COL1"));
assertTrue(dataFrame.getColumns().contains("COL2"));
assertTrue(dataFrame.getColumns().contains("COL3"));
assertTrue(dataFrame.getColumns().contains("COL4"));
assertTrue(dataFrame.getColumns().contains("COL5"));
assertTrue(dataFrame.getColumns().contains("COL6"));
assertTrue(dataFrame.getColumns().contains("COL7"));
assertTrue(dataFrame.getColumns().contains("COL8"));
assertTrue(dataFrame.getColumns().contains("COL9"));
assertTrue(dataFrame.getColumns().contains("COL10"));
assertTrue(dataFrame.getColumns().contains("COL11"));
assertTrue(dataFrame.getColumns().contains("COL12"));
assertTrue(dataFrame.getColumns().contains("COL13"));

assertEquals(13, dataFrame.getColumnsTypes().size());
assertEquals(13, dataFrame.getColumnNames().size());
assertTrue(dataFrame.getColumnNames().contains("COL1"));
assertTrue(dataFrame.getColumnNames().contains("COL2"));
assertTrue(dataFrame.getColumnNames().contains("COL3"));
assertTrue(dataFrame.getColumnNames().contains("COL4"));
assertTrue(dataFrame.getColumnNames().contains("COL5"));
assertTrue(dataFrame.getColumnNames().contains("COL6"));
assertTrue(dataFrame.getColumnNames().contains("COL7"));
assertTrue(dataFrame.getColumnNames().contains("COL8"));
assertTrue(dataFrame.getColumnNames().contains("COL9"));
assertTrue(dataFrame.getColumnNames().contains("COL10"));
assertTrue(dataFrame.getColumnNames().contains("COL11"));
assertTrue(dataFrame.getColumnNames().contains("COL12"));
assertTrue(dataFrame.getColumnNames().contains("COL13"));

assertEquals(13, dataFrame.getColumnNamesTypes().size());
assertEquals("int", dataFrame.getColumnType("COL1"));
assertEquals("String", dataFrame.getColumnType("COL2"));
assertEquals("boolean", dataFrame.getColumnType("COL3"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ class GroovyH2GISTest {
CREATE TABLE h2gis (id int, the_geom geometry(point));
INSERT INTO h2gis VALUES (1, 'POINT(10 10)'::GEOMETRY), (2, 'POINT(1 1)'::GEOMETRY);
""")
assertEquals("ID,THE_GEOM", h2GIS.getSpatialTable("h2gis").columns.join(","))
assertTrue(h2GIS.getSpatialTable("h2gis").columns.indexOf("THE_GEOM") != -1)
assertEquals("ID,THE_GEOM", h2GIS.getSpatialTable("h2gis").columnNames.join(","))
assertTrue(h2GIS.getSpatialTable("h2gis").columnNames.indexOf("THE_GEOM") != -1)
}

@Test
Expand Down Expand Up @@ -347,7 +347,7 @@ class GroovyH2GISTest {
h2GIS.load(h2External, '(SELECT the_geom from externalTable limit 1)', "QUERY_TABLE", true)
assertEquals(1, h2GIS.getSpatialTable("QUERY_TABLE").getRowCount())
assertEquals(1, h2GIS.getSpatialTable("QUERY_TABLE").getColumnCount())
assertEquals("THE_GEOM", h2GIS.getSpatialTable("QUERY_TABLE").getColumns().first())
assertEquals("THE_GEOM", h2GIS.getSpatialTable("QUERY_TABLE").getColumnNames().first())
}

@Test
Expand All @@ -373,7 +373,7 @@ class GroovyH2GISTest {
""")
h2GIS.save("externalTable", 'target/externalFile.shp', true)
def table = h2GIS.getTable(h2GIS.link('target/externalFile.shp', 'super', true))
assertEquals("PK,THE_GEOM,ID", table.columns.join(","))
assertEquals("PK,THE_GEOM,ID", table.columnNames.join(","))
}

@Test
Expand All @@ -389,7 +389,7 @@ class GroovyH2GISTest {
table.save('target/supersave.shp', true)
h2GIS.load('target/supersave.shp', true)
assertTrue(h2GIS.tableNames.contains("SECONDH2GIS.PUBLIC.SUPERSAVE"))
assertEquals("PK,THE_GEOM,ID", table.columns.join(","))
assertEquals("PK,THE_GEOM,ID", table.columnNames.join(","))
}

@Test
Expand Down Expand Up @@ -502,7 +502,7 @@ class GroovyH2GISTest {
insert into h2gis values (4,22, 'POINT(10 10)'::GEOMETRY);
insert into h2gis values (5,22, 'POINT(20 10)'::GEOMETRY);"""

def table = h2GIS.spatialTable "h2gis" columns "COUNT(id)", "code", "the_geom" filter "where code=22" filter "and id<5" filter "group By code" spatialTable
def table = h2GIS.getSpatialTable("h2gis").columns("COUNT(id)", "code", "the_geom").filter("where code=22 and id<5 group By code").getSpatialTable()

def values = new ArrayList<>()
table.eachRow { row ->
Expand All @@ -515,7 +515,7 @@ class GroovyH2GISTest {

values = new ArrayList<>()

h2GIS.table "h2gis" filter "where code=22" filter "or code=56" filter "order By id DESC" eachRow { row ->
h2GIS.getTable("h2gis").filter( "where code=22 or code=56 order By id DESC").eachRow { row ->
values.add row.getInt(1)
}
assertEquals(5, values.size())
Expand Down
20 changes: 10 additions & 10 deletions data/h2gis/src/test/java/org/orbisgis/data/H2gisTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void testIsTemporary() throws Exception {
}

/**
* Test the {@link JdbcTable#getColumns()} method.
* Test the {@link JdbcTable#getColumnNames()} method.
*/
@Test
void testGetColumnNames() throws Exception {
Expand All @@ -482,11 +482,11 @@ void testGetColumnNames() throws Exception {
colList.add(TableLocation.capsIdentifier(COL_ID, DBTypes.H2));
colList.add(TableLocation.capsIdentifier(COL_VALUE, DBTypes.H2));
colList.add(TableLocation.capsIdentifier(COL_MEANING, DBTypes.H2));
assertEquals(colList, getTable().getColumns());
assertEquals(colList, getLinkedTable().getColumns());
assertEquals(colList, getTempTable().getColumns());
assertEquals(colList, getEmptyTable().getColumns());
assertEquals(colList, getBuiltTable().getColumns());
assertEquals(colList, getTable().getColumnNames());
assertEquals(colList, getLinkedTable().getColumnNames());
assertEquals(colList, getTempTable().getColumnNames());
assertEquals(colList, getEmptyTable().getColumnNames());
assertEquals(colList, getBuiltTable().getColumnNames());
}

/**
Expand Down Expand Up @@ -582,15 +582,15 @@ void testGetColumnsType() throws Exception {
}

/**
* Test the {@link JdbcTable#getColumnsTypes()} method.
* Test the {@link JdbcTable#getColumnNamesTypes()} method.
*/
@Test
void testGetColumns() throws Exception {
List<JdbcTable> tables = Arrays.asList(getTable(), getEmptyTable(), getTempTable());
tables.forEach(table -> {
Map<String, String> map = null;
try {
map = table.getColumnsTypes();
map = table.getColumnNamesTypes();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -607,7 +607,7 @@ void testGetColumns() throws Exception {
});

JdbcTable table = getBuiltTable();
Map<String, String> map = table.getColumnsTypes();
Map<String, String> map = table.getColumnNamesTypes();
String[] keys = {COL_THE_GEOM, COL_THE_GEOM2.toUpperCase(), COL_ID, COL_VALUE, COL_MEANING};
String[] values = {"GEOMETRY", "GEOMETRY(POINT Z)", "INTEGER", "DOUBLE PRECISION", "CHARACTER VARYING"};
Arrays.sort(keys);
Expand All @@ -620,7 +620,7 @@ void testGetColumns() throws Exception {
assertArrayEquals(values, actualValues);

table = getLinkedTable();
map = table.getColumnsTypes();
map = table.getColumnNamesTypes();
keys = new String[]{COL_THE_GEOM, COL_THE_GEOM2.toUpperCase(), COL_ID, COL_VALUE, COL_MEANING};
values = new String[] {"GEOMETRY", "GEOMETRY(POINT Z)", "INTEGER", "DOUBLE PRECISION", "CHARACTER VARYING"};
Arrays.sort(keys);
Expand Down
8 changes: 4 additions & 4 deletions data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public boolean isTemporary() {
}

@Override
public Collection<String> getColumns() throws Exception {
public Collection<String> getColumnNames() throws Exception {
Connection con = jdbcDataSource.getConnection();
if (tableLocation == null) {
try {
Expand All @@ -284,7 +284,7 @@ public Collection<String> getColumns() throws Exception {
}

@Override
public Map<String, String> getColumnsTypes() throws Exception {
public Map<String, String> getColumnNamesTypes() throws Exception {
Map<String, String> map = new LinkedHashMap<>();
try {
ResultSet rs = getResultSetLimit(0);
Expand Down Expand Up @@ -438,7 +438,7 @@ public Map<String, Object> firstRow() throws Exception {
} catch (SQLException e) {
throw e;
}
Collection<String> columns = getColumns();
Collection<String> columns = getColumnNames();
for (String column : columns) {
try {
map.put(column, rs.getObject(column));
Expand Down Expand Up @@ -616,7 +616,7 @@ public Object asType(Class<?> clazz) throws Exception {
} else {
return this;
}
Collection<String> columnNames = getColumns();
Collection<String> columnNames = getColumnNames();
if (columnNames == null) {
printer.endTable();
return printer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ class GroovyPostGISTest {
CREATE TABLE testtable (id int, the_geom geometry(point, 0));
INSERT INTO testtable VALUES (1, 'POINT(10 10)'::GEOMETRY), (2, 'POINT(1 1)'::GEOMETRY);
""")
assertEquals("id,the_geom", postGIS.getSpatialTable("testtable").columns.join(","))
assertEquals("id,the_geom", postGIS.getSpatialTable("testtable").columnNames.join(","))
postGIS.execute "alter table testtable add column columns integer"
assertEquals("id,the_geom,columns", postGIS.getSpatialTable("testtable").getColumns().join(","))
assertEquals("id,the_geom,columns", postGIS.getSpatialTable("testtable").getColumnNames().join(","))
}

@Disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class TestProcess {
title "With database"
inputs inputA: ITable
outputs outputA: String
run { inputA -> [outputA: inputA.columns] }
run { inputA -> [outputA: inputA.getColumnNames] }
})


Expand Down

0 comments on commit c56a18f

Please sign in to comment.