src/main/java/de/cimt/talendcomp/exasol/EXASCDHelper.java
String createSCD1Statement(String source, String target, boolean currentOnly) {
		if (!containsSCDType("scd1")) {
			return null;
		}
		if (enabledSCD2Versioning && containsSCDType("scd2")) {
			// with versioning enabled
			String scd1Type = currentOnly ? "scd1a" : "scd1b";
			StringBuilder sb = new StringBuilder();
			sb.append("merge into " + target + " ta using (\n");
			sb.append("SELECT " + validTimePeriodStartColumn + ", ");
			if (currentOnly) {
				sb.append(getCslSourceString(true, true, false, false, false) + "\n");
			} else {
				sb.append(getCslSourceString(true, false, true, false, false) + "\n");

			}
			sb.append("FROM " + source);
			if (currentOnly) {
				sb.append(" WHERE (" + statusInTempTableColumn + " != 'CHANGED' and " + statusInTempTableColumn
						+ " != 'NEW' and " + statusInTempTableColumn + " != 'OLD')");
			} else {
				sb.append(" WHERE (" + statusInTempTableColumn + " != 'NEW' and " + statusInTempTableColumn
						+ " != 'OLD')");
			}
			sb.append(") sr\n");
			sb.append("on " + getKeyClause("sr", "ta"));
			if (currentOnly) {
				sb.append(" and ta." + validTimePeriodEndColumn + "=" + scdEndDateStr);
			}
			sb.append(" when matched then update set " + getSetValuesClause("ta", "sr", scd1Type));
			sb.append(" where (" + getCompareColumnsClause("ta", "sr", scd1Type) + ")");
			String sql = sb.toString();
			if (debug) {
				System.out.println("-- createSCD1Statement");
				System.out.println(sql + ";");
			}
			return sql;
		} else {
			// no versioning (simple upsert)
			StringBuilder sb = new StringBuilder();
			sb.append("merge into " + target + " ta");
			sb.append(" using (select " + getCslSourceString(false) + " from " + source);
			sb.append(") sr\n");
			sb.append(" on " + getKeyClause("sr", "ta") + "\n");
			sb.append(" when not matched then insert (" + getCslTargetString(false) + ")");
			sb.append(" values(" + getCslSourceString(true) + ")");
			sb.append(" when matched then update set " + getSetValuesClause("ta", "sr", "scd1"));
			sb.append(" where " + getCompareColumnsClause("ta", "sr", "scd1"));
			String sql = sb.toString();
			if (debug) {
				System.out.println("-- createSCD1Statement");
				System.out.println(sql + ";");
			}
			return sql;
		}
	}
/*
	 * Create statement for SCD type 1 data processing. If (and only if) SCD 2 is enabled the additional status column
	 * is used.
	 */
