question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array Type Mapping not working

See original GitHub issue

Hi guys, I have a strange problem, maybe it is something that I’m missing out, but I have the following LINQ Lambda query:

    var ss = ctx.ShipZones.SelectMany(
                    z => ctx.ShipDecks,
                    (z, d) => 
                        new
                        {
                            Zone = z.ZIndex,
                            Deck = d.DIndex,
                            Value = ctx.Tags
                                .AsExpandable()
                                .Include(s => s.TagSettings.Device.System)
                                .Where(s =>
                                     s.TagSettings.TagTypeId == 171
                                     && s.TagSettings.Device.System.Id == z.Id
                                     && s.TagSettings.Device.ControlArea.Contains(d.Id)
                                        )
                                .Average(s => s.Value)
                        }
                    ).ToList();

According to this article, this should be translated to this:

SELECT z.z_index AS "Zone", d.d_index AS "Deck", (
    SELECT AVG(t.value)
    FROM tags_current_data AS t
    INNER JOIN tags_settings AS t0 ON t.tag_id = t0.id
    INNER JOIN systems_devices AS s ON t0.device_id = s.id
    INNER JOIN systems AS s0 ON s.system_id = s0.id
    WHERE ((t0.tag_type_id = 171) AND (s0.id = z.id)) AND (d.id = ANY(s.control_area))) AS "Value"
FROM zones AS z
CROSS JOIN decks AS d

But somehow, the translated query is like this:

SELECT z.z_index AS "Zone", d.d_index AS "Deck", (
    SELECT AVG(t.value)
    FROM tags_current_data AS t
    INNER JOIN tags_settings AS t0 ON t.tag_id = t0.id
    INNER JOIN systems_devices AS s ON t0.device_id = s.id
    INNER JOIN systems AS s0 ON s.system_id = s0.id
    WHERE ((t0.tag_type_id = 171) AND (s0.id = z.id)) AND (TRUE = FALSE)) AS "Value"
FROM zones AS z
CROSS JOIN decks AS d

The difference is where it should be d.id = ANY(s.control_area) it is TRUE = FALSE Can anyone tell me what am I doing wrong?

Thanks in advance, Julian Dimitrov

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Sep 28, 2020

Great, thanks for confirming. The new query uses array containment syntax because that allows for index use - if control_area has an index, the query will run much faster than with ANY. See #1372 for more details.

0reactions
julian-dimitroffcommented, Sep 28, 2020

@roji yes it produces a query but it is a bit different. As no expert in postgresql I’ll paste here the query that was produced when the entity has type List<long>

SELECT z.z_index AS "Zone", d.d_index AS "Deck", (
    SELECT AVG(t.value)
    FROM tags_current_data AS t
    INNER JOIN tags_settings AS t0 ON t.tag_id = t0.id
    INNER JOIN systems_devices AS s ON t0.device_id = s.id
    INNER JOIN systems AS s0 ON s.system_id = s0.id
    WHERE ((t0.tag_type_id = 171) AND (s0.id = z.id)) AND (s.control_area @> ARRAY[d.id]::bigint[])) AS "Value"
FROM zones AS z
CROSS JOIN decks AS d

The query works as expected when applied on the database server.

BR, Julian

Read more comments on GitHub >

github_iconTop Results From Across the Web

Map not working in an array but for each is working
1. Your querySnapshot variable is an object instead of an array, that's why you can't use map · 1. What type of data...
Read more >
Mapped Types Not working correctly with arrays #16614
Rewritten MappedType as a homomorphic mapped type called Arrayify . Created a new type for T that is constrained to BaseType . Used...
Read more >
Arrays | Elasticsearch Guide [8.9]
In Elasticsearch, there is no dedicated array data type. ... Arrays of objects do not work as you would expect: you cannot query...
Read more >
Explicit array type in mapping - Elasticsearch
Hello, Does anyone know whether it is possible to explicitly specify that a property is expected to be an array in the mapping?...
Read more >
Can't access mapping when using array as ValueType
1 Answer 1 ... Your mapping is pointing to dynamic arrays (with an s). Each one of those also has an index. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found