Skip to content

Commit

Permalink
[Feature][Server] Add metadata lineage api (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
zixi0825 authored Jul 28, 2024
1 parent 33a358b commit c58c119
Show file tree
Hide file tree
Showing 29 changed files with 683 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
public enum SourceType {

/**
* 0 normal
* 1 invalidate items
* 2 actual value
* 0 source
* 1 target
* 2 metadata
**/
SOURCE(0, "source"),
TARGET(1, "target"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public interface ConnectorFactory {
ConfigBuilder getConfigBuilder();

DataSourceClient getDataSourceClient();

StatementSplitter getStatementSplitter();

StatementParser getStatementParser();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api;

import io.datavines.common.utils.StringUtils;
import io.datavines.connector.api.entity.ScriptMetadata;
import io.datavines.connector.api.entity.StatementMetadata;
import org.apache.commons.collections4.CollectionUtils;

import java.time.LocalDateTime;
import java.util.List;

public class LineageParser {

public static ScriptMetadata parseScript(String script, StatementSplitter statementSplitter, StatementParser statementParser) {
if (StringUtils.isEmpty(script)) {
return null;
}

ScriptMetadata scriptMetadata = new ScriptMetadata();
scriptMetadata.setScript(script);
List<String> statements = statementSplitter.splitStatements(script);

if (CollectionUtils.isEmpty(statements)) {
return null;
}

for (int i=0; i<statements.size(); i++) {
StatementMetadata statementMetadata = new StatementMetadata();
statementMetadata.setStatementIndex(i);
statementMetadata.setStatementText(statements.get(i));
statementMetadata.setStatementParseStartTime(LocalDateTime.now());
statementMetadata.setStatementMetadataFragment(statementParser.parseStatement(statements.get(i)));
statementMetadata.setStatementParseEndTime(LocalDateTime.now());
scriptMetadata.addStatementMetadata(statementMetadata);
}

return scriptMetadata;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api;

import io.datavines.connector.api.entity.StatementMetadataFragment;

public interface StatementParser {

StatementMetadataFragment parseStatement(String statement);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api;

import java.util.List;

public interface StatementSplitter {

List<String> splitStatements(String body) ;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api.entity;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
public class ColumnLineage {

private List<String> inputColumns;

private List<String> outputColumns;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api.entity;

public class MetaDataConstants {

public final static String UNKNOWN_STATEMENT_TYPE = "UNKNOWN";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api.entity;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.List;

@Data
public class ScriptMetadata {

private String script;

private List<StatementMetadata> statementMetadataList;

public void addStatementMetadata(StatementMetadata statementMetadata) {
if (CollectionUtils.isEmpty(statementMetadataList)) {
statementMetadataList = new ArrayList<>();
}
statementMetadataList.add(statementMetadata);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api.entity;

import lombok.Data;

import java.time.LocalDateTime;

@Data
public class StatementMetadata {

private int statementIndex;

private String statementText;

private StatementMetadataFragment statementMetadataFragment;

private LocalDateTime statementParseStartTime;

private LocalDateTime statementParseEndTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.api.entity;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
public class StatementMetadataFragment {

private List<String> inputTables;

private List<String> outputTables;

private List<ColumnLineage> columnLineageList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public ConfigBuilder getConfigBuilder() {
public DataSourceClient getDataSourceClient() {
return null;
}

@Override
public StatementSplitter getStatementSplitter() {
return null;
}

@Override
public StatementParser getStatementParser() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public ConfigBuilder getConfigBuilder() {
public DataSourceClient getDataSourceClient() {
return new JdbcDataSourceClient();
}

@Override
public StatementSplitter getStatementSplitter() {
return new DefaultStatementSplitter();
}

@Override
public StatementParser getStatementParser() {
return new DefaultStatementParser();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.plugin;

import io.datavines.connector.api.StatementParser;
import io.datavines.connector.api.entity.StatementMetadataFragment;

public class DefaultStatementParser implements StatementParser {

@Override
public StatementMetadataFragment parseStatement(String statement) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.datavines.connector.plugin;

import io.datavines.common.utils.StringUtils;
import io.datavines.connector.api.StatementSplitter;

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

public class DefaultStatementSplitter implements StatementSplitter {

@Override
public List<String> splitStatements(String body) {

String DELIMITER = ";";
return StringUtils.isEmpty(body) ? null : Arrays.asList(body.split(DELIMITER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public ConnectorResponse testConnect(TestConnectionRequestParam param) {

@Override
public List<String> keyProperties() {
return Arrays.asList(HOST, PORT, DATABASE);
return Arrays.asList(HOST, PORT);
}

@Override
Expand Down
Loading

0 comments on commit c58c119

Please sign in to comment.