Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLScript Replacement \\n #33

Open
georgedutton opened this issue Apr 24, 2024 · 6 comments
Open

SQLScript Replacement \\n #33

georgedutton opened this issue Apr 24, 2024 · 6 comments
Labels
triage Issue is under investigation

Comments

@georgedutton
Copy link

When trying to use config-prod.csv to replace the script in a sqlscript as part of a synapse deployment, I found that the library saves the file with escaped values, e.g. \n instead of \n etc. After debugging I found that it is due to the $output = ($obj.Body | ConvertTo-Json -Compress:$true -Depth 100) line in Save-SynapseObectAsFile.ps1.

Test script:

$output = "{type=SqlScript; name=Populate serverless; path=content.query; value=IF NOT EXISTS (SELECT * FROM sys.external_file_formats WHERE name = 'SynapseDeltaFor
mat') \n\t"

$output | ConvertTo-Json -Depth 100

Output:

{type=SqlScript; name=Populate serverless; path=content.query; value=IF NOT EXISTS (SELECT * FROM sys.external_file_formats WHERE name = \u0027SynapseDeltaFor\r\nmat\u0027) \\n\\t
@NowinskiK NowinskiK added the triage Issue is under investigation label Apr 25, 2024
@NowinskiK
Copy link
Member

Everything looks correct - check below code:

$output = '{
    "type": "SqlScript", 
    "name": "Populate serverless", 
    "path": "content.query",
    "query": "SELECT * FROM sys.external_file_formats WHERE 1=1; \n\t"
}'

$output | ConvertTo-Json -Depth 100

Output:

{\r\n\t\"name\": \"10-Ext-Table\",\r\n\t\"properties\": {\r\n\t\t\"content\": {\r\n\t\t\t\"query\": \"SELECT * FROM sys.external_file_formats WHERE 1=1; \\n\\t\"\r\n\t\t},\r\n\t\t\"type\": \"SqlQuery\"\r\n\t}\r\n}

Note that new lines in value-part of json element has \\t\\n, but new line in JSON object itself is encoded to \n.
Both are correct.

@georgedutton
Copy link
Author

georgedutton commented Apr 26, 2024

Thanks for the reply @NowinskiK
Sorry for not saying this in the initial bug but we've found that if you deploy that output to Synapse (or view the ~sqlscript file) you find the values \n, \t and \u0027 are also present in the workspace.

The behaviour using config-prod.csv and without it, are different.

@NowinskiK
Copy link
Member

George, can you show me the example of SQLScript (please scrub any client-related pieces).
I'm wondering where the problem lies, as I can't do too much with ConvertTo-Json as it's standard cmd.

@NowinskiK NowinskiK reopened this Apr 26, 2024
@georgedutton
Copy link
Author

Yes of course, config-prod.csv contains this value (truncate for simplicity and obfuscation)

SqlScript,Populate serverless - Datawarehouse database,content.query,"IF NOT EXISTS (SELECT * FROM sys.external_file_formats WHERE name = 'SynapseDeltaFormat') \n\tCREATE EXTERNAL FILE FORMAT [SynapseDeltaFormat] \n\tWITH ( FORMAT_TYPE = DELTA)\nGO\n\n"

~Populate serverless - Datawarehouse database.json file:
{"name":"Populate serverless - Datawarehouse database","properties":{"content":{"query":"IF NOT EXISTS (SELECT * FROM sys.external_file_formats WHERE name = \u0027SynapseDeltaFormat\u0027) \\n\\tCREATE EXTERNAL FILE FORMAT [SynapseDeltaFormat] \\n\\tWITH ( FORMAT_TYPE = DELTA)\\nGO\\n\\n","metadata":{"language":"sql"},"currentConnection":{"databaseName":"DataWarehouse","poolName":"Built-in"},"resultLimit":5000},"type":"SqlQuery"}}

deployment result:
image

Deployment results (without using config-prod.csv)
image

@NowinskiK
Copy link
Member

Could you show me also what the original file (Populate serverless - Datawarehouse database.json) looks like?

@georgedutton
Copy link
Author

Sure, I've removed alot of the script (which contains environment specific storage names which is the reason for the replacement) but the same should apply no matter the length.

{
	"name": "Populate serverless - Datawarehouse database",
	"properties": {
		"content": {
			"query": "IF NOT EXISTS (SELECT * FROM sys.external_file_formats WHERE name = 'SynapseDeltaFormat') \n\tCREATE EXTERNAL FILE FORMAT [SynapseDeltaFormat] \n\tWITH ( FORMAT_TYPE = DELTA)\nGO\n\n",
			"metadata": {
				"language": "sql"
			},
			"currentConnection": {
				"databaseName": "DataWarehouse",
				"poolName": "Built-in"
			},
			"resultLimit": 5000
		},
		"type": "SqlQuery"
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Issue is under investigation
Projects
None yet
Development

No branches or pull requests

2 participants