-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-3329] Implement osquery for OS adapter
- Loading branch information
XuQianJin-Stars
committed
Dec 17, 2023
1 parent
8c640da
commit 94110de
Showing
26 changed files
with
1,198 additions
and
230 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
55 changes: 55 additions & 0 deletions
55
plus/src/main/java/org/apache/calcite/adapter/os/AbstractBaseScannableTable.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,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 org.apache.calcite.adapter.os; | ||
|
||
import org.apache.calcite.config.CalciteConnectionConfig; | ||
import org.apache.calcite.schema.ScannableTable; | ||
import org.apache.calcite.schema.Schema; | ||
import org.apache.calcite.schema.Statistic; | ||
import org.apache.calcite.schema.Statistics; | ||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.util.ImmutableBitSet; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* Abstract base class for implementations of OS table functions. | ||
*/ | ||
abstract class AbstractBaseScannableTable implements ScannableTable { | ||
protected AbstractBaseScannableTable() { | ||
} | ||
|
||
@Override public Statistic getStatistic() { | ||
return Statistics.of(1000d, ImmutableList.of(ImmutableBitSet.of(1))); | ||
} | ||
|
||
@Override public Schema.TableType getJdbcTableType() { | ||
return Schema.TableType.TABLE; | ||
} | ||
|
||
@Override public boolean isRolledUp(String column) { | ||
return false; | ||
} | ||
|
||
@Override public boolean rolledUpColumnValidInsideAgg(String column, SqlCall call, | ||
@Nullable SqlNode parent, @Nullable CalciteConnectionConfig config) { | ||
return true; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
plus/src/main/java/org/apache/calcite/adapter/os/CpuInfoTableFunction.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,62 @@ | ||
/* | ||
* 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 org.apache.calcite.adapter.os; | ||
|
||
import org.apache.calcite.DataContext; | ||
import org.apache.calcite.linq4j.AbstractEnumerable; | ||
import org.apache.calcite.linq4j.Enumerable; | ||
import org.apache.calcite.linq4j.Enumerator; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
import org.apache.calcite.schema.ScannableTable; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* Table function that executes the OS "cpu_info". | ||
*/ | ||
public class CpuInfoTableFunction { | ||
private CpuInfoTableFunction() { | ||
} | ||
|
||
public static ScannableTable eval(boolean b) { | ||
return new AbstractBaseScannableTable() { | ||
@Override public Enumerable<@Nullable Object[]> scan(DataContext root) { | ||
return new AbstractEnumerable<Object[]>() { | ||
@Override public Enumerator<Object[]> enumerator() { | ||
return new OsQueryEnumerator("cpu_info"); | ||
} | ||
}; | ||
} | ||
|
||
@Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { | ||
return typeFactory.builder() | ||
.add("device_id", SqlTypeName.VARCHAR) | ||
.add("model", SqlTypeName.VARCHAR) | ||
.add("manufacturer", SqlTypeName.VARCHAR) | ||
.add("number_of_cores", SqlTypeName.INTEGER) | ||
.add("logical_processors", SqlTypeName.INTEGER) | ||
.add("address_width", SqlTypeName.INTEGER) | ||
.add("max_clock_speed", SqlTypeName.BIGINT) | ||
.add("socket_designation", SqlTypeName.INTEGER) | ||
.add("cpu_load", SqlTypeName.DOUBLE) | ||
.build(); | ||
} | ||
}; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
plus/src/main/java/org/apache/calcite/adapter/os/CpuTimeTableFunction.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,61 @@ | ||
/* | ||
* 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 org.apache.calcite.adapter.os; | ||
|
||
import org.apache.calcite.DataContext; | ||
import org.apache.calcite.linq4j.AbstractEnumerable; | ||
import org.apache.calcite.linq4j.Enumerable; | ||
import org.apache.calcite.linq4j.Enumerator; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
import org.apache.calcite.schema.ScannableTable; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* Table function that executes the OS "cpu_info". | ||
*/ | ||
public class CpuTimeTableFunction { | ||
private CpuTimeTableFunction() { | ||
} | ||
|
||
public static ScannableTable eval(boolean b) { | ||
return new AbstractBaseScannableTable() { | ||
@Override public Enumerable<@Nullable Object[]> scan(DataContext root) { | ||
return new AbstractEnumerable<Object[]>() { | ||
@Override public Enumerator<Object[]> enumerator() { | ||
return new OsQueryEnumerator("cpu_time"); | ||
} | ||
}; | ||
} | ||
|
||
@Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { | ||
return typeFactory.builder() | ||
.add("idle", SqlTypeName.BIGINT) | ||
.add("nice", SqlTypeName.BIGINT) | ||
.add("irq", SqlTypeName.BIGINT) | ||
.add("soft_irq", SqlTypeName.BIGINT) | ||
.add("steal", SqlTypeName.BIGINT) | ||
.add("system", SqlTypeName.BIGINT) | ||
.add("user", SqlTypeName.BIGINT) | ||
.add("io_wait", SqlTypeName.BIGINT) | ||
.build(); | ||
} | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.