Skip to content

Commit

Permalink
make arrow dependencies flip on and off check cargo can build
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed May 23, 2024
1 parent 7ebbd56 commit 590b612
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ arrow-data = { version = "50" }
arrow-array = { version = "50" }

raphtory-arrow = { version = "0.8.1", path = "./raphtory-arrow" }
# raphtory-arrow = { git = "ssh://[email protected]/Pometry/raphtory-arrow.git", branch = "master" }
#flip raphtory-arrow = { git = "ssh://[email protected]/Pometry/raphtory-arrow.git", branch = "master" }

# Make sure that transitive dependencies stick to arrow 50
[patch.crates-io]
Expand Down
10 changes: 8 additions & 2 deletions raphtory-cypher/examples/raphtory_cypher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pub use cyper_arrow::*;
#[cfg(not(feature = "arrow"))]
fn main() {}

#[cfg(feature = "arrow")]
#[tokio::main]
async fn main() {
cyper_arrow::main().await;
}

#[cfg(feature = "arrow")]
mod cyper_arrow {
use std::{error::Error, str::FromStr};
Expand Down Expand Up @@ -121,8 +127,8 @@ mod cyper_arrow {
Load(LoadGraph),
}

#[tokio::main]
async fn main() {
// #[tokio::main]
pub async fn main() {
let args = Args::parse();

match args {
Expand Down
66 changes: 36 additions & 30 deletions raphtory-cypher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#[cfg(feature = "arrow")]
pub use cypher_arrow::*;

#[cfg(feature = "arrow")]
pub mod executor;
#[cfg(feature = "arrow")]
pub mod hop;
#[cfg(feature = "arrow")]
pub mod parser;
#[cfg(feature = "arrow")]
pub mod transpiler;

#[cfg(feature = "arrow")]
mod cypher_arrow {
use arrow::compute::take;
Expand All @@ -20,20 +29,16 @@ mod cypher_arrow {
physical_plan::SendableRecordBatchStream,
};

use executor::{table_provider::edge::EdgeListTableProvider, ExecError};
use parser::ast::*;
use super::executor::{table_provider::edge::EdgeListTableProvider, ExecError};
use super::parser::ast::*;
use raphtory::arrow::graph_impl::ArrowGraph;
use super::*;

use crate::{
executor::table_provider::node::NodeTableProvider,
hop::rule::{HopQueryPlanner, HopRule},
};

pub mod executor;
pub mod hop;
pub mod parser;
pub mod transpiler;

pub use polars_arrow as arrow2;

pub async fn run_cypher(
Expand All @@ -52,7 +57,7 @@ mod cypher_arrow {
enable_hop_optim: bool,
) -> Result<(SessionContext, LogicalPlan), ExecError> {
// println!("Running query: {:?}", query);
let query = parser::parse_cypher(query)?;
let query = super::parser::parse_cypher(query)?;

let config = SessionConfig::from_env()?.with_information_schema(true);

Expand Down Expand Up @@ -292,7 +297,8 @@ mod cypher_arrow {
let srcs = PrimitiveArray::from_vec(vec![1u64, 2u64, 2u64, 2u64]).boxed();
let dsts = PrimitiveArray::from_vec(vec![3u64, 3u64, 4u64, 4u64]).boxed();
let time = PrimitiveArray::from_vec(vec![2i64, 3i64, 4i64, 5i64]).boxed();
let weight = PrimitiveArray::from_vec(vec![3.14f64, 4.14f64, 5.14f64, 6.14f64]).boxed();
let weight =
PrimitiveArray::from_vec(vec![3.14f64, 4.14f64, 5.14f64, 6.14f64]).boxed();

let chunk = StructArray::new(
ArrowDataType::Struct(schema().fields),
Expand All @@ -305,7 +311,8 @@ mod cypher_arrow {
let edge_lists = vec![chunk];

let graph =
ArrowGraph::load_from_edge_lists(&edge_lists, 20, 20, graph_dir, 0, 1, 2).unwrap();
ArrowGraph::load_from_edge_lists(&edge_lists, 20, 20, graph_dir, 0, 1, 2)
.unwrap();

let df = run_cypher("match ()-[e]->() RETURN *", &graph, true)
.await
Expand Down Expand Up @@ -357,7 +364,7 @@ mod cypher_arrow {
None,
1,
)
.unwrap();
.unwrap();

let df = run_cypher("match ()-[e]->() RETURN *", &graph, true)
.await
Expand Down Expand Up @@ -410,8 +417,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();

let data = df.collect().await.unwrap();
print_batches(&data).expect("failed to print batches");
Expand Down Expand Up @@ -462,8 +469,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();

let data = df.collect().await.unwrap();
print_batches(&data).unwrap();
Expand All @@ -479,8 +486,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();

let data = df.collect().await.unwrap();
print_batches(&data).unwrap();
Expand Down Expand Up @@ -510,10 +517,10 @@ mod cypher_arrow {
("name", Prop::str(name.as_ref())),
("age", Prop::I64(*age)),
])
.unwrap();
.unwrap();
if let Some(city) = city {
nv.add_constant_properties(vec![("city", Prop::str(city.as_ref()))])
.unwrap();
.unwrap();
}
}
}
Expand Down Expand Up @@ -561,8 +568,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();

let data = df.collect().await.unwrap();
print_batches(&data).unwrap();
Expand All @@ -578,8 +585,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();
let data = df.collect().await.unwrap();
print_batches(&data).unwrap();
}
Expand Down Expand Up @@ -618,8 +625,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();
let data = df.collect().await.unwrap();
print_batches(&data).unwrap();
}
Expand Down Expand Up @@ -682,8 +689,8 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();

let data = df.collect().await.unwrap();
print_batches(&data).expect("failed to print batches");
Expand Down Expand Up @@ -747,11 +754,10 @@ mod cypher_arrow {
&graph,
true,
)
.await
.unwrap();
.await
.unwrap();
let data = df.collect().await.unwrap();
print_batches(&data).unwrap();
}
}

}
2 changes: 1 addition & 1 deletion raphtory-cypher/src/transpiler/exprs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sqlparser::ast::{self as sql_ast};

use crate::{Clause, Query, Return};
use crate::parser::ast::{Clause, Query, Return};

pub fn parse_limit(query: &Query) -> Option<sql_ast::Expr> {
query.clauses().iter().find_map(|clause| match clause {
Expand Down
12 changes: 0 additions & 12 deletions scripts/add_arrow_dep.sh

This file was deleted.

16 changes: 16 additions & 0 deletions scripts/flip_ra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
import sys

if len(sys.argv) != 2:
print("Usage: flip_ra.py <file>")
sys.exit(1)

file = sys.argv[1]

with open(file, 'r') as f:
for line in f:
if line.startswith("#flip raphtory-arrow"):
line = line.replace("#flip raphtory-arrow", "raphtory-arrow", 1)
elif line.startswith("raphtory-arrow"):
line = line.replace("raphtory-arrow", "#flip raphtory-arrow", 1)
print(line, end='')
12 changes: 4 additions & 8 deletions scripts/hide_arrow_dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ set -e
set -x
# Hide arrow dependency in all Cargo.toml files

# Detect the operating system
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
find . -name "Cargo.toml" -type f -exec sed -i '' '/raphtory-arrow/ s/^/# /' {} +
else
# Linux and other UNIX-like systems
find . -name "Cargo.toml" -type f -exec sed -i '/raphtory-arrow/ s/^/# /' {} +
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

$SCRIPT_DIR/flip_ra.py Cargo.toml > Cargo.toml.bk
mv Cargo.toml.bk Cargo.toml

0 comments on commit 590b612

Please sign in to comment.