forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore features in FeatureRow if it's not requested in import spec
- Loading branch information
Pradithya Aria
committed
Jan 23, 2019
1 parent
6797ba4
commit 98d11cf
Showing
12 changed files
with
405 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
ingestion/src/test/java/feast/ingestion/transform/fn/ConvertTypesDoFnTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2018 The Feast Authors | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
package feast.ingestion.transform.fn; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.withSettings; | ||
|
||
import com.google.protobuf.Timestamp; | ||
import feast.ingestion.model.Specs; | ||
import feast.ingestion.service.FileSpecService; | ||
import feast.ingestion.service.SpecService; | ||
import feast.types.FeatureProto.Feature; | ||
import feast.types.FeatureRowExtendedProto.Attempt; | ||
import feast.types.FeatureRowExtendedProto.FeatureRowExtended; | ||
import feast.types.FeatureRowProto.FeatureRow; | ||
import feast.types.GranularityProto.Granularity.Enum; | ||
import feast.types.ValueProto.Value; | ||
import java.util.Collections; | ||
import org.apache.beam.sdk.testing.PAssert; | ||
import org.apache.beam.sdk.testing.TestPipeline; | ||
import org.apache.beam.sdk.transforms.Create; | ||
import org.apache.beam.sdk.transforms.ParDo; | ||
import org.apache.beam.sdk.values.PCollection; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ConvertTypesDoFnTest { | ||
|
||
@Rule public TestPipeline testPipeline = TestPipeline.create(); | ||
private ConvertTypesDoFn doFn; | ||
private Specs specs; | ||
private SpecService fileSpecService; | ||
|
||
@Before | ||
public void setUp() { | ||
fileSpecService = | ||
new FileSpecService(getClass().getClassLoader().getResource("core_specs").getPath()); | ||
specs = mock(Specs.class, withSettings().serializable()); | ||
doFn = new ConvertTypesDoFn(specs); | ||
} | ||
|
||
@Test | ||
public void shouldIgnoreUnknownFeatureId() { | ||
when(specs.tryGetFeatureSpec("testEntity.day.testInt64")) | ||
.thenReturn( | ||
fileSpecService | ||
.getFeatureSpecs(Collections.singletonList("testEntity.day.testInt64")) | ||
.get("testEntity.day.testInt64")); | ||
|
||
FeatureRow row = | ||
FeatureRow.newBuilder() | ||
.setEntityKey("1234") | ||
.setEntityName("testEntity") | ||
.addFeatures( | ||
Feature.newBuilder() | ||
.setId("testEntity.day.testInt64") | ||
.setValue(Value.newBuilder().setInt64Val(10))) | ||
// this feature should be ignored | ||
.addFeatures(Feature.newBuilder().setId("testEntity.none.unknown_feature")) | ||
.build(); | ||
FeatureRowExtended rowExtended = FeatureRowExtended.newBuilder().setRow(row).build(); | ||
PCollection<FeatureRowExtended> p = testPipeline.apply(Create.of(rowExtended)); | ||
PCollection<FeatureRowExtended> out = p.apply(ParDo.of(doFn)); | ||
|
||
FeatureRow expRow = | ||
FeatureRow.newBuilder() | ||
.setEntityKey("1234") | ||
.setEntityName("testEntity") | ||
.addFeatures( | ||
Feature.newBuilder() | ||
.setId("testEntity.day.testInt64") | ||
.setValue(Value.newBuilder().setInt64Val(10))) | ||
.setGranularity(Enum.DAY) | ||
.setEventTimestamp(Timestamp.getDefaultInstance()) | ||
.build(); | ||
|
||
FeatureRowExtended expected = | ||
FeatureRowExtended.newBuilder() | ||
.setRow(expRow) | ||
.setLastAttempt(Attempt.getDefaultInstance()) | ||
.build(); | ||
PAssert.that(out).containsInAnyOrder(expected); | ||
|
||
testPipeline.run(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
ingestion/src/test/java/feast/ingestion/transform/fn/SplitFeaturesDoFnTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2018 The Feast Authors | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
package feast.ingestion.transform.fn; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.withSettings; | ||
|
||
import feast.ingestion.model.Specs; | ||
import feast.ingestion.transform.SplitFeatures.SplitStrategy; | ||
import feast.types.FeatureProto.Feature; | ||
import feast.types.FeatureRowExtendedProto.FeatureRowExtended; | ||
import feast.types.FeatureRowProto.FeatureRow; | ||
import org.apache.beam.sdk.testing.PAssert; | ||
import org.apache.beam.sdk.testing.TestPipeline; | ||
import org.apache.beam.sdk.transforms.Create; | ||
import org.apache.beam.sdk.transforms.ParDo; | ||
import org.apache.beam.sdk.values.PCollection; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class SplitFeaturesDoFnTest { | ||
@Rule public final transient TestPipeline pipeline = TestPipeline.create(); | ||
Specs specs; | ||
SplitFeaturesDoFn doFn; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
specs = mock(Specs.class, withSettings().serializable()); | ||
SplitStrategy strategy = mock(SplitStrategy.class, withSettings().serializable()); | ||
doFn = new SplitFeaturesDoFn(strategy, specs); | ||
} | ||
|
||
@Test | ||
public void shouldIgnoreUnknownFeatureId() { | ||
FeatureRow row = | ||
FeatureRow.newBuilder() | ||
.setEntityKey("1234") | ||
.setEntityName("testEntity") | ||
// this feature should be ignored | ||
.addFeatures(Feature.newBuilder().setId("testEntity.none.unknown_feature")) | ||
.build(); | ||
FeatureRowExtended rowExtended = FeatureRowExtended.newBuilder().setRow(row).build(); | ||
PCollection<FeatureRowExtended> p = pipeline.apply(Create.of(rowExtended)); | ||
PCollection<FeatureRowExtended> out = (PCollection<FeatureRowExtended>) p.apply(ParDo.of(doFn)); | ||
PAssert.that(out).empty(); | ||
|
||
pipeline.run(); | ||
} | ||
} |
Oops, something went wrong.