Commit bbe056de authored by COTONNEC's avatar COTONNEC
Browse files

Merge branch 'feature/pgsql_extractions' into develop

# Conflicts:
#	sumaris-core/src/main/java/net/sumaris/core/dao/administration/user/PersonSpecifications.java
#	sumaris-core/src/main/java/net/sumaris/core/dao/data/VesselDaoImpl.java
#	sumaris-core/src/main/java/net/sumaris/core/dao/data/VesselSnapshotDaoImpl.java
#	sumaris-core/src/main/java/net/sumaris/core/dao/referential/ReferentialSpecifications.java
parents dc654175 d90b6cd2
......@@ -125,10 +125,10 @@ public class Daos extends net.sumaris.core.dao.technical.Daos {
}
public static void commitIfHsqldb(DataSource dataSource) {
public static void commitIfHsqldbOrPgsql(DataSource dataSource) {
Connection conn = DataSourceUtils.getConnection(dataSource);
try {
if (net.sumaris.core.extraction.dao.technical.Daos.isHsqlDatabase(conn) && DataSourceUtils.isConnectionTransactional(conn, dataSource)) {
if ((net.sumaris.core.extraction.dao.technical.Daos.isHsqlDatabase(conn) || net.sumaris.core.extraction.dao.technical.Daos.isPostgresqlDatabase(conn)) && DataSourceUtils.isConnectionTransactional(conn, dataSource)) {
try {
conn.commit();
} catch (SQLException e) {
......@@ -146,7 +146,7 @@ public class Daos extends net.sumaris.core.dao.technical.Daos {
* @param columnNamesMapping
* @return
*/
public static String sqlReplaceColumnNames(String sqlQuery, Map<String, String> columnNamesMapping) {
public static String sqlReplaceColumnNames(String sqlQuery, Map<String, String> columnNamesMapping, Boolean lowercase) {
if (MapUtils.isEmpty(columnNamesMapping)) return sqlQuery; // Skip
sqlQuery = sqlQuery.toUpperCase();
......@@ -161,6 +161,20 @@ public class Daos extends net.sumaris.core.dao.technical.Daos {
"$1" + targetColumnName + "$2");
}
// for postgresql, lowercase queries are needed.
if (lowercase){
sqlQuery = sqlQuery.toLowerCase();
}
return sqlQuery;
}
/**
* Do column names replacement, but escape sql keyword (e.g. 'DATE' replacement will keep TO_DATE(...) unchanged)
* @param sqlQuery
* @param columnNamesMapping
* @return
*/
public static String sqlReplaceColumnNames(String sqlQuery, Map<String, String> columnNamesMapping) {
return sqlReplaceColumnNames(sqlQuery, columnNamesMapping, false);
}
}
......@@ -41,12 +41,9 @@ import net.sumaris.core.service.referential.ReferentialService;
import net.sumaris.core.util.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.hibernate.dialect.Dialect;
import org.hibernate.query.internal.NativeQueryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.orm.hibernate5.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import javax.annotation.PostConstruct;
import javax.persistence.Query;
......@@ -184,7 +181,7 @@ public abstract class ExtractionBaseDaoImpl extends HibernateDaoSupport {
xmlQuery.setXSLFileName(XSL_ORACLE_FILENAME);
}
else if (this.databaseType == DatabaseType.postgresql){
xmlQuery.setLowercaseAliases(true);
xmlQuery.setLowercase(true);
}
return xmlQuery;
}
......
......@@ -49,18 +49,18 @@ public class XMLQuery extends HSQLDBSingleXMLQuery {
private String xslFileName;
private boolean lowercaseAliases;
private boolean lowercase;
public XMLQuery() {
super();
xslFileName = super.getXSLFileName();
this.lowercaseAliases = false;
this.lowercase = false;
}
public XMLQuery(boolean lowercaseAliases) {
public XMLQuery(boolean lowercase) {
super();
xslFileName = super.getXSLFileName();
this.lowercaseAliases = lowercaseAliases;
this.lowercase = lowercase;
}
@Override
......@@ -74,12 +74,12 @@ public class XMLQuery extends HSQLDBSingleXMLQuery {
// let default values here for HSQLDB
public boolean isLowercaseAliases() {
return lowercaseAliases;
public boolean isLowercase() {
return lowercase;
}
public void setLowercaseAliases(boolean lowercaseAliases) {
this.lowercaseAliases = lowercaseAliases;
public void setLowercase(boolean lowercase) {
this.lowercase = lowercase;
}
/**
......@@ -155,7 +155,7 @@ public class XMLQuery extends HSQLDBSingleXMLQuery {
public String getSQLQueryAsString(){
String query = super.getSQLQueryAsString();
if (this.lowercaseAliases){
if (this.lowercase){
query = query.toLowerCase();
}
return query;
......
......@@ -196,7 +196,7 @@ public class SumarisTableMetadatas {
StringBuilder sb = new StringBuilder();
sb.append("SELECT COUNT(*) FROM (")
.append(getSelectGroupByQuery(tableName, columnNames, whereClause, groupByColumnNames, null, null))
.append(")");
.append(") \"select_group\"");
return sb.toString();
}
......
......@@ -23,6 +23,7 @@
package net.sumaris.core.extraction.dao.trip.free;
import com.google.common.base.Preconditions;
import net.sumaris.core.dao.technical.DatabaseType;
import net.sumaris.core.extraction.dao.technical.Daos;
import net.sumaris.core.extraction.dao.technical.XMLQuery;
import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl;
......@@ -99,6 +100,10 @@ public class ExtractionFree1TripDaoImpl<C extends ExtractionRdbTripContextVO, F
// WIDTH_GEAR Largeur cumulée (drague), missing in SUMARIS
// SEINE_LENGTH Longueur de la bolinche ou senne missing in SUMARIS
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery;
}
......
......@@ -24,6 +24,7 @@ package net.sumaris.core.extraction.dao.trip.free2;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.dao.technical.DatabaseType;
import net.sumaris.core.dao.technical.schema.SumarisDatabaseMetadata;
import net.sumaris.core.extraction.dao.technical.Daos;
import net.sumaris.core.extraction.dao.technical.XMLQuery;
......@@ -195,6 +196,10 @@ public class ExtractionFree2TripDaoImpl<C extends ExtractionFree2ContextVO, F ex
xmlQuery.setGroup("vesselFilter", CollectionUtils.isNotEmpty(context.getVesselIds()));
xmlQuery.bind("vesselIds", Daos.getSqlInNumbers(context.getVesselIds()));
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
return xmlQuery;
}
......
......@@ -375,6 +375,7 @@ public class AggregationRdbTripDaoImpl<
xmlQuery.setGroup("gearType", rawStationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery;
......@@ -532,6 +533,7 @@ public class AggregationRdbTripDaoImpl<
// Enable/Disable group, on DBMS
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
// Enable/Disable group, on optional columns
......@@ -708,9 +710,11 @@ public class AggregationRdbTripDaoImpl<
// Enable/Disable group, on DBMS
xmlQuery.setGroup("hasId", hasId);
xmlQuery.setGroup("hsqldb-hasId", hasId && this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql-hasId", hasId && this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle-hasId", hasId && this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hasSampleIds", hasSampleIds);
xmlQuery.setGroup("hsqldb-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.oracle);
return xmlQuery;
......@@ -789,7 +793,7 @@ public class AggregationRdbTripDaoImpl<
String sqlQuery = xmlQuery.getSQLQueryAsString();
// Do column nanes replacement (e.g. see FREE extraction)
sqlQuery = Daos.sqlReplaceColumnNames(sqlQuery, context.getColumnNamesMapping());
sqlQuery = Daos.sqlReplaceColumnNames(sqlQuery, context.getColumnNamesMapping(), xmlQuery.isLowercase());
return queryUpdate(sqlQuery);
}
......@@ -868,7 +872,8 @@ public class AggregationRdbTripDaoImpl<
c -> query(
Daos.sqlReplaceColumnNames(
String.format("SELECT DISTINCT %s FROM %s where %s IS NOT NULL", c, tableName, c),
context.getColumnNamesMapping()),
context.getColumnNamesMapping(),
xmlQuery.isLowercase()),
Object.class)
.stream()
.map(String::valueOf)
......
......@@ -299,6 +299,10 @@ public class ExtractionRdbTripDaoImpl<C extends ExtractionRdbTripContextVO, F ex
xmlQuery.setGroup("vesselFilter", CollectionUtils.isNotEmpty(context.getVesselIds()));
xmlQuery.bind("vesselIds", Daos.getSqlInNumbers(context.getVesselIds()));
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
return xmlQuery;
}
......@@ -424,6 +428,7 @@ public class ExtractionRdbTripDaoImpl<C extends ExtractionRdbTripContextVO, F ex
xmlQuery.bind("speciesListTableName", context.getSpeciesListTableName());
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
return xmlQuery;
......
......@@ -198,6 +198,7 @@ public class AggregationSurvivalTestDaoImpl<C extends AggregationSurvivalTestCon
xmlQuery.setGroup("gearType", stationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery;
......@@ -264,6 +265,7 @@ public class AggregationSurvivalTestDaoImpl<C extends AggregationSurvivalTestCon
xmlQuery.setGroup("gearType", stationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery;
......
......@@ -24,6 +24,7 @@ package net.sumaris.core.extraction.dao.trip.survivalTest;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.dao.technical.DatabaseType;
import net.sumaris.core.extraction.dao.technical.XMLQuery;
import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl;
import net.sumaris.core.extraction.format.LiveFormatEnum;
......@@ -133,6 +134,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte
xmlQuery.bind("sortingDateTimePmfmId", String.valueOf(PmfmEnum.SORTING_START_DATE_TIME.getId()));
xmlQuery.bind("sortingEndDateTimePmfmId", String.valueOf(PmfmEnum.SORTING_END_DATE_TIME.getId()));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery;
}
......@@ -180,6 +185,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte
xmlQuery.bind("stationTableName", context.getStationTableName());
xmlQuery.bind("survivalTestTableName", context.getSurvivalTestTableName());
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
// aggregate insertion
execute(xmlQuery);
long count = countFrom(context.getSurvivalTestTableName());
......@@ -210,6 +219,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte
xmlQuery.bind("stationTableName", context.getStationTableName());
xmlQuery.bind("releaseTableName", context.getReleaseTableName());
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
// aggregate insertion
execute(xmlQuery);
long count = countFrom(context.getReleaseTableName());
......
......@@ -280,6 +280,7 @@ public class AggregationServiceImpl implements AggregationService {
int offset, int size, String sort, SortDirection direction) {
// Execute the aggregation
AggregationContextVO context = aggregate(type, filter, strata);
Daos.commitIfHsqldbOrPgsql(dataSource);
// Prepare the read filter
ExtractionFilterVO readFilter = null;
......@@ -301,7 +302,7 @@ public class AggregationServiceImpl implements AggregationService {
public File executeAndDump(AggregationTypeVO type, @Nullable ExtractionFilterVO filter, @Nullable AggregationStrataVO strata) {
// Execute the aggregation
AggregationContextVO context = aggregate(type, filter, strata);
Daos.commitIfHsqldb(dataSource);
Daos.commitIfHsqldbOrPgsql(dataSource);
try {
// Dump to files
......@@ -309,7 +310,7 @@ public class AggregationServiceImpl implements AggregationService {
}
finally {
// Delete aggregation tables, after dump
clean(context, true);
clean(context);
}
}
......
......@@ -551,7 +551,7 @@ public class ExtractionServiceImpl implements ExtractionService {
@Override
public CompletableFuture<Boolean> asyncClean(ExtractionContextVO context) {
try {
clean(context);
clean(context, true);
return CompletableFuture.completedFuture(Boolean.TRUE);
} catch (Exception e) {
log.warn(String.format("Error while cleaning extraction #%s: %s", context.getId(), e.getMessage()), e);
......@@ -622,7 +622,7 @@ public class ExtractionServiceImpl implements ExtractionService {
// Execute live extraction to temp tables
ExtractionContextVO context = executeLiveDao(format, filter);
Daos.commitIfHsqldb(dataSource);
Daos.commitIfHsqldbOrPgsql(dataSource);
try {
log.info(String.format("Dumping tables of extraction #%s to files...", context.getId()));
......@@ -631,7 +631,7 @@ public class ExtractionServiceImpl implements ExtractionService {
return dumpTablesToFile(context, null /*no filter, because already applied*/);
}
finally {
clean(context, true);
clean(context);
}
}
......
......@@ -25,10 +25,9 @@
<query type="create" temp="false" table="&amp;landingTableName">
<!-- PK -->
<select alias="RECORD_TYPE" type="text">'CL'</select>
<select alias="RECORD_TYPE" type="text">UPPER('CL')</select>
<select alias="VESSEL_FLAG_COUNTRY" type="text">VESSEL_FLAG_COUNTRY</select>
<select alias="LANDING_COUNTRY" type="text">LANDING_COUNTRY</select>
<!-- <select alias="SPECIES" type="text">MIN(DECODE(TG.LABEL, NULL, CL.SPECIES, TG.LABEL || ' - ' || TG.NAME))</select>-->
<select alias="SPECIES" type="text">MIN(CASE TG.LABEL WHEN NULL THEN CL.SPECIES ELSE TG.LABEL || ' - ' || TG.NAME END)</select>
<select alias="LANDING_CATEGORY" type="text">LANDING_CATEGORY</select>
<select alias="COMMERCIAL_SIZE_CATEGORY_SCALE" type="text">COMMERCIAL_SIZE_CATEGORY_SCALE</select>
......
......@@ -24,7 +24,7 @@
<query type="create" temp="false" table="&amp;speciesLengthTableName">
<select alias="RECORD_TYPE" type="text">'HL'</select>
<select alias="RECORD_TYPE" type="text">UPPER('HL')</select>
<!-- PK inherited from HH -->
<select alias="SAMPLING_TYPE" type="text">SL.SAMPLING_TYPE</select>
......@@ -63,13 +63,13 @@
<from alias="SL" >&amp;speciesListTableName</from>
<from group="hsqldb-hasId"><![CDATA[
<from group="hsqldb-hasId,pgsql-hasId"><![CDATA[
UNNEST(SL.IDS) WITH ORDINALITY COORDS(SL_ID, POS)
INNER JOIN &speciesLengthMapTableName SL2HL on SL2HL.SL_ID = SL_ID
INNER JOIN &rawSpeciesLengthTableName HL on HL.ID = SL2HL.HL_ID
]]></from>
<from group="hsqldb-hasSampleIds"><![CDATA[
<from group="hsqldb-hasSampleIds,pgsql-hasSampleIds"><![CDATA[
UNNEST(SL.SAMPLE_IDS) WITH ORDINALITY COORDS(SAMPLE_ID, POS)
INNER JOIN &rawSpeciesLengthTableName HL on HL.SAMPLE_ID = SAMPLE_ID
]]></from>
......@@ -105,4 +105,4 @@
<groupby group="lengthClass">LENGTH_CLASS</groupby>
</query>
</queries>
\ No newline at end of file
</queries>
......@@ -25,7 +25,7 @@
<query type="create" temp="false" table="&amp;speciesListTableName" option="distinct">
<!-- PK (inherited from station) -->
<select alias="RECORD_TYPE" type="text">'SL'</select>
<select alias="RECORD_TYPE" type="text">UPPER('SL')</select>
<select alias="SAMPLING_TYPE" type="text">S.SAMPLING_TYPE</select>
<select alias="LANDING_COUNTRY" type="text">S.LANDING_COUNTRY</select>
<select alias="VESSEL_FLAG_COUNTRY" type="text">S.VESSEL_FLAG_COUNTRY</select>
......@@ -45,7 +45,7 @@
<select alias="GEAR_TYPE" group="gearType" type="text">S.GEAR_TYPE</select>
<!-- Unique identifier for station, to be able to link HL children rows -->
<select alias="STATION_NUMBER" group="hsqldb" type="number">ABS(F_HASH_CODE(SL.TRIP_CODE || '-' || SL.STATION_NUMBER))</select>
<select alias="STATION_NUMBER" group="hsqldb,pgsql" type="number">ABS(F_HASH_CODE(SL.TRIP_CODE || '-' || SL.STATION_NUMBER))</select>
<select alias="STATION_NUMBER" group="oracle" type="number">ORA_HASH(SL.TRIP_CODE || '-' || SL.STATION_NUMBER)</select>
<!-- SL fields -->
......@@ -77,6 +77,10 @@
UNNEST(S.TRIP_CODES, S.STATION_NUMBERS) WITH ORDINALITY COORDS(TRIP_CODE, STATION_NUMBER, POS)
INNER JOIN &rawSpeciesListTableName SL on SL.TRIP_CODE = TRIP_CODE and SL.STATION_NUMBER = STATION_NUMBER
]]></from>
<from group="pgsql"><![CDATA[
UNNEST(S.TRIP_CODES, S.STATION_NUMBERS) WITH ORDINALITY COORDS(T_CODE, S_NUMBER, POS)
INNER JOIN &rawSpeciesListTableName SL on SL.TRIP_CODE = T_CODE and SL.STATION_NUMBER = S_NUMBER
]]></from>
<from group="oracle"><![CDATA[
TABLE(SPLIT(S.STATION_NUMBERS, ',')) STATION_NUMBER
INNER JOIN &rawSpeciesListTableName SL on SL.STATION_NUMBER = STATION_NUMBER.COLUMN_VALUE
......
......@@ -52,7 +52,7 @@
</with>
<!-- PK -->
<select alias="RECORD_TYPE" type="text">'HH'</select>
<select alias="RECORD_TYPE" type="text">UPPER('HH')</select>
<select alias="SAMPLING_TYPE" type="text">S.SAMPLING_TYPE</select>
<select alias="LANDING_COUNTRY" type="text">S.LANDING_COUNTRY</select>
<select alias="VESSEL_FLAG_COUNTRY" type="text">S.VESSEL_FLAG_COUNTRY</select>
......@@ -82,8 +82,8 @@
<select alias="FISHING_TIME" type="number">SUM(S.FISHING_TIME)</select>
<select alias="STATION_COUNT" type="number">COUNT(DISTINCT S.STATION_NUMBER)</select>
<select alias="TRIP_COUNT_BY_STATION" type="number">CAST(COUNT(DISTINCT S.TRIP_CODE) AS DOUBLE) * COUNT(DISTINCT S.STATION_NUMBER) / AVG(T.NUMBER_OF_SETS)</select>
<select alias="TRIP_COUNT_BY_FISHING_TIME" type="number">CAST(COUNT(DISTINCT T.TRIP_CODE) AS DOUBLE) * SUM(S.FISHING_TIME) / AVG(T.FISHING_TIME)</select>
<select alias="TRIP_COUNT_BY_STATION" type="number">CASE AVG(T.NUMBER_OF_SETS) WHEN 0 THEN AVG(T.NUMBER_OF_SETS) ELSE CAST(COUNT(DISTINCT S.TRIP_CODE) AS DECIMAL) * COUNT(DISTINCT S.STATION_NUMBER) / AVG(T.NUMBER_OF_SETS) END</select>
<select alias="TRIP_COUNT_BY_FISHING_TIME" type="number">CASE AVG(T.FISHING_TIME) WHEN 0 THEN AVG(T.FISHING_TIME) ELSE CAST(COUNT(DISTINCT T.TRIP_CODE) AS DECIMAL) * SUM(S.FISHING_TIME) / AVG(T.FISHING_TIME) END</select>
<!-- for debug on TRIP_COUNT_* computation
<select alias="TRIP_COUNT_RAW" type="number">COUNT(DISTINCT S.TRIP_CODE)</select>
......@@ -92,9 +92,9 @@
<!-- Hidden field (use min trip/station as identifier) -->
<select alias="TRIP_CODES" group="hsqldb" type="hidden">ARRAY_AGG(S.TRIP_CODE)</select>
<select alias="TRIP_CODES" group="hsqldb,pgsql" type="hidden">ARRAY_AGG(S.TRIP_CODE)</select>
<select alias="TRIP_CODES" group="oracle" type="hidden">LISTAGG(S.TRIP_CODE, ',')</select>
<select alias="STATION_NUMBERS" group="hsqldb" type="hidden">ARRAY_AGG(S.STATION_NUMBER)</select>
<select alias="STATION_NUMBERS" group="hsqldb,pgsql" type="hidden">ARRAY_AGG(S.STATION_NUMBER)</select>
<select alias="STATION_NUMBERS" group="oracle" type="hidden">LISTAGG(S.STATION_NUMBER, ',')</select>
<from alias="S">&amp;rawStationTableName</from>
......@@ -102,7 +102,7 @@
<where>1=1</where>
<where operator="AND" group="excludeInvalidStation"><![CDATA[S.FISHING_VALIDITY != 'I' OR S.FISHING_VALIDITY IS NULL]]></where>
<where operator="AND" group="excludeInvalidStation"><![CDATA[S.FISHING_VALIDITY != UPPER('I') OR S.FISHING_VALIDITY IS NULL]]></where>
<where operator="AND" group="programFilter">
<in field="S.PROJECT">&amp;progLabels</in>
......
......@@ -24,7 +24,7 @@
<query type="create" temp="false" table="&amp;releaseTableName">
<select alias="RECORD_TYPE" type="text">'RL'</select>
<select alias="RECORD_TYPE" type="text">UPPER('RL')</select>
<!-- PK -->
<select alias="SAMPLING_TYPE" type="text">S.SAMPLING_TYPE</select>
......@@ -47,7 +47,7 @@
<select alias="GEAR_TYPE" group="gearType" type="text">S.GEAR_TYPE</select>
<!-- Unique identifier for station -->
<select alias="STATION_NUMBER" group="hsqldb" type="number">ABS(F_HASH_CODE(RL.TRIP_CODE || '-' || RL.STATION_NUMBER))</select>
<select alias="STATION_NUMBER" group="hsqldb,pgsql" type="number">ABS(F_HASH_CODE(RL.TRIP_CODE || '-' || RL.STATION_NUMBER))</select>
<select alias="STATION_NUMBER" group="oracle" type="number">ORA_HASH(RL.TRIP_CODE || '-' || RL.STATION_NUMBER)</select>
<!-- hidden column -->
......@@ -68,6 +68,10 @@
UNNEST(S.TRIP_CODES, S.STATION_NUMBERS) WITH ORDINALITY COORDS(TRIP_CODE, STATION_NUMBER, POS)
INNER JOIN &rawReleaseTableName RL on RL.TRIP_CODE = TRIP_CODE and RL.STATION_NUMBER = STATION_NUMBER
]]></from>
<from group="pgsql"><![CDATA[
UNNEST(S.TRIP_CODES, S.STATION_NUMBERS) WITH ORDINALITY COORDS(T_CODE, S_NUMBER, POS)
INNER JOIN &rawReleaseTableName RL on RL.TRIP_CODE = T_CODE and RL.STATION_NUMBER = S_NUMBER
]]></from>
<from group="oracle"><![CDATA[
TABLE(SPLIT(S.STATION_NUMBERS, ',')) STATION_NUMBER
INNER JOIN &rawReleaseTableName RL on RL.STATION_NUMBER = STATION_NUMBER.COLUMN_VALUE
......@@ -75,4 +79,4 @@
</query>
</queries>
\ No newline at end of file
</queries>
......@@ -25,7 +25,7 @@
<query type="create" temp="false" table="&amp;survivalTestTableName">
<select alias="RECORD_TYPE" type="text">'ST'</select>
<select alias="RECORD_TYPE" type="text">UPPER('ST')</select>
<!-- PK (inherited) -->
<select alias="SAMPLING_TYPE" type="text">S.SAMPLING_TYPE</select>
......@@ -48,7 +48,7 @@
<select alias="GEAR_TYPE" group="gearType" type="text">S.GEAR_TYPE</select>
<!-- Unique identifier for station -->
<select alias="STATION_NUMBER" group="hsqldb" type="number">ABS(F_HASH_CODE(ST.TRIP_CODE || '-' || ST.STATION_NUMBER))</select>
<select alias="STATION_NUMBER" group="hsqldb,pgsql" type="number">ABS(F_HASH_CODE(ST.TRIP_CODE || '-' || ST.STATION_NUMBER))</select>
<select alias="STATION_NUMBER" group="oracle" type="number">ORA_HASH(ST.TRIP_CODE || '-' || ST.STATION_NUMBER)</select>
<!-- hidden column -->
......@@ -93,10 +93,14 @@
UNNEST(S.TRIP_CODES, S.STATION_NUMBERS) WITH ORDINALITY COORDS(TRIP_CODE, STATION_NUMBER, POS)
INNER JOIN &rawSurvivalTestTableName ST on ST.TRIP_CODE = TRIP_CODE and ST.STATION_NUMBER = STATION_NUMBER
]]></from>
<from group="pgsql"><![CDATA[
UNNEST(S.TRIP_CODES, S.STATION_NUMBERS) WITH ORDINALITY COORDS(T_CODE, S_NUMBER, POS)
INNER JOIN &rawSurvivalTestTableName ST on ST.TRIP_CODE = T_CODE and ST.STATION_NUMBER = S_NUMBER
]]></from>
<from group="oracle"><![CDATA[
TABLE(SPLIT(S.STATION_NUMBERS, ',')) STATION_NUMBER
INNER JOIN &rawSurvivalTestTableName ST on ST.STATION_NUMBER = STATION_NUMBER.COLUMN_VALUE
]]></from>
</query>
</queries>
\ No newline at end of file
</queries>
......@@ -31,7 +31,7 @@
FROM BATCH BL
WHERE
BL.PARENT_BATCH_FK=SL.SAMPLE_ID
AND BL.LABEL like 'SORTING_BATCH_INDIVIDUAL#%'
AND BL.LABEL like UPPER('SORTING_BATCH_INDIVIDUAL#%')
) END)</select>
<groupby>NUMBER_INDIVIDUAL</groupby>
......
......@@ -15,24 +15,24 @@
<!-- other fields -->
<select alias="PARAMETER_FK" type="text"><![CDATA[
(CASE P.LABEL
WHEN 'SMALLER_MESH_GAUGE' THEN 'GEAR_LEGAL_MESH_SIZE'
WHEN 'HEADLINE_CUMULATIVE_LENGTH' THEN 'HEADLINE_LENGTH'
WHEN 'WING_LINE_FORM' THEN 'WING_LINE_CARAC'
WHEN 'SELECTIVE_DEVICE' THEN 'SELECTIVE_DEVICE_1'
WHEN UPPER('SMALLER_MESH_GAUGE') THEN UPPER('GEAR_LEGAL_MESH_SIZE')
WHEN UPPER('HEADLINE_CUMULATIVE_LENGTH') THEN UPPER('HEADLINE_LENGTH')
WHEN UPPER('WING_LINE_FORM') THEN UPPER('WING_LINE_CARAC')
WHEN UPPER('SELECTIVE_DEVICE') THEN UPPER('SELECTIVE_DEVICE_1')
ELSE P.LABEL
END)
]]></select>
<select alias="NAME" type="text">P.NAME</select>
<select alias="NUMERICAL_VALUE" type="number">CASE P.IS_BOOLEAN WHEN TRUE THEN null ELSE PGM.NUMERICAL_VALUE END)</select>
<select alias="NUMERICAL_VALUE" type="number">CASE P.IS_BOOLEAN WHEN TRUE THEN null ELSE PGM.NUMERICAL_VALUE END</select>
<select alias="QUALITATIVE_VALUE_NAME" type="number"><![CDATA[
CASE
WHEN (P.IS_BOOLEAN AND PGM.NUMERICAL_VALUE = 1) THEN 'Oui'
WHEN (P.IS_BOOLEAN AND PGM.NUMERICAL_VALUE = 0) THEN 'Non'
WHEN (P.LABEL = 'WING_LINE_FORM') THEN QV.NAME
WHEN (P.LABEL = UPPER('WING_LINE_FORM')) THEN QV.NAME
ELSE COALESCE(QV.LABEL, QV.NAME)
END
]]></select>
<select alias="CHARACTERISTICS" type="text">'PH'</select>
<select alias="CHARACTERISTICS" type="text">UPPER('PH')</select>