Skip to content
Closed
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
1 change: 1 addition & 0 deletions docs/Salesforce-batchsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ PK chunking only works with the following objects:
| LoginHistory |
| LoyaltyAggrPointExprLedger |
| LoyaltyLedger |
| LoyaltyLedgerTraceability |
| LoyaltyMemberCurrency |
| LoyaltyMemberTier |
| LoyaltyPartnerProduct |
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<name>Salesforce plugins</name>
<groupId>io.cdap.plugin</groupId>
<artifactId>salesforce-plugins</artifactId>
<version>1.7.0-SNAPSHOT</version>
<version>1.7.2-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Salesforce Plugins</description>
<url>https://github.com/data-integrations/salesforce</url>
Expand Down Expand Up @@ -66,14 +66,14 @@
<spark2.version>2.1.3</spark2.version>
<hydrator.version>2.10.0</hydrator.version>
<commons.version>3.18.0</commons.version>
<salesforce.api.version>62.0.0</salesforce.api.version>
<salesforce.api.version>64.0.0</salesforce.api.version>
<cometd.java.client.version>4.0.0</cometd.java.client.version>
<antlr.version>4.7.2</antlr.version>
<mockito.version>2.23.0</mockito.version>
<commons.csv.version>1.6</commons.csv.version>
<jackson.version>1.9.13</jackson.version>
<jackson2.version>2.17.1</jackson2.version>
<json.version>20180813</json.version>
<json.version>20231013</json.version>
<awaitility.version>3.1.6</awaitility.version>
<commons-logging.version>1.2</commons-logging.version>
<testSourceLocation>${project.basedir}/src/test/java/</testSourceLocation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class SalesforceConstants {

public static final String API_VERSION = "62.0";
public static final String API_VERSION = "64.0";
public static final String REFERENCE_NAME_DELIMITER = ".";

public static final String PROPERTY_CONSUMER_KEY = "consumerKey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class SalesforceSourceConstants {
public static final int MIN_PK_CHUNK_SIZE = 1;
// https://developer.salesforce.com/docs/atlas.en-us.252.0.api_asynch.meta/api_asynch/
// async_api_headers_enable_pk_chunking.htm
// **Always use lowercase names** to ensure consistency, especially if the sObject name is manually provided.
// Update this list with each API version upgrade.
public static final List<String> SUPPORTED_OBJECTS_WITH_PK_CHUNK = Arrays.asList("account",
"accountcontactrelation",
"accountteammember",
Expand Down Expand Up @@ -108,6 +110,7 @@ public class SalesforceSourceConstants {
"loginhistory",
"loyaltyaggrpointexprledger",
"loyaltyledger",
"loyaltyledgertraceability",
"loyaltymembercurrency",
"loyaltymembertier",
"loyaltypartnerproduct",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.cdap.plugin.salesforce.plugin.source.batch.util;

import com.google.common.base.Strings;
import com.sforce.async.AsyncApiException;
import com.sforce.async.AsyncExceptionCode;
import com.sforce.async.BatchInfo;
Expand Down Expand Up @@ -252,4 +253,18 @@ public static RetryPolicy<Object> getRetryPolicy(Long initialRetryDuration, Long
return RetryPolicy.builder().withMaxRetries(0).build();
}
}

// This is added for UCS use case only to identify the objects where PK chunking needs to be enabled by default.
public static boolean isPkChunkingSupported(String sobjectName) {
if (!Strings.isNullOrEmpty(sobjectName)) {
return SalesforceSourceConstants.SUPPORTED_OBJECTS_WITH_PK_CHUNK.contains(sobjectName.toLowerCase())
|| isCustomObject(sobjectName);
}
return false;
}

// This is added only for UCS use case.
private static boolean isCustomObject(String sobjectName) {
return sobjectName.toLowerCase().endsWith("__c");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.LoggerFactory;
import scala.reflect.ClassTag$;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -148,6 +149,13 @@ private static Object convertValue(Object value, Schema.Field field) {
}
}

// NOTE: org.json >= 20230227 returns BigDecimal for all non-integer JSON numbers.
if (value instanceof BigDecimal && fieldSchemaType.equals(Schema.Type.DOUBLE)) {
// Avro Schema.Type.DOUBLE expects a Double instance (or primitive double) at serialization time,
// so converting BigDecimal → double for compatibility.
return ((BigDecimal) value).doubleValue();
}

return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import com.sforce.async.BulkConnection;
import com.sforce.async.ConcurrencyMode;
import com.sforce.async.JobInfo;
import io.cdap.plugin.salesforce.plugin.source.batch.util.SalesforceSourceConstants;
import io.cdap.plugin.salesforce.plugin.source.batch.util.SalesforceSplitUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -83,4 +86,25 @@ public void testAwaitCompletionBatchCompleted() throws Exception {
// Call the awaitCompletion method and verify that it completes successfully
SalesforceBulkUtil.awaitCompletion(bulkConnection, job, Collections.singletonList(batchInfo), true);
}

@Test
public void testPKChunkingEnabledForSobjectsWithAllCases() {
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("Account"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("account"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("aCcOuNt"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("Case"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("CONTACT"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("test_custom__c"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("Test_custom__c"));
Assert.assertTrue(SalesforceSplitUtil.isPkChunkingSupported("TEST_CUSTOM__C"));
Assert.assertFalse(SalesforceSplitUtil.isPkChunkingSupported("Not_Supported"));
Assert.assertFalse(SalesforceSplitUtil.isPkChunkingSupported("notsupported"));
}

@Test
public void testPKChunkingSupportedListContainsNoUpperCaseValues() {
// SUPPORTED_OBJECTS_WITH_PK_CHUNK list must have only lower case values.
Assert.assertFalse(SalesforceSourceConstants.SUPPORTED_OBJECTS_WITH_PK_CHUNK.stream()
.anyMatch(s -> s.matches(".*[A-Z].*")));
}
}