What does the 1M resistor do in this circuit? (knock sensor)

voltage = resistance x current.

The piezo outputs current (at almost any voltage - it doesn't care). The resistor fixes the voltage to be a
function of the current.

Put another way the piezo pushes out electrons as hard as it needs to to get them out (they are almost literally
squeezed mechanically out of the crystal). With no resistance load the voltage will go up to 1000's of volts (or
with the arduino simply conduct away through the protection diodes). So you would see a nearly square wave
and lose all the analog detail.

[ actually to be a bit more accurate the piezo outputs charge proportional to physical distortion, but otherwise acts
like an insulator (with some capacitance) - this is how ferroelectric materials behave, mechanical strain coupled to charge
displacement ]