Skip to content

Commit

Permalink
Merge pull request #509 from MarkMpn/virtualentity
Browse files Browse the repository at this point in the history
Virtual Entity
  • Loading branch information
MarkMpn authored Jul 11, 2024
2 parents 06de393 + 8b4517f commit 21cd274
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions AzureDataStudioExtension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

## [v9.2.0](https://github.com/MarkMpn/Sql4Cds/releases/tag/v9.2.0) - 2024-07-10
## [v9.2.0](https://github.com/MarkMpn/Sql4Cds/releases/tag/v9.2.0) - 2024-07-11

Added export to CSV/Excel/JSON/Markdown/XML
Simplify filters that can easily be identified as tautologies or contradictions
Expand All @@ -15,7 +15,7 @@ Fixed paging when using semi-joins
Various fixes when querying virtual entities with unreliable providers:
* values returned as different types
* attributes using names with different case
* not honouring `top`, `offset`, `count`, `order`
* not honouring `top`, `offset`, `count`, `order`, `filter`
Improved error reporting:
* when using `*` instead of column name
* when passing incorrect number of parameters to aggregate functions
Expand Down
9 changes: 8 additions & 1 deletion MarkMpn.Sql4Cds.Engine/ExecutionPlan/FetchXmlScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,13 @@ private void OnRetrievedEntity(Entity entity, INodeSchema schema, IQueryExecutio
// than expected, e.g. msdyn_componentlayer returns string values as guids. Convert the CLR
// values to the correct type before converting to SQL types.
var expectedClrType = SqlTypeConverter.SqlToNetType(col.Value.Type.ToNetType(out _));

// Unwrap common types
if (value is OptionSetValue osv)
value = osv.Value;
else if (value is Money m)
value = m.Value;

if (value.GetType() != expectedClrType)
{
if (value is Guid guidValue)
Expand Down Expand Up @@ -806,7 +813,7 @@ private void OnRetrievedEntity(Entity entity, INodeSchema schema, IQueryExecutio
throw new QueryExecutionException($"Expected {expectedClrType.Name} value, got {value.GetType()}");
}
}
else
else if (value is IConvertible)
{
value = Convert.ChangeType(value, expectedClrType);
}
Expand Down
7 changes: 7 additions & 0 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/FilterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,8 @@ private bool FoldFiltersToDataSources(NodeCompilationContext context, IList<Opti
throw new NotSupportedQueryFragmentException("Missing datasource " + fetchXml.DataSource);

// If the criteria are ANDed, see if any of the individual conditions can be translated to FetchXML
var originalFilter = fetchXml.IsUnreliableVirtualEntityProvider ? Filter.Clone() : null;

Filter = ExtractFetchXMLFilters(
foldableContext,
dataSource,
Expand Down Expand Up @@ -1521,6 +1523,11 @@ private bool FoldFiltersToDataSources(NodeCompilationContext context, IList<Opti
fetchXml.Entity.Items = fetchXml.Entity.Items.Except(notNull).ToArray();
}
}

// Virtual entity providers are unreliable - fold the filters to the FetchXML but keep this
// node to filter again if necessary
if (originalFilter != null)
Filter = originalFilter;
}

if (source is MetadataQueryNode meta)
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine/MarkMpn.Sql4Cds.Engine.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Fixed paging when using semi-joins
Various fixes when querying virtual entities with unreliable providers:
* values returned as different types
* attributes using names with different case
* not honouring `top`, `offset`, `count`, `order`
* not honouring `top`, `offset`, `count`, `order`, `filter`
Improved error reporting:
* when using `*` instead of column name
* when passing incorrect number of parameters to aggregate functions
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds/MarkMpn.SQL4CDS.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Fixed paging when using semi-joins
Various fixes when querying virtual entities with unreliable providers:
* values returned as different types
* attributes using names with different case
* not honouring `top`, `offset`, `count`, `order`
* not honouring `top`, `offset`, `count`, `order`, `filter`
Improved error reporting:
* when using `*` instead of column name
* when passing incorrect number of parameters to aggregate functions
Expand Down

0 comments on commit 21cd274

Please sign in to comment.