EntityQuery and several different NativeArray.

Hello.
There are entities which have A,B,C,D components. There are other entities which have A,B,C,E components. I need to create two arrays of component A.
The first should consist of entities at which there are D and E components.
The second should consist of entities at which there are components D.
At the same time whether it is possible to make so that their indexes matched?
For example:
[ A(d), A(d), A(d), A(d) ]
[ A(d), A(d), A(d), A(d), A(e), A(e), A(e) ]

There is such assumption:

       EntityQuery m_GroupFirst = GetEntityQuery (
            new EntityQueryDesc {
                All = new ComponentType [] {
                    ComponentType.ReadWrite<ComponentA> (),
                    ComponentType.ReadWrite<ComponentB> (),
                    ComponentType.ReadWrite<ComponentC> (),
                    ComponentType.ReadWrite<ComponentD> (),
                },
                //Any = new ComponentType [] {},
                //None = new ComponentType [] {},
            }
        );

       EntityQuery m_GroupSecond = GetEntityQuery (
            new EntityQueryDesc {
                All = new ComponentType [] {
                    ComponentType.ReadWrite<ComponentA> (),
                    ComponentType.ReadWrite<ComponentB> (),
                    ComponentType.ReadWrite<ComponentC> (),
                    ComponentType.ReadWrite<ComponentD> (),

                },
                Any = new ComponentType [] {
                    ComponentType.ReadWrite<ComponentE> (),
                },
                //None = new ComponentType [] {},
            }
        );

    protected override JobHandle OnUpdate ( JobHandle inputDeps ) {

        var arrayFirst = m_GroupFirst.ToComponentDataArray<ComponentA> ( Allocator.TempJob );
        var arraySecond = m_GroupSecond.ToComponentDataArray<ComponentA> ( Allocator.TempJob );

On how many this correct solution?
Can perhaps make through one EntityQuery, but not two?

I’m not sure why you need this but I can’t think of a solution that’d just naturally do it that way. I’d probably just create a single query and generate the arrays myself.

For example, I’d do this in a job but here’s an example just using ForEach to explain what I mean.

            // Do this is in a job it'd be very fast.
            var listFirst = new NativeList<ComponentA>(Allocator.TempJob);
            var listE = new NativeList<ComponentA>(Allocator.TempJob);

            this.Entities.WithAll<ComponentB, ComponentC, ComponentD>().ForEach((Entity entity, ref ComponentA a) =>
            {
                if (this.EntityManager.HasComponent<ComponentE>(entity))
                {
                    listE.Add(a);
                }
                else
                {
                    listFirst.Add(a);
                }
            });

            var arrayFirst = listFirst.AsArray();
            var arraySecond = new NativeArray<ComponentA>(listFirst.Length + listE.Length, Allocator.TempJob);

            NativeArray<ComponentA>.Copy(arrayFirst, 0, arraySecond, 0, arrayFirst.Length);
            NativeArray<ComponentA>.Copy(listE.AsArray(), 0, arraySecond, listFirst.Length, listE.Length);

Not tested~

there is a much cleaner way if ComponentE is only ever accompanied by ABCD as well, but breaks down if it has a separate archetype.

Thanks a lot.
Most likely “EntityManager.HasComponent (entity))” will solve my problem.

Added later:
Though many not necessary admissions turn out.
And in a case with sorting it will not turn out to write in components because, it seems, indexes of arrays and components differ.