I want to load empty strings in JSON as null value into snowflake table.
The snowflake document says that this should be possible with NULL_IF=('')
I tried that in COPY INTO statement, but did not work as expected.
Here is my sample JSON:
{
"Id": 100,
"Address": ""
}
Here is my sample query:
COPY INTO my_table FROM 's3://my_bucket/'
FILES = ('my_file.json')
FILE_FORMAT = (TYPE = json STRIP_OUTER_ARRAY = true NULL_IF = ('\\N', 'NULL', 'null', 'NUL', ''))
CREDENTIALS = (AWS_KEY_ID = 'my_key' AWS_SECRET_KEY = 'my_secret_key')
MATCH_BY_COLUMN_NAME = CASE_SENSITIVE
ON_ERROR = 'CONTINUE'
FORCE = TRUE ;
Related
Getting errors in following TypeORM query:
async exportUsers(stateId: string, zipcodes: string)
{
//zipcodes = '60563', '54656', '94087';//
const query = await this.userRepository
.createQueryBuilder('user')
.select('user.email', 'email')
.where('left(user.Zip,5) in :zip', { zip: zipcodes });
}
How to pass string containing 'array of strings' to TypeORM query using IN.
This worked:
zipcodes = '60563', '54656', '94087';
const ziplist: string[] = zipcodes.replace("'", "").split(",");
Changed query to:
.where('left(s.ShipToZip,5) in (:...zip)', { zip: ziplist });
Replace your where clause with this code:
.where("left(user.Zip,5) IN (:zip )", { zip : zipcodes })
Note: your zipcode variable should be in array format; in means:
zipcodes = ['94085','54656','94087']
Am trying to upsert some values in salesforce object using mule4 transform my input is below
Transform shape:
%dw 2.0
output application/java
---
[{
Name: vars.det,
Request_Body__c: vars.Req
}]
The input payload am upserting is
input:
[{Name= MuleSoft--Salesforce, Request_Body__c= {
data = {
schema = PZAhU2AlqQtEHKOut4Rctg,
payload = {
Job_Prev_Name__c =Mule UWW, LastModifiedDate= 2020 - 09 - 15,
ChangeEventHeader = {
commitNumber = 1072316585812,
commitUser = 0057000001 cAAA,
sequenceNumber = 1,
entityName = ATI__c,
changeType = UPDATE,
changedFields =
}, Job_Name__c = Mule UWX, Name = CMule UWX}, event= {
replayId = 0311
}
},
channel = /data/ATI_Job__ChangeEvent
}
}]
While upserting am getting error like invalid input
How can i modify the "Request_Body__c" filed inorder to upsert in salesforce?
I have a Controller class on which I execute a SOQL query to Custom Metadata Type records.
The SOQL query also contains a child relationship query (Master-Detail relationship).
I need to write a test with mock custom metadata records
#AuraEnabled(cacheable=true)
public static List<Response> getLeadMetadataValues() {
List<Lead_Business_Status__mdt> leadBusinessStatusList = [
SELECT Id, Label, DeveloperName, Index__c,
(SELECT Id, Label, DeveloperName, Reason_Status_Api_Name__c FROM Lead_Reason_Status__r)
FROM Lead_Business_Status__mdt ORDER BY Index__c ASC
];
List<Response> resList = new List<Response>();
if (Test.isRunningTest()) {
leadBusinessStatusList = new List<Lead_Business_Status__mdt>();
leadBusinessStatusList.add(createMock());
}
for (Lead_Business_Status__mdt bs : leadBusinessStatusList) {
Response res = new Response();
res.Id = bs.Id;
res.businessStatusLabel = bs.Label;
res.businessStatusDevName = bs.DeveloperName;
res.index = bs.Index__c;
for (Lead_Reason_Status__mdt rs : bs.Lead_Reason_Status__r) {
ReasonStatus rsObj = new ReasonStatus();
rsObj.Id = rs.Id;
rsObj.reasonStatusLabel = rs.Label;
rsObj.reasonStatusDevName = rs.DeveloperName;
rsObj.fieldApiName = rs.Reason_Status_Api_Name__c;
res.reasonStatusList.add(rsObj);
}
resList.add(res);
}
return resList;
}
I use Test.isRunningTest() to populate the leadBusinessStatusList with the mock data.
I am able to create a mock object for the Master record: Lead_Business_Status__mdt and Detail record: Lead_Reason_Status__mdt. However, I wasn't able to add the Detail record to the related list: Lead_Reason_Status__r
private static Lead_Business_Status__mdt createMock() {
String reasonStatusStr = '{"Label":"Transfer to Queue", "DeveloperName":"Transfer_to_Queue", "Reason_Status_Api_Name__c":"Transfer_to_Queue"}';
Lead_Reason_Status__mdt reasonStatusObj = (Lead_Reason_Status__mdt) System.JSON.deserialize(reasonStatusStr, Lead_Reason_Status__mdt.class);
System.debug('Lead_Reason_Status__mdt: ' + reasonStatusObj);
String businessStatusStr = '{"Label":"Wrong Lead", "DeveloperName":"Wrong_Lead", "Index__c":"1"}';
Lead_Business_Status__mdt businessStatusObj = (Lead_Business_Status__mdt) System.JSON.deserialize(businessStatusStr, Lead_Business_Status__mdt.class);
return businessStatusObj;
}
The test is covered except the inner for loop of the Lead_Reason_Status__mdt.
How can I create a mock object with populating the child relationship list?
Can you try use JSON.deserialize method to setup these metadata records.
List<Lead_Business_Status__mdt> leadBusinessStatusList = (List< Lead_Business_Status__mdt >) JSON.deserialize( '[{"Id": "xoid914011599", "Label": "test", "DeveloperName": "test","Reason_Status_Api_Name__c": "test"}, {"Id": "xoid9140115992","Label":"test2","DeveloperName": "test2","Reason_Status_Api_Name__c": "test2"}]', List<Lead_Business_Status__mdt>.class );
I am trying to create and execute a simple Snowflake stored procedure which takes an input argument and creates a stage. However, when I try to call the procedure it throws
ERROR: invalid value [:] for parameter
create or replace procedure raw.test.create_stage_test(PARM_URL string)
returns string
language javascript
execute as owner
as
$$
var cmd = `create or replace stage raw.test.agency_type_test
url =:1
file_format = (type = json)
credentials = (aws_role = 'arn:aws:iam::myrole');`
var sql_statement = snowflake.createStatement({
sqlText: cmd,
binds: [PARM_URL]
});
try {
var rs = sql_statement.execute();
rs.next()
rcount = rs.getColumnValue(1);
if (rcount == 0){
throw "row count is 0";
}
return "Rows count: " + rcount;
}
catch (err) {
return "Failed: " + err; // Return a success/error indicator.
}
$$;
CALL raw.test.create_stage_test('s3://mybucket');
Perhaps using interpolation, as in the following code snippet, could be an alternative? Note the single quotes included around the url value:
var cmd = `create or replace stage agency_type_test
url='${PARM_URL}'
file_format = (type = json)
credentials = (aws_role = 'arn:aws:iam::myrole');`
var sql_statement = snowflake.createStatement({
sqlText: cmd
});
I'm using the azure search api trying to filter by a certain field value: businesstype = store. It always returns 3 stores, even though I should have thousands. I can't tell for sure what's inside the index. In the Azure search web portal I type businessType eq 'store' and it gives me two stores, then starts returning businesstype = restaurant. Not sure what is going on. We have other implementations in other projects where filters are working. Here's code that I'm executing as it is invoked by using ASP.NET Web API
var indexClient = new SearchIndexClient(GlobalSettings.SearchServiceName, $"businesses{GlobalSettings.Environment}", new SearchCredentials(GlobalSettings.SearchServiceAdminApiKey));
if (latitude == null && longitude == null)
{
//chicago
latitude = 41.8333925;
longitude = -88.0121478;
}
// get all attributes and camel case them
var attributes = typeof(BusinessSearchItem).GetProperties().Select(x => char.ToLowerInvariant(x.Name[0]) + x.Name.Substring(1)).ToList();
var parameters = new SearchParameters
{
Select = attributes,
QueryType = QueryType.Full,
Top = take,
Skip = skip,
IncludeTotalResultCount = true,
OrderBy = new List<string>() { $"geo.distance(location, geography'POINT({longitude} {latitude})')" }
};
// filters
string filter = "";
if (!string.IsNullOrEmpty(businessType))
{
switch (businessType.ToLower())
{
case "restaurant":
filter += "businessType eq 'Restaurant'";
break;
case "store":
filter += "businessType eq 'Store'";
break;
}// end switch on business type
}
parameters.Filter = filter;
try
{
// run the search
var results = indexClient.Documents.Search<BusinessSearchItem>(q, parameters);
Logger.Log.Info($"Search conducted. Query: {q} Business Type: {businessType} Lat: {latitude} Long: {longitude} User: {username}");
var businessDTOs = results.Results.Select(x => new BusinessDTO
{
.........
).ToList()
}).ToList();
the model BusinessSearchItem has a field BusinessType of string that has the attribute searchable. The skip is 0 and take 40.
The problem wasn't the search at all, it was that the data was not in the index