Skip to content

Commit a63e64b

Browse files
committed
refactor(cubesql): Use &str instead of &String
1 parent 6fad670 commit a63e64b

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

packages/cubejs-backend-native/src/node_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async fn handle_sql_query(
183183
native_auth_ctx: Arc<NativeAuthContext>,
184184
channel: Arc<Channel>,
185185
stream_methods: WritableStreamMethods,
186-
sql_query: &String,
186+
sql_query: &str,
187187
) -> Result<(), CubeError> {
188188
let config = services
189189
.injector()

rust/cubesql/cubesql/src/compile/parser.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ static SIGMA_WORKAROUND: LazyLock<Regex> = LazyLock::new(|| {
4141
});
4242

4343
pub fn parse_sql_to_statements(
44-
query: &String,
44+
query: &str,
4545
protocol: DatabaseProtocol,
4646
qtrace: &mut Option<Qtrace>,
4747
) -> CompilationResult<Vec<Statement>> {
48-
let original_query = query.clone();
48+
let original_query = query;
4949

5050
log::debug!("Parsing SQL: {}", query);
5151
// @todo Support without workarounds
5252
// metabase
53-
let query = query.clone().replace("IF(TABLE_TYPE='BASE TABLE' or TABLE_TYPE='SYSTEM VERSIONED', 'TABLE', TABLE_TYPE) as TABLE_TYPE", "TABLE_TYPE");
53+
let query = query.replace("IF(TABLE_TYPE='BASE TABLE' or TABLE_TYPE='SYSTEM VERSIONED', 'TABLE', TABLE_TYPE) as TABLE_TYPE", "TABLE_TYPE");
5454
let query = query.replace("ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME", "");
5555
// @todo Implement CONVERT function
5656
let query = query.replace("CONVERT (CASE DATA_TYPE WHEN 'year' THEN NUMERIC_SCALE WHEN 'tinyint' THEN 0 ELSE NUMERIC_SCALE END, UNSIGNED INTEGER)", "0");
@@ -247,13 +247,14 @@ pub fn parse_sql_to_statements(
247247
};
248248

249249
parse_result.map_err(|err| {
250-
CompilationError::user(format!("Unable to parse: {:?}", err))
251-
.with_meta(Some(HashMap::from([("query".to_string(), original_query)])))
250+
CompilationError::user(format!("Unable to parse: {:?}", err)).with_meta(Some(
251+
HashMap::from([("query".to_string(), original_query.to_string())]),
252+
))
252253
})
253254
}
254255

255256
pub fn parse_sql_to_statement(
256-
query: &String,
257+
query: &str,
257258
protocol: DatabaseProtocol,
258259
qtrace: &mut Option<Qtrace>,
259260
) -> CompilationResult<Statement> {
@@ -274,7 +275,10 @@ pub fn parse_sql_to_statement(
274275
))
275276
};
276277

277-
Err(err.with_meta(Some(HashMap::from([("query".to_string(), query.clone())]))))
278+
Err(err.with_meta(Some(HashMap::from([(
279+
"query".to_string(),
280+
query.to_string(),
281+
)]))))
278282
}
279283
}
280284
}

rust/cubesql/cubesql/src/compile/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub async fn convert_statement_to_cube_query(
637637
}
638638

639639
pub async fn convert_sql_to_cube_query(
640-
query: &String,
640+
query: &str,
641641
meta: Arc<MetaContext>,
642642
session: Arc<Session>,
643643
) -> CompilationResult<QueryPlan> {

rust/cubesql/cubesql/src/sql/postgres/shim.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,7 @@ impl AsyncPostgresShim {
17921792
let cache_entry = self.get_cache_entry().await?;
17931793
let meta = self.session.server.compiler_cache.meta(cache_entry).await?;
17941794

1795-
let statements =
1796-
parse_sql_to_statements(&query.to_string(), DatabaseProtocol::PostgreSQL, qtrace)?;
1795+
let statements = parse_sql_to_statements(query, DatabaseProtocol::PostgreSQL, qtrace)?;
17971796

17981797
if statements.len() == 0 {
17991798
self.write(protocol::EmptyQuery::new()).await?;

0 commit comments

Comments
 (0)