Create statement for SCD type 1 data processing. If (and only if) SCD 2 is enabled the additional status column
is used.
Create statement for SCD type 1 data processing . If ( and only if ) SCD 2 is enabled the additional status column is used .
String createSCD1Statement(String source, String target, boolean currentOnly) {
		if (!containsSCDType("scd1")) {
			return null;
		}
		if (enabledSCD2Versioning && containsSCDType("scd2")) {
			String scd1Type = currentOnly ? "scd1a" : "scd1b";
			StringBuilder sb = new StringBuilder();
			sb.append("merge into " + target + " ta using (\n");
			sb.append("SELECT " + validTimePeriodStartColumn + ", ");
			if (currentOnly) {
				sb.append(getCslSourceString(true, true, false, false, false) + "\n");
			} else {
				sb.append(getCslSourceString(true, false, true, false, false) + "\n");
			}
			sb.append("FROM " + source);
			if (currentOnly) {
				sb.append(" WHERE (" + statusInTempTableColumn + " != 'CHANGED' and " + statusInTempTableColumn
						+ " != 'NEW' and " + statusInTempTableColumn + " != 'OLD')");
			} else {
				sb.append(" WHERE (" + statusInTempTableColumn + " != 'NEW' and " + statusInTempTableColumn
						+ " != 'OLD')");
			}
			sb.append(") sr\n");
			sb.append("on " + getKeyClause("sr", "ta"));
			if (currentOnly) {
				sb.append(" and ta." + validTimePeriodEndColumn + "=" + scdEndDateStr);
			}
			sb.append(" when matched then update set " + getSetValuesClause("ta", "sr", scd1Type));
			sb.append(" where (" + getCompareColumnsClause("ta", "sr", scd1Type) + ")");
			String sql = sb.toString();
			if (debug) {
				System.out.println("-- createSCD1Statement");
				System.out.println(sql + ";");
			}
			return sql;
		} else {
			StringBuilder sb = new StringBuilder();
			sb.append("merge into " + target + " ta");
			sb.append(" using (select " + getCslSourceString(false) + " from " + source);
			sb.append(") sr\n");
			sb.append(" on " + getKeyClause("sr", "ta") + "\n");
			sb.append(" when not matched then insert (" + getCslTargetString(false) + ")");
			sb.append(" values(" + getCslSourceString(true) + ")");
			sb.append(" when matched then update set " + getSetValuesClause("ta", "sr", "scd1"));
			sb.append(" where " + getCompareColumnsClause("ta", "sr", "scd1"));
			String sql = sb.toString();
			if (debug) {
				System.out.println("-- createSCD1Statement");
				System.out.println(sql + ";");
			}
			return sql;
		}
	}
String createSCD1Statement ( String source , String target , boolean currentOnly ) { if ( ! containsSCDType ( "scd1" ) ) { return null ; } if ( enabledSCD2Versioning && containsSCDType ( "scd2" ) ) { String scd1Type = currentOnly ? "scd1a" : "scd1b" ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "merge into " + target + " ta using (\n" ) ; sb . append ( "SELECT " + validTimePeriodStartColumn + ", " ) ; if ( currentOnly ) { sb . append ( getCslSourceString ( true , true , false , false , false ) + "\n" ) ; } else { sb . append ( getCslSourceString ( true , false , true , false , false ) + "\n" ) ; } sb . append ( "FROM " + source ) ; if ( currentOnly ) { sb . append ( " WHERE (" + statusInTempTableColumn + " != 'CHANGED' and " + statusInTempTableColumn + " != 'NEW' and " + statusInTempTableColumn + " != 'OLD')" ) ; } else { sb . append ( " WHERE (" + statusInTempTableColumn + " != 'NEW' and " + statusInTempTableColumn + " != 'OLD')" ) ; } sb . append ( ") sr\n" ) ; sb . append ( "on " + getKeyClause ( "sr" , "ta" ) ) ; if ( currentOnly ) { sb . append ( " and ta." + validTimePeriodEndColumn + "=" + scdEndDateStr ) ; } sb . append ( " when matched then update set " + getSetValuesClause ( "ta" , "sr" , scd1Type ) ) ; sb . append ( " where (" + getCompareColumnsClause ( "ta" , "sr" , scd1Type ) + ")" ) ; String sql = sb . toString ( ) ; if ( debug ) { System . out . println ( "-- createSCD1Statement" ) ; System . out . println ( sql + ";" ) ; } return sql ; } else { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "merge into " + target + " ta" ) ; sb . append ( " using (select " + getCslSourceString ( false ) + " from " + source ) ; sb . append ( ") sr\n" ) ; sb . append ( " on " + getKeyClause ( "sr" , "ta" ) + "\n" ) ; sb . append ( " when not matched then insert (" + getCslTargetString ( false ) + ")" ) ; sb . append ( " values(" + getCslSourceString ( true ) + ")" ) ; sb . append ( " when matched then update set " + getSetValuesClause ( "ta" , "sr" , "scd1" ) ) ; sb . append ( " where " + getCompareColumnsClause ( "ta" , "sr" , "scd1" ) ) ; String sql = sb . toString ( ) ; if ( debug ) { System . out . println ( "-- createSCD1Statement" ) ; System . out . println ( sql + ";" ) ; } return sql ; } }
Create statement for SCD type 1 data processing.
Create statement for SCD type 1 data processing .
// with versioning enabled // no versioning (simple upsert)