Giter Club home page Giter Club logo

tableau-server-postgres-queries's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @isajediknight
  • ๐Ÿ‘€ Iโ€™m interested in Python, Crypto and NodeJS
  • ๐ŸŒฑ Iโ€™m currently learning how to integrate Solana Web Apps with Phantom Wallets
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on Crypto Projects
  • ๐Ÿ“ซ You can reach me via LinkedIn message: https://www.linkedin.com/in/lukebrady/

tableau-server-postgres-queries's People

Contributors

isajediknight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tableau-server-postgres-queries's Issues

nviews - How long?

I couldn't find anything in the Tableau data dictionary about how long the data is stored for [nviews]. When pulling from "views_stats" the date that is presented (as the [time] field) appears to be the most recent access date from the user. I've been told that [nviews] is a tally of 180 days (by workbook id, user id, site id, and device type) regardless of the most recent access date/time, but I can't find it documented anywhere.

It might be helpful to update the queries that use the [nviews] field to notate that [time] and [nviews] are not directly related. In other words: One cannot use the [time] field to trend out how many times a user views a view over time; only the max time and total number of views are presented. Unknown what "total" means in relation to time.

Example queries from our server (with actual values adjusted for security purposes) proving the point.

-- I cannot find any documentation that indicates how to trend view/workbooks/site usage by date by user.
-- We can get view/workbook/site usage by date.
-- We can get MAX date by user by view/workbook/site.
-- There may be another table/view we could use, but I'm unable to locate it in https://tableau.github.io/tableau-data-dictionary/2021.2/data_dictionary.htm?_fsi=urL1jOre
-- Also refernced https://github.com/isajediknight/Tableau-Server-Postgres-Queries

select
user_id, view_id, site_id,
count(1) view_count
from views_stats
group by user_id, view_id, site_id
order by count(1) desc
-- We see a max of 5 records for the user + view + site combination (the only other fields in the table other than time)
-- If this were a daily view, we'd see more than 5 for a single user + view + site combination

select 
min(time)
from views_stats
--2019-02-01 12:11:11 returns as min(time)
--Defintely more than 180 days of data in the table
--Though it is possible the the key combination (user_id, view_id, site_id) is updated to reflect the most recent view

select
*
from views_stats
where user_id = 762951
and view_id = 68168
-- Only showing 5 records - 2 for 'desktop device_type' and then 1 each for other device_types - regardless of time
-- This indicates that this is NOT a table showing number of views by user for each view for each date

Null :: errors on the background jobs union

running your background jobs failed... It doesn't like the NULL :: on the union.. I fixed it and the below works

=========================
this works

SELECT background_jobs.backgrounder_id,
background_jobs.id,
background_jobs.created_at,
background_jobs.completed_at,
background_jobs.finish_code,
background_jobs.job_type,
background_jobs.progress,
background_jobs.args,
background_jobs.notes,
background_jobs.started_at,
background_jobs.job_name,
background_jobs.priority,
background_jobs.title,
background_jobs.processed_on_worker,
background_jobs.subtitle,
background_jobs.language,
background_jobs.site_id,
background_jobs.locale
FROM OPENQUERY(TABLEAU,'select * from public.background_jobs')background_jobs
UNION
SELECT async_jobs.worker AS backgrounder_id,
async_jobs.id,
async_jobs.created_at,
async_jobs.completed_at,
CASE
WHEN async_jobs.success = 1 THEN 0
ELSE 1
END AS finish_code,
async_jobs.job_type,
async_jobs.progress,
-NULL AS args,
async_jobs.notes,
async_jobs.created_at AS started_at,
async_jobs.job_type AS job_name ,
0 AS priority,
NULL AS title,
async_jobs.worker AS processed_on_worker,
NULL AS subtitle,
NULL AS language,
async_jobs.site_id,
NULL AS locale
FROM OPENQUERY(TABLEAU,'select * from public.async_jobs')async_jobs

workbooks query 2 inner joins incorrect

Theres 2 inner joins on here I have commented out as else it doesn't work.. adding one reduced the record count which is incorrect and the checksum one cuts all records out...

This runs and brings the correct amount.. Start by the record count of the workbook table and enable and disable joins.. record count should stay the same as the overall workbook table

SELECT DISTINCT
T301.asset_key_id AS "Asset_Key_ID (WB)",
T301.checksum AS "Checksum (WB)",
T301.content_version AS "Content_Version (WB)",
T301.created_at AS "Created_At (WB)",
T301.data_engine_extracts AS "Data_Engine_Extracts (WB)",
T301.data_id AS "Data_ID (WB)",
T301.default_view_index AS "Default_View_Index (WB)",
T301.description AS "Description (WB)",
T301.display_tabs AS "Display_Tabs (WB)",
T301.document_version AS "Document_Version (WB)",
--T301.embedded AS "Embedded (WB)",
T301.extracts_incremented_at AS "Extracts_Incremented_At (WB)",
T301.extracts_refreshed_at AS "Extracts_Refreshed_At (WB)",
T301.first_published_at AS "First_Published_At (WB)",
T301.id AS "Id (WB)",
T301.incrementable_extracts AS "Incrementable_Extracts (WB)",
T301.last_published_at AS "Last_Published_At (WB)",
T301.lock_version AS "Lock_Version (WB)",
T301.luid AS "Luid (WB)",
T301.name AS "Name (WB)",
T301.owner_id AS "Owner_ID (WB)",
T301.primary_content_url AS "Primary_Content_Url (WB)",
T301.project_id AS "Project_ID (WB)",
T301.published_all_sheets AS "Published_All_Sheets (WB)",
T301.reduced_data_id AS "Reduced_Data_ID (WB)",
T301.refreshable_extracts AS "Refreshable_Extracts (WB)",
T301.repository_data_id AS "Repository_Data_ID (WB)",
T301.repository_extract_data_id AS "Repository_Extract_Data_ID (WB)",
T301.repository_url AS "Repository_Url (WB)",
T301.revision AS "Revision (WB)",
T301.share_description AS "Share_Description (WB)",
T301.show_toolbar AS "Show_Toolbar (WB)",
T301.site_id AS "Site_ID (WB)",
T301.size AS "Size (WB)",
T301.state AS "State (WB)",
T301.thumb_user AS "Thumb_User (WB)",
T301.updated_at AS "Updated_At (WB)",
T301.version AS "Version (WB)",
T301.view_count AS "View_Count (WB)"
FROM OPENQUERY(TABLEAU,'select * from public.workbooks')T301
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.data_alerts') T47 ON T301.id = T47.workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.data_connections') T49 ON T301.id = T49.owner_id AND T49.owner_type = 'Workbook'
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.datasources') T55 ON T301.id = T55.parent_workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.extracts') T68 ON T301.id = T68.workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.hist_workbooks') T93 ON T301.id = T93.workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.most_recent_refreshes') T116 ON T301.id = T116.workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.next_gen_permissions') T120 ON T301.id = T120.authorizable_id AND T120.authorizable_type = 'Workbook'
INNER JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.views') T297 ON T301.id = T297.workbook_id
-- INNER JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.workbook_checksums')T299 ON T301.id = T299.workbook_id -- this joins makes query bring back 0
--INNER JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.workbook_versions') T300 ON T301.id = T300.workbook_id -- this join cuts records down by a lot -
INNER JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.users')T290 ON T301.owner_id = T290.id
INNER JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.projects') T227 ON T301.project_id = T227.id
INNER JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.sites') T259 ON T301.site_id = T259.id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC._views') T16 ON T301.id = T16.workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC._views_stats') T17 ON T301.id = T17.views_workbook_id
LEFT JOIN OPENQUERY(TABLEAU,'SELECT * FROM PUBLIC.subscriptions_workbooks')T270 ON T301.repository_url = T270.repository_url

errors doesnt run

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'FROM'.

=====================================
SELECT DISTINCT
T28.created_at AS "Started",
CAST(EXTRACT(SECOND FROM (T28.completed_at - T28.created_at)) AS INT) AS "Runtime_Seconds",
T28.notes AS "Subscription_Results",
D4.name AS "Subscriber",
D3.name AS "Subscribed_By",
T267.subject AS "Subscribed_Content",
CASE
WHEN (T268.customized_view_id IS NULL AND false OR NOT T268.customized_view_id IS NULL AND NOT false) AND (T269.subscription_id IS NULL AND false OR NOT T269.subscription_id IS NULL AND NOT false) THEN 'Customized View - Single View'::text
WHEN (T268.customized_view_id IS NULL AND false OR NOT T268.customized_view_id IS NULL AND NOT false) AND (T270.subscription_id IS NULL AND false OR NOT T270.subscription_id IS NULL AND NOT false) THEN 'Customized View - Workbook'::text
WHEN T269.subscription_id IS NULL AND false OR NOT T269.subscription_id IS NULL AND NOT false THEN 'Single View'::text
WHEN T270.subscription_id IS NULL AND false OR NOT T270.subscription_id IS NULL AND NOT false THEN 'Workbook'::text
ELSE 'Unknown'::text
END AS "Content_Type",
CASE
WHEN T301.name IS NULL THEN D10.name
ELSE T301.name
END AS "Workbook",
CASE
WHEN T269.repository_url IS NULL THEN T270.repository_url
ELSE regexp_replace(T269.repository_url, '/sheets'::text, ''::text)
END AS "URL",
CASE
WHEN D11.name IS NULL THEN D12.name
ELSE D11.name
END AS "Workbook Owner",
T28.site_id AS "Background_Jobs_Site_ID",
T267.site_id AS "Subscription_Site_ID",
T267.is_refresh_extract_triggered AS "Extract_Refreshed",
T28.processed_on_worker AS "Worker",
T267.ID AS "Subscription_ID",
T28.id AS "Background_Jobs_ID",
T268.customized_view_id AS "Customized_View_ID"
--Add T28. Columns Here
--Add T1. Columns Here
--regexp_replace(T269.repository_url, '/sheets'::text, ''::text) AS "View_URL",
--T270.repository_url AS "Workbook_URL",
FROM OPENQUERY(TABLEAU,'select * from public.background_jobs') T28
INNER JOIN OPENQUERY(TABLEAU,'select * from public.subscriptions') T267 ON T267.id = T28.correlation_id
INNER JOIN OPENQUERY(TABLEAU,'select * from public.system_users')D3 ON D3.ID = T267.creator_id
INNER JOIN OPENQUERY(TABLEAU,'select * from public.system_users') D4 ON D4.ID = T267.user_id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.subscriptions_views') T269 ON T267.id = T269.subscription_id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.subscriptions_workbooks')T270 ON T267.id = T270.subscription_id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.subscriptions_customized_views') T268 ON T267.id = T268.subscription_id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.views') T297 ON T269.repository_url = T297.repository_url--T269.id = T297.id doesnt work
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.workbooks')D10 ON T297.workbook_id = D10.id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.system_users')D12 ON D12.id = D10.owner_id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.workbooks')T301 ON T301.repository_url = T270.repository_url--T301.id = T270.id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public.system_users') D11 ON D11.id = T301.owner_id
LEFT JOIN OPENQUERY(TABLEAU,'select * from public._background_tasks') T1 ON T1.backgrounder_id = T28.backgrounder_id
WHERE
T28.job_name = 'Subscription Notifications'
ORDER BY T28.created_at ASC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.