microsoft / Analysis-Services

Git repo for Analysis Services samples and community projects
MIT License
605 stars 416 forks source link

Commit aefeb26 brings -LiteralPath in function and prevents the use of wildcard characters #269

Closed VincentCotineau closed 4 months ago

VincentCotineau commented 4 months ago

Hi, I am using the function Import-FabricItems as such :

$pbipFilePath = "$ArtifactRoot/$PBIPArtifactName.*"

Import-FabricItems -workspaceId $groupId -path $pbipFilePath

Since yesterday (Commit aefeb26), this function uses LiteralPath to try to find the files passed as parameters, and thus prevents from using wildcard characters and i find it troublesome because for example when we try to import pbip files we have to match several folders (PBIPArtifactName.SemanticModel and PBIPArtifactName.Report) and several files in those folders.

RuiRomano commented 4 months ago

Thanks for the feedback. I made that change to support working with folders with characters in the path like square brackets (common in workspace names). Import-FabricItems is already recursively searching for all the .pbir and .pbism files in the provider folder, you do not require to search for the .Report and .SemanticModel.

For example, before if you did something like: Import-FabricItems -path "c:\temp\Project [dev]\PBIP" it wouldnt work and user must know that he should escape the square brackets.

VincentCotineau commented 4 months ago

Thanks for the reply Rui. I was using this in way that the path provided was matching .SemanticModel folder and subfiles and .Report folder and subfiles so it was working and the pbir and pbism files were found. It was matching because of the .* wildcard. I understand why you made the change, and I tried to adapt by doing the import in 2 steps :

$PBIPArtifactName = $datasetName
$pbipFilePathSemanticModel = "$ArtifactRoot\$PBIPArtifactName.SemanticModel"
$pbipFilePathReport = "$ArtifactRoot\$PBIPArtifactName.Report"
#Publishing Semantic Model
$semanticModelImport = Import-FabricItems -workspaceId $groupId -path $pbipFilePathSemanticModel 
#Publishing Report
Import-FabricItems -workspaceId $groupId -path $pbipFilePathReport -itemProperties @{"semanticModelId"=$semanticModelImport.Id} 

So that no wildcard is given, and the objects are found. I found that way in the readme here : (https://github.com/microsoft/Analysis-Services/tree/aefeb2662e358cf4d0ca131b37824180bf26a3b7/pbidevmode/fabricps-pbip) But now i get antoher error :


2024-06-28T14:05:32.8934130Z Item API dont support byPath connection, switch the connection in the *.pbir file to 'byConnection'.
2024-06-28T14:05:32.8942375Z At D:\a\r1\a\modules\FabricPS-PBIP.psm1:787 char:29
2024-06-28T14:05:32.8943844Z + …             throw "Item API dont support byPath connection, switch th …
2024-06-28T14:05:32.8944596Z +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-06-28T14:05:32.8945571Z + CategoryInfo          : OperationStopped: (Item API dont suppo… to 'byConnection'.:String) [], RuntimeException
2024-06-28T14:05:32.8946115Z + FullyQualifiedErrorId : Item API dont support byPath connection, switch the connection in the *.pbir file to 'byConnection'.```

This new error i don't understand. Maybe you can help ? 
RuiRomano commented 4 months ago

A few weeks ago I launched another commandlet Import-FabricItem specific for item by item deployment giving you more control. See the example here: https://learn.microsoft.com/en-us/rest/api/fabric/articles/get-started/deploy-project#script-template

VincentCotineau commented 4 months ago

Yes this is also what I saw and tried to use. That's when I get the 'Item API dont suport byPath connection' which I don't understand...

RuiRomano commented 4 months ago

The reason of the byPath error its because the API cannot solve the relative path in the byPath as Fabric Git integration does. Basically, when you deploy your report using an API you must resolve that connection to the semantic model. If you deploy both semantic model and report, then you should first deploy the semantic model, save the id and then deploy the report connected to the semantic model id. To avoid that error you must specify the semanticModel id in the -itemProperties of the import-fabricitem.

Import-FabricItems does what I described above automatically for you.

# Import the semantic model and save the item id
$semanticModelImport = Import-FabricItem -workspaceId $workspaceId -path $pbipSemanticModelPath

# Import the report and ensure its binded to the previous imported report
$reportImport = Import-FabricItem -workspaceId $workspaceId -path $pbipReportPath -itemProperties @{"semanticModelId" = $semanticModelImport.Id}
VincentCotineau commented 4 months ago

This is what I do. `$PBIPArtifactName = $datasetName $pbipFilePathSemanticModel = "$ArtifactRoot\$PBIPArtifactName.SemanticModel" $pbipFilePathReport = "$ArtifactRoot\$PBIPArtifactName.Report"

Publishing Semantic Model

$semanticModelImport = Import-FabricItems -workspaceId $groupId -path $pbipFilePathSemanticModel

Publishing Report

Import-FabricItems -workspaceId $groupId -path $pbipFilePathReport -itemProperties @{"semanticModelId"=$semanticModelImport.Id} `

I think the semanticModelId is never used later in the code.

$reportDatasetPath = (Resolve-path -LiteralPath (Join-Path $itemPath $pbirJson.datasetReference.byPath.path.Replace("/", "\"))).Path

                        $datasetReference = $datasetReferences[$reportDatasetPath]       

                        if ($datasetReference)
                        {
                            # $datasetName = $datasetReference.name

                            $datasetId = $datasetReference.id

the few lines of code

But i am not sure. But i already use the code you gave me as a reference

RuiRomano commented 4 months ago

Looking at your code above it looks like you are using the Import-FabricItems with plural and not the singular Import-FabricItem that returns the imported object id.

Try change to the following, notice the name of the commandlet 'Import-FabricItem' and not 'Import-FabricItems'

$PBIPArtifactName = $datasetName 
$pbipFilePathSemanticModel = "$ArtifactRoot\$PBIPArtifactName.SemanticModel" 
$pbipFilePathReport = "$ArtifactRoot\$PBIPArtifactName.Report" 

#Publishing Semantic Model 
$semanticModelImport = Import-FabricItem -workspaceId $groupId -path $pbipFilePathSemanticModel  

#Publishing Report 
Import-FabricItem -workspaceId $groupId -path $pbipFilePathReport -itemProperties @{"semanticModelId"=$semanticModelImport.Id} 

When you use 'Import-FabricItems' it handles the publishing of both semantic model and report, you only need to call it once and point to the folder that includes the subfolder for the semantic model and report. You can even point it to a folder with many reports and semantic models.

VincentCotineau commented 4 months ago

Oh well. I believe I should seen that myself. Thank you for your time, have a good week !