Skip to content

Commit

Permalink
Fix so views can be used in views (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulimo authored Dec 11, 2023
1 parent b76915a commit dc7fb82
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/FlowtideDotNet.Substrait/PlanModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ public Plan Modify()
}
var modifierVisitor = new ModifierVisitor(subPlanNameToId);

for (int i = 0; i < newPlan.Relations.Count; i++)
{
var relation = newPlan.Relations[i];
if (relation is RootRelation rootRelation)
{
var modified = modifierVisitor.Visit(rootRelation.Input, default);
newPlan.Relations[i] = modified;
}
else
{
var modified = modifierVisitor.Visit(relation, default);
newPlan.Relations[i] = modified;
}
}

var rootRelationId = -1;
RootRelation? oldRootRel = null;
for (int i = 0; i < _rootPlan.Relations.Count; i++)
Expand Down
55 changes: 55 additions & 0 deletions tests/FlowtideDotNet.AcceptanceTests/ViewTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit.Abstractions;

namespace FlowtideDotNet.AcceptanceTests
{
public class ViewTests : FlowtideAcceptanceBase
{
public ViewTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
}

[Fact]
public async Task TestViewInView()
{
GenerateData();

await StartStream(@"
CREATE VIEW test AS
SELECT
userKey,
firstName
FROM users;
CREATE VIEW test2 AS
SELECT
userKey,
firstName
FROM test;
INSERT INTO output
SELECT userKey, firstName FROM test2;
");

await WaitForUpdate();

AssertCurrentDataEqual(Users.Select(u => new { u.UserKey, u.FirstName }).ToList());
}
}
}

0 comments on commit dc7fb82

Please sign in to comment.