Content-Length: 482118 | pFad | http://github.com/data-integrations/bigquery-delta-plugins/pull/146/files

97 mock implementation of rename transformation by seanzhougoogle · Pull Request #146 · data-integrations/bigquery-delta-plugins · GitHub
Skip to content

mock implementation of rename transformation #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>lib</Embed-Directory>
<!--Only @Plugin classes in the export packages will be included as plugin-->
<_exportcontents>io.cdap.delta.bigquery.*</_exportcontents>
<_exportcontents>io.cdap.delta.bigquery.*,io.cdap.delta.transformation.*</_exportcontents>
</instructions>
</configuration>
<executions>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/io/cdap/delta/transformation/MockColumnInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright © 2021 Cask Data, Inc.
*
* 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.
*/

package io.cdap.delta.transformation;

import io.cdap.transformation.api.ColumnInfo;

/**
* Mock Column Info
*/
public class MockColumnInfo implements ColumnInfo {
private String name;

public MockColumnInfo(String name) {
this.name = name;
}

@Override
public String getName() {
return name;
}
}
36 changes: 36 additions & 0 deletions src/main/java/io/cdap/delta/transformation/MockColumnSchema.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2021 Cask Data, Inc.
*
* 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.
*/

package io.cdap.delta.transformation;

import io.cdap.cdap.api.data.schema.Schema;
import io.cdap.transformation.api.ColumnSchema;

/**
* Mock Column Schema
*/
public class MockColumnSchema implements ColumnSchema {
private Schema.Field field;

public MockColumnSchema(Schema.Field field) {
this.field = field;
}

@Override
public Schema.Field getField() {
return field;
}
}
35 changes: 35 additions & 0 deletions src/main/java/io/cdap/delta/transformation/MockColumnValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright © 2021 Cask Data, Inc.
*
* 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.
*/

package io.cdap.delta.transformation;

import io.cdap.transformation.api.ColumnValue;

/**
* Mock Column Value
*/
public class MockColumnValue implements ColumnValue {
private Object value;

public MockColumnValue(Object value) {
this.value = value;
}

@Override
public Object getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright © 2021 Cask Data, Inc.
*
* 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.
*/

package io.cdap.delta.transformation;

import io.cdap.cdap.api.annotation.Name;
import io.cdap.cdap.api.annotation.Plugin;
import io.cdap.cdap.api.data.schema.Schema;
import io.cdap.transformation.api.ColumnInfo;
import io.cdap.transformation.api.ColumnSchema;
import io.cdap.transformation.api.ColumnValue;
import io.cdap.transformation.api.Transformation;
import io.cdap.transformation.api.TransformationContext;
import io.cdap.transformation.api.TransformationDefinitionContext;
import io.cdap.transformation.api.TransformationSpec;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* Mock rename transformation
*/
@Plugin(type = Transformation.PLUGIN_TYPE)
@Name("rename")
public class MockRenameTransformation implements Transformation {
private final MockRenameTransformationConfig config;
private String directive;
private String srcColumn;
private String tgtColumn;

public MockRenameTransformation(MockRenameTransformationConfig config) {
this.config = config;
}

@Override
public void initialize(TransformationContext context) throws Exception {
}

private void parseDirective() {
String[] splits = directive.split(" ");
srcColumn = splits[1];
tgtColumn = splits[2];
}

@Override
public TransformationSpec define(TransformationDefinitionContext context) {
this.directive = context.getDirective();
parseDirective();
return getSecification();
}

@Override
public TransformationSpec getSecification() {
return new TransformationSpec() {
@Override
public List<ColumnInfo> getInputColumns() {
return Arrays.asList(new MockColumnInfo(srcColumn));
}

@Override
public List<ColumnInfo> getOutputColumns() {
return Arrays.asList(new MockColumnInfo(srcColumn));
}
};
}

@Override
public Map<String, ColumnValue> transformValue(Map<String, ColumnValue> input) throws Exception {
Object value = input.remove(srcColumn);
input.put(tgtColumn, new MockColumnValue(value));
return input;
}

@Override
public List<ColumnSchema> transformSchema(Map<String, ColumnSchema> input) throws Exception {


ColumnSchema schema = input.get(srcColumn);
return Arrays.asList(new MockColumnSchema(Schema.Field.of(tgtColumn, schema.getField().getSchema())));
}

@Override
public String getDirective() {
return directive;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright © 2021 Cask Data, Inc.
*
* 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.
*/

package io.cdap.delta.transformation;

import io.cdap.cdap.api.plugin.PluginConfig;

/**
* Config for Mock transformation
*/
public class MockRenameTransformationConfig extends PluginConfig {
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/data-integrations/bigquery-delta-plugins/pull/146/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy