window-functions

What is the Hamming window for?

醉酒当歌 提交于 2019-12-02 16:14:34
I'm working with some code that does a Fourier transform (to calculate the cepstrum of an audio sample). Before it computes the Fourier transform, it applies a Hamming window to the sample: for(int i = 0; i < SEGMENTATION_LENGTH;i++){ timeDomain[i] = (float) (( 0.53836 - ( 0.46164 * Math.cos( TWOPI * (double)i / (double)( SEGMENTATION_LENGTH - 1 ) ) ) ) * frameBuffer[i]); } Why is it doing this? I can't find any reason for it to do this in the code, or online. Whenever you do a finite Fourier transform, you're implicitly applying it to an infinitely repeating signal. So, for instance, if the

Spark Window Functions requires HiveContext?

痞子三分冷 提交于 2019-12-02 15:08:45
问题 I trying one example of window function on spark from this blog http://xinhstechblog.blogspot.in/2016/04/spark-window-functions-for-dataframes.html. Getting following error while running the program.My questions ,do we need hivecontext to execute the window functions in spark? Exception in thread "main" org.apache.spark.sql.AnalysisException: Could not resolve window function 'avg'. Note that, using window functions currently requires a HiveContext; at org.apache.spark.sql.catalyst.analysis

Complex 'Gaps and Islands' issue

南楼画角 提交于 2019-12-02 13:03:24
问题 I have a table in a Postgres DB like this: person | eventdate | type -------------------------------------- <uuid-1> | 2016-05-14 | 300 <uuid-3> | 2016-05-14 | 300 <uuid-1> | 2016-05-15 | 301 <uuid-1> | 2016-05-16 | 301 <uuid-1> | 2016-05-18 | 304 <uuid-1> | 2016-05-22 | 300 <uuid-2> | 2016-05-22 | 304 <uuid-2> | 2016-05-27 | 301 <uuid-1> | 2016-05-30 | 300 <uuid-1> | 2016-06-01 | 300 <uuid-2> | 2016-06-15 | 501 <uuid-2> | 2016-06-16 | 301 <uuid-4> | 2016-06-16 | 300 <uuid-5> | 2016-06-20 |

How to label groups in postgresql when group belonging depends on the preceding line?

眉间皱痕 提交于 2019-12-02 11:24:26
I want, in a request, to fill all Null values by the last known value. When it's in a table and not in a request, it's easy: If I define and fill my table as follows: CREATE TABLE test_fill_null ( date INTEGER, value INTEGER ); INSERT INTO test_fill_null VALUES (1,2), (2, NULL), (3, 45), (4,NULL), (5, null); SELECT * FROM test_fill_null ; date | value ------+------- 1 | 2 2 | 3 | 45 4 | 5 | Then I just have to fill like that: UPDATE test_fill_null t1 SET value = ( SELECT t2.value FROM test_fill_null t2 WHERE t2.date <= t1.date AND value IS NOT NULL ORDER BY t2.date DESC LIMIT 1 ); SELECT *

Running total over repeating group by items based on time in Oracle SQL

百般思念 提交于 2019-12-02 10:31:19
My first post, so bear with me. I want to sum based upon a value that is broken by dates but only want the sum for the dates, not for the the group by item in total. Have been working on this for days, trying to avoid using a cursor but may have to. Here's an example of the data I'm looking at. BTW, this is in Oracle 11g. Key Time Amt ------ ------------------ ------ Null 1-1-2016 00:00 50 Null 1-1-2016 02:00 50 Key1 1-1-2016 04:00 30 Null 1-1-2016 06:00 30 Null 1-1-2016 08:00 30 Key2 1-1-2016 10:00 40 Null 1-1-2016 12:00 40 Key1 1-1-2016 14:00 30 Null 1-2-2016 00:00 30 Key2 1-2-2016 02:00 35

Spark Window Functions requires HiveContext?

删除回忆录丶 提交于 2019-12-02 07:41:34
I trying one example of window function on spark from this blog http://xinhstechblog.blogspot.in/2016/04/spark-window-functions-for-dataframes.html . Getting following error while running the program.My questions ,do we need hivecontext to execute the window functions in spark? Exception in thread "main" org.apache.spark.sql.AnalysisException: Could not resolve window function 'avg'. Note that, using window functions currently requires a HiveContext; at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$class.failAnalysis(CheckAnalysis.scala:38) at org.apache.spark.sql.catalyst.analysis

Select partitions based on matches in other table

别说谁变了你拦得住时间么 提交于 2019-12-02 02:41:42
Having the following table ( conversations ): id | record_id | is_response | text | ---+------------+---------------+----------------------+ 1 | 1 | false | in text 1 | 2 | 1 | true | response text 3 | 3 | 1 | false | in text 2 | 4 | 1 | true | response text 2 | 5 | 1 | true | response text 3 | 6 | 2 | false | in text 1 | 7 | 2 | true | response text 1 | 8 | 2 | false | in text 2 | 9 | 2 | true | response text 3 | 10 | 2 | true | response text 4 | And another help table ( responses ): id | text | ---+----------------------+ 1 | response text 1 | 2 | response text 2 | 3 | response text 4 | I'm

Select finishes where athlete didn't finish first for the past 3 events

馋奶兔 提交于 2019-12-02 02:16:55
Suppose I have a database of athletic meeting results with a schema as follows DATE,NAME,FINISH_POS I wish to do a query to select all rows where an athlete has competed in at least three events without winning. For example with the following sample data 2013-06-22,Johnson,2 2013-06-21,Johnson,1 2013-06-20,Johnson,4 2013-06-19,Johnson,2 2013-06-18,Johnson,3 2013-06-17,Johnson,4 2013-06-16,Johnson,3 2013-06-15,Johnson,1 The following rows: 2013-06-20,Johnson,4 2013-06-19,Johnson,2 Would be matched. I have only managed to get started at the following stub: select date,name FROM table WHERE ...;

Grouping based on sequence of rows

假如想象 提交于 2019-12-02 00:29:05
I have a table of orders with a column denoting whether it's a buy or a sell, with the rows typically ordered by timestamp. What I'd like to do is operate on groups of consecutive buys, plus their sell. e.g. B B S B S B B S -> (B B S) (B S) (B B S) Example: order_action | timestamp -------------+--------------------- buy | 2013-10-03 13:03:02 buy | 2013-10-08 13:03:02 sell | 2013-10-10 15:58:02 buy | 2013-11-01 09:30:02 buy | 2013-11-01 14:03:02 sell | 2013-11-07 10:34:02 buy | 2013-12-03 15:46:02 sell | 2013-12-09 16:00:03 buy | 2013-12-11 13:02:02 sell | 2013-12-18 15:59:03 I'll be running

Multiple averages over evenly spaced intervals

天涯浪子 提交于 2019-12-02 00:27:54
问题 I'm trying to learn SQL so be patient with me. I'm using PostgreSQL 9.3 I want to average a column based on a window of dates. I've been able to write window functions that accomplish this with a set interval but I'd like to be able to be able to do this with a growing interval . By this I mean: average values from date_0 to date_1 average values from date_0 to date_2 average values from date_0 to date_3 ..... so date date_0 stays the same and date_x grows and creates a larger sample I'm