Skip to content

Function not found: random; Did you mean rand? #448

@mwilson19

Description

@mwilson19

Getting error when running simple query in dplyr syntax with slice_sample on bigquery sample data. I am able to query if I replicate using standard SQL and the RAND() function.

The error reads

Function not found: random; Did you mean rand? at [2:508]

Maybe need to update backend with a new function? Looks like the show_query uses RANDOM not RAND.

library(tidyverse)
library(dbplyr)
library(bigrquery)
library(DBI)

# bigquery authentication
bq_auth(path = 'xxxx.json')

con <- dbConnect(
  bigrquery::bigquery(),
  project = "bigquery-public-data",
  dataset = "samples",
  billing = "billing"
)

# THIS WORKS
sql <- "SELECT *
         FROM `publicdata.samples.natality`
         WHERE RAND() < 0.001"

example <- dbGetQuery(con, sql2)
glimpse(example)


# THIS DOES NOT WORK
# use dbi/dplyr syntax
natality <- tbl(con, "natality")

nat <- 
  natality %>%
  slice_sample(n=50) %>%  
  collect()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions